MessageHandler.c 678 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293
  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 1,
  125. unsigned char TriggerMeterValue:1; //bit 2,
  126. unsigned char :5; //bit 5~7
  127. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  128. }CpinitiateMsg;
  129. CpinitiateMsg cpinitateMsg;
  130. //GetConfiguration Array
  131. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  132. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  133. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  134. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  135. #if 0
  136. static char *ChargePointErrorCodeStr[] = {
  137. MACROSTR(ConnectorLockFailure),
  138. MACROSTR(EVCommunicationError),
  139. MACROSTR(GroundFailure),
  140. MACROSTR(HighTemperature),
  141. MACROSTR(InternalError),
  142. MACROSTR(LocalListConflict),
  143. MACROSTR(NoError),
  144. MACROSTR(OtherError),
  145. MACROSTR(OverCurrentFailure),
  146. MACROSTR(OverVoltage),
  147. MACROSTR(PowerMeterFailure),
  148. MACROSTR(PowerSwitchFailure),
  149. MACROSTR(ReaderFailure),
  150. MACROSTR(ResetFailure),
  151. MACROSTR(UnderVoltage),
  152. MACROSTR(WeakSignal)
  153. };
  154. #endif
  155. static char * ChargePointStatusStr[] = {
  156. MACROSTR(Available),
  157. MACROSTR(Preparing),
  158. MACROSTR(Charging),
  159. MACROSTR(SuspendedEVSE),
  160. MACROSTR(SuspendedEV),
  161. MACROSTR(Finishing),
  162. MACROSTR(Reserved),
  163. MACROSTR(Unavailable),
  164. MACROSTR(Faulted)
  165. };
  166. static char *RegistrationStatusStr[] = {
  167. MACROSTR(Accepted),
  168. MACROSTR(Pending),
  169. MACROSTR(Rejected)
  170. };
  171. static char *AvailabilityTypeStr[] = {
  172. MACROSTR(Inoperative),
  173. MACROSTR(Operative)
  174. };
  175. static char *AvailabilityStatusStr[] = {
  176. MACROSTR(Accepted),
  177. MACROSTR(Rejected),
  178. MACROSTR(Scheduled)
  179. };
  180. static char *ConfigurationStatusStr[] = {
  181. MACROSTR(Accepted),
  182. MACROSTR(Rejected),
  183. MACROSTR(RebootRequired),
  184. MACROSTR(NotSupported)
  185. };
  186. static char *ClearCacheStatusStr[] = {
  187. MACROSTR(Accepted),
  188. MACROSTR(Rejected)
  189. };
  190. static char *ChargingProfilePurposeTypeStr[] = {
  191. MACROSTR(ChargePointMaxProfile),
  192. MACROSTR(TxDefaultProfile),
  193. MACROSTR(TxProfile)
  194. };
  195. static char *ChargingProfileStatusStr[] = {
  196. MACROSTR(Accepted),
  197. MACROSTR(Rejected),
  198. MACROSTR(NotSupported)
  199. };
  200. static char *ClearChargingProfileStatusStr[] = {
  201. MACROSTR(Accepted),
  202. MACROSTR(Unknown)
  203. };
  204. static char *GetCompositeScheduleStatusStr[] = {
  205. MACROSTR(Accepted),
  206. MACROSTR(Rejected)
  207. };
  208. static char *UpdateTypeStr[] = {
  209. MACROSTR(Differential),
  210. MACROSTR(Full)
  211. };
  212. static char *UpdateStatusStr[] = {
  213. MACROSTR(Accepted),
  214. MACROSTR(Failed),
  215. MACROSTR(NotSupported),
  216. MACROSTR(VersionMismatch)
  217. };
  218. static char *RemoteStartStopStatusStr[] = {
  219. MACROSTR(Accepted),
  220. MACROSTR(Rejected)
  221. };
  222. static char *ReservationStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Faulted),
  225. MACROSTR(Occupied),
  226. MACROSTR(Rejected),
  227. MACROSTR(Unavailable)
  228. };
  229. static char *ResetTypeStr[] = {
  230. MACROSTR(Hard),
  231. MACROSTR(Soft)
  232. };
  233. static char *ResetStatusStr[] = {
  234. MACROSTR(Accepted),
  235. MACROSTR(Rejected)
  236. };
  237. static char * DiagnosticsStatusStr[] = {
  238. MACROSTR(Idle),
  239. MACROSTR(Uploaded),
  240. MACROSTR(UploadFailed),
  241. MACROSTR(Uploading)
  242. };
  243. static char * FirmwareStatusStr[] = {
  244. MACROSTR(Downloaded),
  245. MACROSTR(DownloadFailed),
  246. MACROSTR(Downloading),
  247. MACROSTR(Idle),
  248. MACROSTR(InstallationFailed),
  249. MACROSTR(Installing),
  250. MACROSTR(Installed)
  251. };
  252. static char * MessageTriggerStr[] = {
  253. MACROSTR(BootNotification),
  254. MACROSTR(DiagnosticsStatusNotification),
  255. MACROSTR(FirmwareStatusNotification),
  256. MACROSTR(Heartbeat),
  257. MACROSTR(MeterValues),
  258. MACROSTR(StatusNotification)
  259. };
  260. static char * TriggerMessageStatusStr[] = {
  261. MACROSTR(Accepted),
  262. MACROSTR(Rejected),
  263. MACROSTR(NotImplemented)
  264. };
  265. static char * UnlockStatusStr[] = {
  266. MACROSTR(Unlocked),
  267. MACROSTR(UnlockFailed),
  268. MACROSTR(NotSupported)
  269. };
  270. #if 0
  271. static char * StopTransactionReasonStr[] = {
  272. MACROSTR(EmergencyStop),
  273. MACROSTR(EVDisconnected),
  274. MACROSTR(HardReset),
  275. MACROSTR(Local),
  276. MACROSTR(Other),
  277. MACROSTR(PowerLoss),
  278. MACROSTR(Reboot),
  279. MACROSTR(Remote),
  280. MACROSTR(SoftReset),
  281. MACROSTR(UnlockCommand),
  282. MACROSTR(DeAuthorized)
  283. };
  284. #endif
  285. static char * CancelReservationStatusStr[] = {
  286. MACROSTR(Accepted),
  287. MACROSTR(Rejected)
  288. };
  289. static char * ReadingContextStr[] = {
  290. MACROSTR(Interruption.Begin),
  291. MACROSTR(Interruption.End),
  292. MACROSTR(Other),
  293. MACROSTR(Sample.Clock),
  294. MACROSTR(Sample.Periodic),
  295. MACROSTR(Transaction.Begin),
  296. MACROSTR(Transaction.End),
  297. MACROSTR(Trigger)
  298. };
  299. static char * ValueFormatStr[] = {
  300. MACROSTR(Raw),
  301. MACROSTR(SignedData)
  302. };
  303. static char * MeasurandStr[] = {
  304. MACROSTR(Current.Export),
  305. MACROSTR(Current.Import),
  306. MACROSTR(Current.Offered),
  307. MACROSTR(Energy.Active.Export.Register),
  308. MACROSTR(Energy.Active.Import.Register),
  309. MACROSTR(Energy.Reactive.Export.Register),
  310. MACROSTR(Energy.Reactive.Import.Register),
  311. MACROSTR(Energy.Active.Export.Interval),
  312. MACROSTR(Energy.Active.Import.Interval),
  313. MACROSTR(Energy.Reactive.Export.Interval),
  314. MACROSTR(Energy.Reactive.Import.Interval),
  315. MACROSTR(Frequency),
  316. MACROSTR(Power.Active.Export),
  317. MACROSTR(Power.Active.Import),
  318. MACROSTR(Power.Factor),
  319. MACROSTR(Power.Offered),
  320. MACROSTR(Power.Reactive.ExportMACROSTR),
  321. MACROSTR(Power.Reactive.Import),
  322. MACROSTR(RPM),
  323. MACROSTR(SoC),
  324. MACROSTR(Temperature),
  325. MACROSTR(Voltage)
  326. };
  327. static char * LocationStr[] = {
  328. MACROSTR(Body),
  329. MACROSTR(Cable),
  330. MACROSTR(EV),
  331. MACROSTR(Inlet),
  332. MACROSTR(Outlet)
  333. };
  334. static char * PhaseStr[] = {
  335. MACROSTR(L1),
  336. MACROSTR(L2),
  337. MACROSTR(L3),
  338. MACROSTR(N),
  339. MACROSTR(L1-N),
  340. MACROSTR(L2-N),
  341. MACROSTR(L3-N),
  342. MACROSTR(L1-L2),
  343. MACROSTR(L2-L3),
  344. MACROSTR(L3-L1)
  345. };
  346. static char * UnitOfMeasureStr[] = {
  347. MACROSTR(Wh),
  348. MACROSTR(kWh),
  349. MACROSTR(varh),
  350. MACROSTR(kvarh),
  351. MACROSTR(W),
  352. MACROSTR(kW),
  353. MACROSTR(VA),
  354. MACROSTR(kVA),
  355. MACROSTR(var),
  356. MACROSTR(kvar),
  357. MACROSTR(A),
  358. MACROSTR(V),
  359. MACROSTR(Celsius),
  360. MACROSTR(Fahrenheit),
  361. MACROSTR(K),
  362. MACROSTR(Percent)
  363. };
  364. //==========================================
  365. // Check time passed since today
  366. //==========================================
  367. long long DiffTimebWithNow(struct timeb ST)
  368. {
  369. //return milli-second
  370. struct timeb ET;
  371. long long StartTime,StopTime;
  372. ftime(&ET);
  373. StartTime=(long long)ST.time;
  374. StopTime=(long long)ET.time;
  375. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  376. }
  377. int getTimePassSinceToday()
  378. {
  379. int result = -1;
  380. time_t t;
  381. struct tm *tmStartToday;
  382. struct timeb tbStartToday;
  383. t=time(NULL);
  384. tmStartToday=localtime(&t);
  385. tmStartToday->tm_hour = 0;
  386. tmStartToday->tm_min = 0;
  387. tmStartToday->tm_sec = 0;
  388. tbStartToday.time = mktime(tmStartToday);
  389. tbStartToday.millitm = 0;
  390. result = DiffTimebWithNow(tbStartToday)/1000;
  391. return result;
  392. }
  393. //==========================================
  394. // GetCompositeSchedule logic related function
  395. //==========================================
  396. int DiffTimebSec(struct timeb ST, struct timeb ET)
  397. {
  398. //return milli-second
  399. unsigned int StartTime,StopTime;
  400. StartTime=(unsigned int)ST.time;
  401. StopTime=(unsigned int)ET.time;
  402. return (StopTime-StartTime);
  403. }
  404. int DiffTimebWithNowSec(struct timeb ST)
  405. {
  406. //return milli-second
  407. struct timeb ET;
  408. unsigned int StartTime,StopTime;
  409. ftime(&ET);
  410. StartTime=(unsigned int)ST.time;
  411. StopTime=(unsigned int)ET.time;
  412. return (StopTime-StartTime);
  413. }
  414. int getStartStop(uint8_t *start, uint8_t *stop)
  415. {
  416. int result = -1;
  417. struct tm tmStart;
  418. struct timeb tbStart;
  419. struct tm tmStop;
  420. struct timeb tbStop;
  421. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  422. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  423. {
  424. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  425. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  426. tmStart.tm_year -= 1900;
  427. tmStart.tm_mon -= 1;
  428. tbStart.time = mktime(&tmStart);
  429. tbStart.millitm = 0;
  430. tmStop.tm_year -= 1900;
  431. tmStop.tm_mon -= 1;
  432. tbStop.time = mktime(&tmStop);
  433. tbStop.millitm = 0;
  434. result = DiffTimebSec(tbStart, tbStop);
  435. //DEBUG_INFO("getStartStop(): %d\n", result);
  436. }
  437. else
  438. {
  439. DEBUG_WARN("Start or stop date parsing error.\r\n");
  440. }
  441. return result;
  442. }
  443. int isOvertNow(uint8_t *start)
  444. {
  445. int result = YES;
  446. struct tm tmStart;
  447. struct timeb tbStart;
  448. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  449. {
  450. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  451. tmStart.tm_year -= 1900;
  452. tmStart.tm_mon -= 1;
  453. tbStart.time = mktime(&tmStart);
  454. tbStart.millitm = 0;
  455. if(DiffTimebWithNowSec(tbStart) <= 0)
  456. result = NO;
  457. }
  458. else
  459. {
  460. DEBUG_WARN("Start date parsing error.\r\n");
  461. }
  462. return result;
  463. }
  464. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  465. {
  466. int result = -1;
  467. struct tm tmStart;
  468. struct timeb tbStart;
  469. struct tm tmStop;
  470. struct timeb tbStop;
  471. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  472. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  473. {
  474. tmStart.tm_year -= 1900;
  475. tmStart.tm_mon -= 1;
  476. tbStart.time = mktime(&tmStart);
  477. tbStart.millitm = 0;
  478. tmStop.tm_year -= 1900;
  479. tmStop.tm_mon -= 1;
  480. tbStop.time = mktime(&tmStop);
  481. tbStop.millitm = 0;
  482. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  483. }
  484. return result;
  485. }
  486. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  487. {
  488. FILE *fp;
  489. char profileFileName[128];
  490. char *line = NULL;
  491. size_t len = 0;
  492. time_t CurrentTime;
  493. struct tm *tmComposite;
  494. struct StructChargingProfile maxProfile;
  495. struct StructChargingProfile defaultTxProfile;
  496. struct StructChargingProfile txProfile;
  497. struct StructChargingSchedulePeriod tmpPeriod;
  498. uint8_t limitMax=0;
  499. uint8_t limitDef=0;
  500. uint8_t limitTx=0;
  501. int compositePeriodIdx = 0;
  502. CurrentTime = time(NULL);
  503. tmComposite=localtime(&CurrentTime);
  504. sprintf((char*)compositeProfile->ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  505. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  506. compositeProfile->ChargingSchedule.Duration = durationReq;
  507. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  508. {
  509. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  510. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  511. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  512. }
  513. compositeProfile->ChargingProfileId = 0;
  514. compositeProfile->StackLevel = 99 ;
  515. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  516. maxProfile.ChargingProfileId = -1;
  517. defaultTxProfile.ChargingProfileId = -1;
  518. txProfile.ChargingProfileId = -1;
  519. maxProfile.ChargingSchedule.Duration = -1;
  520. defaultTxProfile.ChargingSchedule.Duration = -1;
  521. txProfile.ChargingSchedule.Duration = -1;
  522. system("yes|rm /tmp/*.json");
  523. system("cp /Storage/OCPP/*.json /tmp");
  524. /*
  525. * Search valid charging profile
  526. */
  527. //DEBUG_INFO("====================================\n");
  528. // Search tx profile
  529. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  530. if((access(profileFileName, F_OK))!=-1)
  531. {
  532. fp = fopen(profileFileName, "r");
  533. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  534. {
  535. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  536. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  537. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  538. }
  539. txProfile.ChargingProfileId = -1;
  540. txProfile.StackLevel = -1;
  541. while(getline(&line, &len, fp) != -1)
  542. {
  543. json_object *obj = NULL;
  544. obj = json_tokener_parse(line);
  545. if(is_error(obj))
  546. {
  547. DEBUG_ERROR("Parse txProfile from file error.\n");
  548. }
  549. else
  550. {
  551. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  552. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  553. )
  554. {
  555. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  556. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  557. )
  558. {
  559. struct tm tmFrom, tmTo;
  560. struct timeb tbFrom, tbTo;
  561. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  562. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  563. {
  564. tmFrom.tm_year -= 1900;
  565. tmFrom.tm_mon -= 1;
  566. tbFrom.time = mktime(&tmFrom);
  567. tmTo.tm_year -= 1900;
  568. tmTo.tm_mon -= 1;
  569. tbTo.time = mktime(&tmTo);
  570. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  571. {
  572. if(txProfile.ChargingProfileId == -1)
  573. DEBUG_INFO("TxProfile found.\n");
  574. else
  575. DEBUG_INFO("TxProfile updated.\n");
  576. // Required item
  577. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  578. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  579. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  580. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  581. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  582. {
  583. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  584. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  585. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  586. 3:
  587. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  588. }
  589. // Optional item
  590. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  591. {
  592. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  593. }
  594. else
  595. {
  596. sprintf((char*)txProfile.ValidFrom, " ");
  597. }
  598. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  599. {
  600. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  601. }
  602. else
  603. {
  604. sprintf((char*)txProfile.ValidTo, " ");
  605. }
  606. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  607. {
  608. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  609. }
  610. else
  611. {
  612. sprintf((char*)txProfile.RecurrencyKind, " ");
  613. }
  614. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  615. {
  616. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  617. }
  618. else
  619. {
  620. txProfile.TransactionId = -1;
  621. }
  622. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  623. {
  624. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  625. }
  626. else
  627. {
  628. txProfile.ChargingSchedule.Duration = 86400;
  629. }
  630. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  631. {
  632. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  633. }
  634. else
  635. {
  636. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  637. }
  638. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  639. {
  640. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  641. }
  642. else
  643. {
  644. txProfile.ChargingSchedule.MinChargingRate = -1;
  645. }
  646. }
  647. }
  648. }
  649. else
  650. {
  651. if(txProfile.ChargingProfileId == -1)
  652. DEBUG_INFO("TxProfile found.\n");
  653. else
  654. DEBUG_INFO("TxProfile updated.\n");
  655. // Required item
  656. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  657. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  658. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  659. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  660. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  661. {
  662. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  663. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  664. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  665. 3:
  666. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  667. }
  668. // Optional item
  669. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  670. {
  671. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  672. }
  673. else
  674. {
  675. sprintf((char*)txProfile.ValidFrom, " ");
  676. }
  677. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  678. {
  679. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  680. }
  681. else
  682. {
  683. sprintf((char*)txProfile.ValidTo, " ");
  684. }
  685. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  686. {
  687. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  688. }
  689. else
  690. {
  691. sprintf((char*)txProfile.RecurrencyKind, " ");
  692. }
  693. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  694. {
  695. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  696. }
  697. else
  698. {
  699. txProfile.TransactionId = -1;
  700. }
  701. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  702. {
  703. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  704. }
  705. else
  706. {
  707. txProfile.ChargingSchedule.Duration = 86400;
  708. }
  709. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  710. {
  711. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  712. }
  713. else
  714. {
  715. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  716. }
  717. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  718. {
  719. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  720. }
  721. else
  722. {
  723. txProfile.ChargingSchedule.MinChargingRate = -1;
  724. }
  725. }
  726. }
  727. }
  728. json_object_put(obj);
  729. }
  730. fclose(fp);
  731. /*
  732. if(txProfile.ChargingProfileId != -1)
  733. {
  734. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  735. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  736. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  737. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  738. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  739. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  740. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  741. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  742. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  743. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  744. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  745. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  746. {
  747. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  748. {
  749. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  750. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  751. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  752. }
  753. }
  754. }
  755. else
  756. DEBUG_INFO("TxProfile not found.\n");*/
  757. }
  758. // Search default tx profile
  759. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  760. if((access(profileFileName, F_OK))==-1)
  761. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  762. if((access(profileFileName, F_OK))!=-1)
  763. {
  764. fp = fopen(profileFileName, "r");
  765. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  766. {
  767. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  768. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  769. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  770. }
  771. defaultTxProfile.ChargingProfileId = -1;
  772. defaultTxProfile.StackLevel = -1;
  773. while(getline(&line, &len, fp) != -1)
  774. {
  775. json_object *obj = NULL;
  776. obj = json_tokener_parse(line);
  777. if(is_error(obj))
  778. {
  779. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  780. }
  781. else
  782. {
  783. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  784. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  785. )
  786. {
  787. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  788. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  789. )
  790. {
  791. struct tm tmFrom, tmTo;
  792. struct timeb tbFrom, tbTo;
  793. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  794. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  795. {
  796. tmFrom.tm_year -= 1900;
  797. tmFrom.tm_mon -= 1;
  798. tbFrom.time = mktime(&tmFrom);
  799. tmTo.tm_year -= 1900;
  800. tmTo.tm_mon -= 1;
  801. tbTo.time = mktime(&tmTo);
  802. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  803. {
  804. if(defaultTxProfile.ChargingProfileId == -1)
  805. DEBUG_INFO("TxDefaultProfile found.\n");
  806. else
  807. DEBUG_INFO("TxDefaultProfile updated.\n");
  808. // Required item
  809. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  810. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  811. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  812. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  813. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  814. {
  815. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  816. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  817. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  818. 3:
  819. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  820. }
  821. // Optional item
  822. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  823. {
  824. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  825. }
  826. else
  827. {
  828. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  829. }
  830. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  831. {
  832. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  833. }
  834. else
  835. {
  836. sprintf((char*)defaultTxProfile.ValidTo, " ");
  837. }
  838. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  839. {
  840. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  841. }
  842. else
  843. {
  844. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  845. }
  846. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  847. {
  848. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  849. }
  850. else
  851. {
  852. defaultTxProfile.TransactionId = -1;
  853. }
  854. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  855. {
  856. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  857. }
  858. else
  859. {
  860. defaultTxProfile.ChargingSchedule.Duration = 86400;
  861. }
  862. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  863. {
  864. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  865. }
  866. else
  867. {
  868. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  869. }
  870. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  871. {
  872. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  873. }
  874. else
  875. {
  876. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  877. }
  878. }
  879. }
  880. }
  881. else
  882. {
  883. if(defaultTxProfile.ChargingProfileId == -1)
  884. DEBUG_INFO("TxDefaultProfile found.\n");
  885. else
  886. DEBUG_INFO("TxDefaultProfile updated.\n");
  887. // Required item
  888. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  889. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  890. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  891. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  892. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  893. {
  894. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  895. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  896. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  897. 3:
  898. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  899. }
  900. // Optional item
  901. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  902. {
  903. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  904. }
  905. else
  906. {
  907. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  908. }
  909. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  910. {
  911. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  912. }
  913. else
  914. {
  915. sprintf((char*)defaultTxProfile.ValidTo, " ");
  916. }
  917. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  918. {
  919. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  920. }
  921. else
  922. {
  923. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  924. }
  925. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  926. {
  927. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  928. }
  929. else
  930. {
  931. defaultTxProfile.TransactionId = -1;
  932. }
  933. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  934. {
  935. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  936. }
  937. else
  938. {
  939. defaultTxProfile.ChargingSchedule.Duration = 86400;
  940. }
  941. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  942. {
  943. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  944. }
  945. else
  946. {
  947. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  948. }
  949. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  950. {
  951. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  952. }
  953. else
  954. {
  955. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  956. }
  957. }
  958. }
  959. }
  960. json_object_put(obj);
  961. }
  962. fclose(fp);
  963. /*
  964. if(defaultTxProfile.ChargingProfileId != -1)
  965. {
  966. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  967. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  968. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  969. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  970. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  971. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  972. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  973. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  974. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  975. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  976. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  977. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  978. {
  979. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  980. {
  981. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  982. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  983. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  984. }
  985. }
  986. }
  987. else
  988. DEBUG_INFO("TxDefaultProfile not found.\n");
  989. DEBUG_INFO("------------------------------------\n");*/
  990. }
  991. // Search max profile
  992. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  993. if((access(profileFileName, F_OK))!=-1)
  994. {
  995. fp = fopen(profileFileName, "r");
  996. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  997. {
  998. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  999. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1000. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1001. }
  1002. maxProfile.ChargingProfileId = -1;
  1003. maxProfile.StackLevel = -1;
  1004. while(getline(&line, &len, fp) != -1)
  1005. {
  1006. json_object *obj = NULL;
  1007. obj = json_tokener_parse(line);
  1008. if(is_error(obj))
  1009. {
  1010. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1011. }
  1012. else
  1013. {
  1014. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1015. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1016. )
  1017. {
  1018. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1019. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1020. )
  1021. {
  1022. struct tm tmFrom, tmTo;
  1023. struct timeb tbFrom, tbTo;
  1024. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1025. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1026. {
  1027. tmFrom.tm_year -= 1900;
  1028. tmFrom.tm_mon -= 1;
  1029. tbFrom.time = mktime(&tmFrom);
  1030. tmTo.tm_year -= 1900;
  1031. tmTo.tm_mon -= 1;
  1032. tbTo.time = mktime(&tmTo);
  1033. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1034. {
  1035. if(maxProfile.ChargingProfileId == -1)
  1036. DEBUG_INFO("MaxProfile found.\n");
  1037. else
  1038. DEBUG_INFO("MaxProfile updated.\n");
  1039. // Required item
  1040. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1041. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1042. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1043. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1044. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1045. {
  1046. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1047. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1048. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1049. 3:
  1050. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1051. }
  1052. // Optional item
  1053. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1054. {
  1055. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1056. }
  1057. else
  1058. {
  1059. sprintf((char*)maxProfile.ValidFrom, " ");
  1060. }
  1061. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1062. {
  1063. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1064. }
  1065. else
  1066. {
  1067. sprintf((char*)maxProfile.ValidTo, " ");
  1068. }
  1069. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1070. {
  1071. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1072. }
  1073. else
  1074. {
  1075. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1076. }
  1077. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1078. {
  1079. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1080. }
  1081. else
  1082. {
  1083. maxProfile.TransactionId = -1;
  1084. }
  1085. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1086. {
  1087. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1088. }
  1089. else
  1090. {
  1091. maxProfile.ChargingSchedule.Duration = 86400;
  1092. }
  1093. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1094. {
  1095. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1096. }
  1097. else
  1098. {
  1099. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1100. }
  1101. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1102. {
  1103. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1104. }
  1105. else
  1106. {
  1107. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1108. }
  1109. }
  1110. }
  1111. }
  1112. else
  1113. {
  1114. if(maxProfile.ChargingProfileId == -1)
  1115. DEBUG_INFO("MaxProfile found.\n");
  1116. else
  1117. DEBUG_INFO("MaxProfile updated.\n");
  1118. // Required item
  1119. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1120. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1121. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1122. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1123. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1124. {
  1125. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1126. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1127. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1128. 3:
  1129. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1130. }
  1131. // Optional item
  1132. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1133. {
  1134. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1135. }
  1136. else
  1137. {
  1138. sprintf((char*)maxProfile.ValidFrom, " ");
  1139. }
  1140. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1141. {
  1142. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1143. }
  1144. else
  1145. {
  1146. sprintf((char*)maxProfile.ValidTo, " ");
  1147. }
  1148. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1149. {
  1150. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1151. }
  1152. else
  1153. {
  1154. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1155. }
  1156. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1157. {
  1158. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1159. }
  1160. else
  1161. {
  1162. maxProfile.TransactionId = -1;
  1163. }
  1164. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1165. {
  1166. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1167. }
  1168. else
  1169. {
  1170. maxProfile.ChargingSchedule.Duration = 86400;
  1171. }
  1172. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1173. {
  1174. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1175. }
  1176. else
  1177. {
  1178. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1179. }
  1180. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1181. {
  1182. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1183. }
  1184. else
  1185. {
  1186. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1187. }
  1188. }
  1189. }
  1190. }
  1191. json_object_put(obj);
  1192. }
  1193. fclose(fp);
  1194. /*
  1195. if(maxProfile.ChargingProfileId !=-1)
  1196. {
  1197. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1198. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1199. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1200. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1201. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1202. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1203. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1204. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1205. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1206. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1207. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1208. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1209. {
  1210. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1211. {
  1212. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1213. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1214. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1215. }
  1216. }
  1217. }
  1218. else
  1219. DEBUG_INFO("MaxProfile not found.\n");
  1220. DEBUG_INFO("------------------------------------\n");*/
  1221. }
  1222. /*
  1223. * Align found profile start schedule & periods
  1224. */
  1225. //DEBUG_INFO("====================================\n");
  1226. /*
  1227. // For local test usage, force modify found profile start schedule info
  1228. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-10);
  1229. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-5);
  1230. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-3);
  1231. */
  1232. if(txProfile.ChargingProfileId != -1)
  1233. {
  1234. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1235. {
  1236. if(txProfile.ChargingSchedule.Duration != -1)
  1237. {
  1238. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1239. 0:
  1240. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1241. }
  1242. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1243. {
  1244. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1245. {
  1246. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1247. 0:
  1248. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1249. if(idxPeriod > 0)
  1250. {
  1251. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1252. {
  1253. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1254. }
  1255. }
  1256. }
  1257. }
  1258. }
  1259. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1260. {
  1261. if(txProfile.ChargingSchedule.Duration != -1)
  1262. {
  1263. txProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1264. 0:
  1265. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1266. }
  1267. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1268. {
  1269. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1270. {
  1271. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1272. 0:
  1273. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1274. if(idxPeriod > 0)
  1275. {
  1276. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1277. {
  1278. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1279. }
  1280. }
  1281. }
  1282. }
  1283. }
  1284. else
  1285. {
  1286. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1287. {
  1288. if(txProfile.ChargingSchedule.Duration != -1)
  1289. {
  1290. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1291. 0:
  1292. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1293. }
  1294. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1295. {
  1296. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1297. {
  1298. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1299. 0:
  1300. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1301. if(idxPeriod > 0)
  1302. {
  1303. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1304. {
  1305. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1306. }
  1307. }
  1308. }
  1309. }
  1310. }
  1311. else
  1312. {
  1313. if(txProfile.ChargingSchedule.Duration != -1)
  1314. {
  1315. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1316. 0:
  1317. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1318. }
  1319. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1320. {
  1321. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1322. {
  1323. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1324. 0:
  1325. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1326. if(idxPeriod > 0)
  1327. {
  1328. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1329. {
  1330. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1331. }
  1332. }
  1333. }
  1334. }
  1335. }
  1336. }
  1337. /*
  1338. DEBUG_INFO("txProfile after align.\n");
  1339. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1340. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1341. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1342. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1343. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1344. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1345. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1346. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1347. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1348. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1349. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1350. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1351. {
  1352. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1353. {
  1354. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1355. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1356. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1357. }
  1358. }*/
  1359. }
  1360. if(defaultTxProfile.ChargingProfileId != -1)
  1361. {
  1362. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1363. {
  1364. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1365. {
  1366. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1367. 0:
  1368. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1369. }
  1370. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1371. {
  1372. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1373. {
  1374. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1375. 0:
  1376. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1377. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1378. {
  1379. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1380. }
  1381. if(idxPeriod > 0)
  1382. {
  1383. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1384. {
  1385. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1386. }
  1387. }
  1388. }
  1389. }
  1390. }
  1391. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1392. {
  1393. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1394. {
  1395. defaultTxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1396. 0:
  1397. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1398. }
  1399. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1400. {
  1401. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1402. {
  1403. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1404. 0:
  1405. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1406. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1407. {
  1408. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1409. }
  1410. if(idxPeriod > 0)
  1411. {
  1412. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1413. {
  1414. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1415. }
  1416. }
  1417. }
  1418. }
  1419. }
  1420. else
  1421. {
  1422. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1423. {
  1424. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1425. {
  1426. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1427. 0:
  1428. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1429. }
  1430. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1431. {
  1432. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1433. {
  1434. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1435. 0:
  1436. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1437. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1438. {
  1439. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1440. }
  1441. if(idxPeriod > 0)
  1442. {
  1443. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1444. {
  1445. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1446. }
  1447. }
  1448. }
  1449. }
  1450. }
  1451. else
  1452. {
  1453. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1454. {
  1455. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1456. 0:
  1457. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1458. }
  1459. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1460. {
  1461. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1462. {
  1463. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1464. 0:
  1465. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1466. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1467. {
  1468. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1469. }
  1470. if(idxPeriod > 0)
  1471. {
  1472. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1473. {
  1474. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1475. }
  1476. }
  1477. }
  1478. }
  1479. }
  1480. }
  1481. /*
  1482. DEBUG_INFO("defaultTxProfile after align.\n");
  1483. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1484. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1485. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1486. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1487. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1488. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1489. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1490. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1491. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1492. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1493. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1494. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1495. {
  1496. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1497. {
  1498. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1499. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1500. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1501. }
  1502. }
  1503. DEBUG_INFO("------------------------------------\n");*/
  1504. }
  1505. if(maxProfile.ChargingProfileId != -1)
  1506. {
  1507. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1508. {
  1509. if(maxProfile.ChargingSchedule.Duration != -1)
  1510. {
  1511. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1512. 0:
  1513. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1514. }
  1515. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1516. {
  1517. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1518. {
  1519. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1520. 0:
  1521. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1522. if(idxPeriod > 0)
  1523. {
  1524. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1525. {
  1526. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1527. }
  1528. }
  1529. }
  1530. }
  1531. }
  1532. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1533. {
  1534. if(maxProfile.ChargingSchedule.Duration != -1)
  1535. {
  1536. maxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1537. 0:
  1538. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1539. }
  1540. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1541. {
  1542. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1543. {
  1544. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1545. 0:
  1546. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1547. if(idxPeriod > 0)
  1548. {
  1549. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1550. {
  1551. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1552. }
  1553. }
  1554. }
  1555. }
  1556. }
  1557. else
  1558. {
  1559. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1560. {
  1561. if(maxProfile.ChargingSchedule.Duration != -1)
  1562. {
  1563. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1564. 0:
  1565. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1566. }
  1567. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1568. {
  1569. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1570. {
  1571. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1572. 0:
  1573. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1574. if(idxPeriod > 0)
  1575. {
  1576. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1577. {
  1578. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1579. }
  1580. }
  1581. }
  1582. }
  1583. }
  1584. else
  1585. {
  1586. if(maxProfile.ChargingSchedule.Duration != -1)
  1587. {
  1588. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1589. 0:
  1590. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1591. }
  1592. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1593. {
  1594. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1595. {
  1596. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1597. 0:
  1598. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1599. if(idxPeriod > 0)
  1600. {
  1601. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1602. {
  1603. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1604. }
  1605. }
  1606. }
  1607. }
  1608. }
  1609. }
  1610. /*
  1611. DEBUG_INFO("MaxProfile after align.\n");
  1612. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1613. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1614. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1615. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1616. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1617. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1618. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1619. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1620. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1621. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1622. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1623. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1624. {
  1625. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1626. {
  1627. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1628. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1629. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1630. }
  1631. }
  1632. DEBUG_INFO("------------------------------------\n");*/
  1633. }
  1634. /*
  1635. * Merge to conposite schedule
  1636. */
  1637. //DEBUG_INFO("====================================\n");
  1638. // Find each profile period quantity
  1639. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1640. {
  1641. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1642. limitMax = idx+1;
  1643. }
  1644. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1645. {
  1646. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1647. limitDef = idx+1;
  1648. }
  1649. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1650. {
  1651. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1652. limitTx = idx+1;
  1653. }
  1654. // TxProfile found, composite schedule based on it
  1655. if(txProfile.ChargingProfileId != -1)
  1656. {
  1657. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1658. {
  1659. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1660. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  1661. (txProfile.ChargingSchedule.Duration > 0))
  1662. {
  1663. if(maxProfile.ChargingProfileId != -1)
  1664. {
  1665. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1666. {
  1667. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  1668. {
  1669. if((maxProfile.ChargingSchedule.Duration > 0))
  1670. {
  1671. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1672. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1673. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1674. }
  1675. else
  1676. {
  1677. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1678. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1679. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  1680. }
  1681. }
  1682. if(idxMaxPeriod == (limitMax-1))
  1683. {
  1684. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1685. {
  1686. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1687. {
  1688. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1689. compositePeriodIdx++;
  1690. }
  1691. else
  1692. {
  1693. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1694. }
  1695. }
  1696. }
  1697. }
  1698. }
  1699. else
  1700. {
  1701. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1702. {
  1703. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1704. compositePeriodIdx++;
  1705. }
  1706. else
  1707. {
  1708. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1709. }
  1710. }
  1711. }
  1712. if(idxTxPeriod == (limitTx-1))
  1713. {
  1714. if(defaultTxProfile.ChargingProfileId != -1)
  1715. {
  1716. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1717. {
  1718. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  1719. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1720. (defaultTxProfile.ChargingSchedule.Duration>0))
  1721. {
  1722. if(maxProfile.ChargingProfileId != -1)
  1723. {
  1724. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1725. {
  1726. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1727. {
  1728. if((maxProfile.ChargingSchedule.Duration > 0))
  1729. {
  1730. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1731. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1732. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1733. }
  1734. else
  1735. {
  1736. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1737. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1738. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1739. }
  1740. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1741. {
  1742. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1743. {
  1744. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1745. compositePeriodIdx++;
  1746. }
  1747. else
  1748. {
  1749. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1750. }
  1751. }
  1752. break;
  1753. }
  1754. }
  1755. }
  1756. else
  1757. {
  1758. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1759. {
  1760. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1761. compositePeriodIdx++;
  1762. }
  1763. else
  1764. {
  1765. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1766. }
  1767. }
  1768. }
  1769. }
  1770. }
  1771. }
  1772. }
  1773. }
  1774. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1775. else if(defaultTxProfile.ChargingProfileId != -1)
  1776. {
  1777. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1778. {
  1779. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1780. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1781. (defaultTxProfile.ChargingSchedule.Duration > 0))
  1782. {
  1783. if(maxProfile.ChargingProfileId != -1)
  1784. {
  1785. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1786. {
  1787. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1788. {
  1789. if((maxProfile.ChargingSchedule.Duration > 0))
  1790. {
  1791. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1792. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1793. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1794. }
  1795. else
  1796. {
  1797. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1798. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1799. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1800. }
  1801. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1802. {
  1803. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1804. {
  1805. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1806. compositePeriodIdx++;
  1807. }
  1808. else
  1809. {
  1810. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1811. }
  1812. }
  1813. break;
  1814. }
  1815. }
  1816. }
  1817. else
  1818. {
  1819. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1820. {
  1821. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1822. compositePeriodIdx++;
  1823. }
  1824. else
  1825. {
  1826. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1827. }
  1828. }
  1829. }
  1830. }
  1831. }
  1832. // Fill other period by MaxProfile
  1833. if(maxProfile.ChargingProfileId != -1)
  1834. {
  1835. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1836. {
  1837. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1838. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1839. (maxProfile.ChargingSchedule.Duration > 0))
  1840. {
  1841. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  1842. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1843. {
  1844. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  1845. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  1846. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1847. }
  1848. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1849. {
  1850. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  1851. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  1852. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1853. }
  1854. if(tmpPeriod.Limit != -1)
  1855. {
  1856. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1857. {
  1858. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1859. {
  1860. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1861. compositePeriodIdx++;
  1862. }
  1863. else
  1864. {
  1865. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1866. }
  1867. }
  1868. }
  1869. }
  1870. }
  1871. }
  1872. DEBUG_INFO("Composite schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1873. DEBUG_INFO("Composite schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1874. DEBUG_INFO("Composite rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1875. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1876. {
  1877. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1878. {
  1879. compositeProfile->ChargingProfileId = 1;
  1880. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1881. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1882. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1883. }
  1884. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1885. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1886. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1887. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1888. }
  1889. if(line)
  1890. free(line);
  1891. }
  1892. //==========================================
  1893. // Init all share memory
  1894. //==========================================
  1895. int InitShareMemory()
  1896. {
  1897. int result = PASS;
  1898. int MeterSMId;
  1899. //creat ShmSysConfigAndInfo
  1900. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1901. {
  1902. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1903. result = FAIL;
  1904. }
  1905. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1906. {
  1907. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  1908. result = FAIL;
  1909. }
  1910. else
  1911. {}
  1912. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1913. {
  1914. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1915. result = FAIL;
  1916. }
  1917. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1918. {
  1919. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1920. result = FAIL;
  1921. }
  1922. else
  1923. {}
  1924. //creat ShmPsuData
  1925. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  1926. {
  1927. DEBUG_ERROR("shmget ShmPsuData NG\n");
  1928. result = FAIL;
  1929. }
  1930. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1931. {
  1932. DEBUG_ERROR("shmat ShmPsuData NG\n");
  1933. result = FAIL;
  1934. }
  1935. else
  1936. {}
  1937. //creat ShmOCPP16Data
  1938. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1939. {
  1940. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  1941. result = FAIL;
  1942. }
  1943. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1944. {
  1945. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  1946. result = FAIL;
  1947. }
  1948. else
  1949. {}
  1950. /****************************** For Initial Settings************************************************/
  1951. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  1952. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  1953. // allocate Configuration memory address
  1954. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  1955. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  1956. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  1957. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  1958. //offline MeterValue Interval
  1959. TempMeterValueInterval = 0;
  1960. return result;
  1961. }
  1962. int ProcessShareMemory()
  1963. {
  1964. if(InitShareMemory() == FAIL)
  1965. {
  1966. DEBUG_ERROR("InitShareMemory NG\n");
  1967. if(ShmStatusCodeData!=NULL)
  1968. {
  1969. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1970. }
  1971. sleep(5);
  1972. return FAIL;
  1973. }
  1974. return PASS;
  1975. }
  1976. //---------------------common routine---------------------------//
  1977. int isOFFline(void)
  1978. {
  1979. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  1980. {
  1981. if(TempMeterValueInterval >= 2 )
  1982. {
  1983. TempMeterValueInterval = 0;
  1984. return TRUE;
  1985. }
  1986. else
  1987. {
  1988. TempMeterValueInterval = TempMeterValueInterval+ 1;
  1989. return FALSE;
  1990. }
  1991. }
  1992. else
  1993. {
  1994. return FALSE;
  1995. }
  1996. }
  1997. //---------------------------------------------
  1998. // new:
  1999. // enum SYSTEM_STATUS
  2000. // {
  2001. // SYS_MODE_BOOTING = 0,
  2002. // SYS_MODE_IDLE = 1,
  2003. // SYS_MODE_AUTHORIZING = 2,
  2004. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  2005. // SYS_MODE_REASSIGN = 4,
  2006. // SYS_MODE_PREPARING = 5,
  2007. // SYS_MODE_PREPARE_FOR_EV = 6,
  2008. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  2009. // SYS_MODE_CHARGING = 8,
  2010. // SYS_MODE_TERMINATING = 9,
  2011. // SYS_MODE_COMPLETE = 10,
  2012. // SYS_MODE_ALARM = 11,
  2013. // SYS_MODE_FAULT = 12,
  2014. // SYS_MODE_RESERVATION = 13,
  2015. // SYS_MODE_BOOKING = 14,
  2016. // SYS_MODE_MAINTAIN = 15,
  2017. // SYS_MODE_DEBUG = 16,
  2018. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  2019. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  2020. // SYS_MODE_UPDATE = 19
  2021. // };
  2022. //
  2023. //
  2024. //-----------------------------------------
  2025. void CheckSystemValue(void)
  2026. {
  2027. uint8_t reqSampleMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2028. uint8_t reqClockAlignMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2029. char filenmae[100]={0};
  2030. char str[100]={0};
  2031. int tempIndex = 0;
  2032. //===============================
  2033. // send Heartbeat
  2034. //===============================
  2035. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2036. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2037. {
  2038. clientTime.Heartbeat=time((time_t*)NULL);
  2039. if(server_sign == TRUE)
  2040. {
  2041. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2042. }
  2043. else
  2044. {
  2045. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2046. }
  2047. }
  2048. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  2049. {
  2050. //parameter for test
  2051. sendHeartbeatRequest(0);
  2052. //==============================================
  2053. // Reset Waiting Time
  2054. //==============================================
  2055. clientTime.Heartbeat=time((time_t*)NULL);
  2056. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  2057. }
  2058. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2059. {
  2060. //===============================
  2061. // CSU Trigger Reset Conf
  2062. //===============================
  2063. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2064. {
  2065. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2066. }
  2067. //===============================
  2068. // CSU Trigger Authorize Request
  2069. //===============================
  2070. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2071. {
  2072. sendAuthorizeRequest(0);
  2073. authorizeRetryTimes = authorizeRetryTimes + 1;
  2074. if(authorizeRetryTimes < 3)
  2075. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2076. }
  2077. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2078. {
  2079. authorizeRetryTimes = 0;
  2080. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  2081. server_sign = FALSE;
  2082. }
  2083. 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))
  2084. {
  2085. sendAuthorizeRequest(0);
  2086. }
  2087. //===============================
  2088. // CSU Trigger Smart Charging Profilw
  2089. //===============================
  2090. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2091. {
  2092. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  2093. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2094. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  2095. }
  2096. //==============================================
  2097. // Charger start transaction
  2098. //==============================================
  2099. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2100. {
  2101. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  2102. sendStartTransactionRequest(gun_index);
  2103. clientTime.StartTransaction = time((time_t*)NULL);
  2104. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2105. }
  2106. //==============================================
  2107. // Charger stop transaction
  2108. //==============================================
  2109. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2110. {
  2111. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  2112. sendStopTransactionRequest(gun_index);
  2113. clientTime.StopTransaction = time((time_t*)NULL);
  2114. }
  2115. //==============================================
  2116. // Charger status report
  2117. //==============================================
  2118. //--- Check Mode Change ---//
  2119. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2120. if(gunType[gun_index] == 'J')
  2121. {
  2122. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2123. {
  2124. tempIndex = ((gun_index==2) ? 1: 0);
  2125. }
  2126. else
  2127. {
  2128. tempIndex = gun_index;
  2129. }
  2130. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2131. {
  2132. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2133. {
  2134. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2135. {
  2136. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2137. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2138. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2139. statusModeChage[gun_index] = TRUE;
  2140. }
  2141. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2142. {
  2143. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2144. if((access(filenmae,F_OK))!=-1)
  2145. {
  2146. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2147. sprintf(str,"rm -f %s",filenmae);
  2148. system(str);
  2149. }
  2150. }
  2151. #if 1 // for TempStopTransaction
  2152. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2153. {
  2154. checkTempStopTransaction(gun_index);
  2155. }
  2156. #endif
  2157. }
  2158. }
  2159. }
  2160. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2161. {
  2162. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2163. {
  2164. tempIndex = ((gun_index==2) ? 1: 0);
  2165. }
  2166. else
  2167. {
  2168. tempIndex = gun_index;
  2169. }
  2170. for (int index = 0; index < CCS_QUANTITY; index++)
  2171. {
  2172. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2173. {
  2174. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  2175. {
  2176. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2177. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2178. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2179. statusModeChage[gun_index] = TRUE;
  2180. }
  2181. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2182. {
  2183. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2184. if((access(filenmae,F_OK))!=-1)
  2185. {
  2186. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2187. sprintf(str,"rm -f %s",filenmae);
  2188. system(str);
  2189. }
  2190. }
  2191. #if 1 // for TempStopTransaction
  2192. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2193. {
  2194. checkTempStopTransaction(gun_index);
  2195. }
  2196. #endif
  2197. }
  2198. }
  2199. }
  2200. else if(gunType[gun_index] == 'G')
  2201. {
  2202. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2203. {
  2204. tempIndex = ((gun_index==2) ? 1: 0);
  2205. }
  2206. else
  2207. {
  2208. tempIndex = gun_index;
  2209. }
  2210. for (int index = 0; index < GB_QUANTITY; index++)
  2211. {
  2212. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2213. {
  2214. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2215. {
  2216. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2217. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2218. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2219. statusModeChage[gun_index] = TRUE;
  2220. }
  2221. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2222. {
  2223. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2224. if((access(filenmae,F_OK))!=-1)
  2225. {
  2226. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2227. sprintf(str,"rm -f %s",filenmae);
  2228. system(str);
  2229. }
  2230. }
  2231. #if 1 // for TempStopTransaction
  2232. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2233. {
  2234. checkTempStopTransaction(gun_index);
  2235. }
  2236. #endif
  2237. }
  2238. }
  2239. }
  2240. else
  2241. {
  2242. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2243. {
  2244. tempIndex = 2;
  2245. }
  2246. else
  2247. {
  2248. tempIndex = gun_index;
  2249. }
  2250. for (int index = 0; index < AC_QUANTITY; index++)
  2251. {
  2252. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2253. {
  2254. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2255. {
  2256. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2257. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2258. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2259. statusModeChage[gun_index] = TRUE;
  2260. }
  2261. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2262. {
  2263. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2264. if((access(filenmae,F_OK))!=-1)
  2265. {
  2266. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2267. sprintf(str,"rm -f %s",filenmae);
  2268. system(str);
  2269. }
  2270. }
  2271. #if 1 // for TempStopTransaction
  2272. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2273. {
  2274. checkTempStopTransaction(gun_index);
  2275. }
  2276. #endif
  2277. }
  2278. }// END
  2279. }
  2280. if(isWebsocketSendable &&
  2281. (((statusModeChage[gun_index] == TRUE) || ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 10)))) )
  2282. {
  2283. if(SystemInitial > 0)
  2284. SystemInitial -= 1;
  2285. sendStatusNotificationRequest(gun_index);
  2286. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2287. statusModeChage[gun_index] = FALSE;
  2288. }
  2289. //==============================================
  2290. // Meter report
  2291. //==============================================
  2292. if(cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2293. {
  2294. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2295. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2296. }
  2297. if(/*(server_sign == TRUE) &&(isOFFline() == TRUE) ||*/
  2298. (((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)))
  2299. {
  2300. //check Transaction active
  2301. if(gunType[gun_index] == 'J')
  2302. {
  2303. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2304. {
  2305. tempIndex = ((gun_index==2) ? 1: 0);
  2306. }
  2307. else
  2308. {
  2309. tempIndex = gun_index;
  2310. }
  2311. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2312. {
  2313. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2314. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2315. {
  2316. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2317. {
  2318. reqSampleMeter[gun_index] = 1;
  2319. }
  2320. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2321. {
  2322. reqClockAlignMeter[gun_index] = 1;
  2323. }
  2324. }
  2325. }// End for CHAdeMO
  2326. }
  2327. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2328. {
  2329. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2330. {
  2331. tempIndex = ((gun_index==2) ? 1: 0);
  2332. }
  2333. else
  2334. {
  2335. tempIndex = gun_index;
  2336. }
  2337. for (int index = 0; index < CCS_QUANTITY; index++)
  2338. {
  2339. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2340. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2341. {
  2342. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2343. {
  2344. reqSampleMeter[gun_index] = 1;
  2345. }
  2346. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2347. {
  2348. reqClockAlignMeter[gun_index] = 1;
  2349. }
  2350. }
  2351. } // End for CCS
  2352. }
  2353. else if(gunType[gun_index] == 'G')
  2354. {
  2355. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2356. {
  2357. tempIndex = ((gun_index==2) ? 1: 0);
  2358. }
  2359. else
  2360. {
  2361. tempIndex = gun_index;
  2362. }
  2363. for (int index = 0; index < GB_QUANTITY; index++)
  2364. {
  2365. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2366. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2367. {
  2368. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2369. {
  2370. reqSampleMeter[gun_index] = 1;
  2371. }
  2372. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2373. {
  2374. reqClockAlignMeter[gun_index] = 1;
  2375. }
  2376. }
  2377. }// End for GB
  2378. }
  2379. else
  2380. {
  2381. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2382. {
  2383. tempIndex = 2;
  2384. }
  2385. else
  2386. {
  2387. tempIndex = gun_index;
  2388. }
  2389. for (int index = 0; index < AC_QUANTITY; index++)
  2390. {
  2391. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2392. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2393. {
  2394. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2395. {
  2396. reqSampleMeter[gun_index] = 1;
  2397. }
  2398. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2399. {
  2400. reqClockAlignMeter[gun_index] = 1;
  2401. }
  2402. }
  2403. }//End for AC
  2404. }
  2405. if(reqSampleMeter[gun_index] == 1)
  2406. {
  2407. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2408. storeTempStopTransaction(gun_index);
  2409. }
  2410. else if(reqClockAlignMeter[gun_index] == 1)
  2411. {
  2412. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2413. }
  2414. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2415. sleep(1);
  2416. }
  2417. //==============================================
  2418. // Check Connector reserved
  2419. //==============================================
  2420. //===============================
  2421. // Check if Reserve is expired
  2422. //===============================
  2423. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2424. {
  2425. double diff_t;
  2426. struct tm tp;
  2427. // current time
  2428. time_t t = time(NULL);
  2429. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2430. tp.tm_isdst = -1;
  2431. time_t utc = mktime(&tp);
  2432. diff_t = difftime(utc, t);
  2433. if(diff_t <= 0)
  2434. {
  2435. DEBUG_INFO("reserve expired.\n");
  2436. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2437. }
  2438. }//END OF Check if Reserve is expired
  2439. //==========================================
  2440. // csu trigger FirmwareStatusNotificationReq
  2441. //==========================================
  2442. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2443. {
  2444. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2445. }
  2446. //==========================================
  2447. // csu trigger CancelReservationConf
  2448. //==========================================
  2449. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2450. {
  2451. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2452. }
  2453. //==========================================
  2454. // csu trigger ChangeAvailabilityConf
  2455. //==========================================
  2456. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2457. {
  2458. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2459. }
  2460. //==========================================
  2461. // csu trigger UnlockConnectorConf
  2462. //==========================================
  2463. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2464. {
  2465. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2466. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2467. }
  2468. //==========================================
  2469. // csu trigger ReserveNowConf
  2470. //==========================================
  2471. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2472. {
  2473. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2474. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2475. }
  2476. //==========================================
  2477. // csu trigger DataTransferReq
  2478. //==========================================
  2479. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2480. {
  2481. sendDataTransferRequest(gun_index);
  2482. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2483. }
  2484. }
  2485. }
  2486. //==========================================
  2487. // send request routine
  2488. //==========================================
  2489. int sendAuthorizeRequest(int gun_index)
  2490. {
  2491. mtrace();
  2492. int result = FAIL;
  2493. char message[100]={0};
  2494. char guid[37];
  2495. char tempdata[65]={0};
  2496. DEBUG_INFO("sendAuthorizeRequest...\n");
  2497. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2498. //Local Authorize
  2499. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2500. {
  2501. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2502. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2503. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2504. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2505. result = PASS;
  2506. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2507. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2508. authorizeRetryTimes = 0;
  2509. return result;
  2510. }
  2511. 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))||
  2512. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2513. {
  2514. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2515. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2516. {
  2517. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2518. {
  2519. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2520. }
  2521. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2522. {
  2523. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2524. }
  2525. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  2526. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2527. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2528. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2529. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2530. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2531. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2532. authorizeRetryTimes = 0;
  2533. return result;
  2534. }
  2535. else
  2536. {
  2537. DEBUG_INFO("offline Local Authorization get result !!!!\n");
  2538. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2539. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2540. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  2541. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  2542. else
  2543. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2544. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2545. result = PASS;
  2546. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2547. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2548. authorizeRetryTimes = 0;
  2549. return result;
  2550. }
  2551. }
  2552. //initailize struct Authorize
  2553. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2554. //get data from shared memory
  2555. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2556. random_uuid(guid);
  2557. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2558. LWS_Send(message);
  2559. sprintf(tempdata, "Authorize,%d", gun_index);
  2560. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2561. {
  2562. result = PASS;
  2563. DEBUG_INFO("Authorize mapItem pass\n");
  2564. }
  2565. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2566. return result;
  2567. }
  2568. int sendBootNotificationRequest(void)
  2569. {
  2570. mtrace();
  2571. int result = FAIL;
  2572. char message[500]={0}, payload[700]={0};
  2573. char guid[37]={0};
  2574. char tempdata[65]={0};
  2575. /*
  2576. int IsGunCharging = FALSE;
  2577. //check Transaction active
  2578. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2579. {
  2580. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2581. {
  2582. IsGunCharging = TRUE;
  2583. }
  2584. }
  2585. for (int index = 0; index < CCS_QUANTITY; index++)
  2586. {
  2587. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2588. {
  2589. IsGunCharging = TRUE;
  2590. }
  2591. }
  2592. for (int index = 0; index < GB_QUANTITY; index++)
  2593. {
  2594. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2595. {
  2596. IsGunCharging = TRUE;
  2597. }
  2598. }
  2599. for (int index = 0; index < AC_QUANTITY; index++)
  2600. {
  2601. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2602. {
  2603. IsGunCharging = TRUE;
  2604. }
  2605. }
  2606. if(IsGunCharging == TRUE)
  2607. {
  2608. server_sign = TRUE;
  2609. return result;
  2610. }
  2611. */
  2612. // Fill BootNotification fields
  2613. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2614. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2615. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2616. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2617. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2618. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2619. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2620. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2621. ShmOCPP16Data->ChargeBoxId
  2622. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2623. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2624. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2625. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2626. ,ShmOCPP16Data->BootNotification.CpIccid
  2627. ,ShmOCPP16Data->BootNotification.CpImsi);
  2628. random_uuid(guid);
  2629. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2630. LWS_Send(message);
  2631. sprintf(tempdata, "BootNotification,0");
  2632. 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*/)
  2633. {
  2634. result = PASS;
  2635. }
  2636. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2637. strcpy(queuedata,message);
  2638. return result;
  2639. }
  2640. int sendDataTransferRequest(int gun_index)
  2641. {
  2642. mtrace();
  2643. char message[1000]={0};
  2644. char guid[37]={0};
  2645. char tempdata[65]={0};
  2646. int result = FAIL;
  2647. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2648. random_uuid(guid);
  2649. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2650. MESSAGE_TYPE_CALL,
  2651. guid,
  2652. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2653. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2654. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2655. LWS_Send(message);
  2656. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2657. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2658. {
  2659. result = PASS;
  2660. DEBUG_INFO("DataTransfer mapItem pass\n");
  2661. }
  2662. return result;
  2663. }
  2664. int sendDiagnosticsStatusNotificationRequest(char *status)
  2665. {
  2666. mtrace();
  2667. int result = FAIL;
  2668. char message[110]={0};
  2669. char guid[37]={0};
  2670. char tempdata[65]={0};
  2671. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2672. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2673. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2674. random_uuid(guid);
  2675. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2676. LWS_Send(message);
  2677. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2678. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2679. {
  2680. result = PASS;
  2681. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2682. }
  2683. //#ifdef SystemLogMessage
  2684. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2685. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2686. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2687. //#endif
  2688. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2689. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2690. //record status
  2691. if(strcmp(status,"Idle")==0)
  2692. {
  2693. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2694. }
  2695. else if(strcmp(status,"Uploaded")==0)
  2696. {
  2697. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2698. }
  2699. else if(strcmp(status,"UploadFailed")==0)
  2700. {
  2701. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2702. }
  2703. else if(strcmp(status,"Uploading")==0)
  2704. {
  2705. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2706. }
  2707. return result;
  2708. }
  2709. int sendFirmwareStatusNotificationRequest(char *status)
  2710. {
  2711. mtrace();
  2712. int result = FAIL;
  2713. char message[110]={0};
  2714. char guid[37]={0};
  2715. char tempdata[65]={0};
  2716. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2717. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2718. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2719. random_uuid(guid);
  2720. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2721. LWS_Send(message);
  2722. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2723. 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*/)
  2724. {
  2725. result = PASS;
  2726. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2727. }
  2728. //#ifdef SystemLogMessage
  2729. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2730. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2731. //#endif
  2732. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2733. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2734. //record status
  2735. if(strcmp(status,"Downloaded")==0)
  2736. {
  2737. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2738. }
  2739. else if(strcmp(status,"DownloadFailed")==0)
  2740. {
  2741. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  2742. }
  2743. else if(strcmp(status,"Downloading")==0)
  2744. {
  2745. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2746. }
  2747. else if(strcmp(status,"Idle")==0)
  2748. {
  2749. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2750. }
  2751. else if(strcmp(status,"InstallationFailed")==0)
  2752. {
  2753. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2754. }
  2755. else if(strcmp(status,"Installing")==0)
  2756. {
  2757. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2758. }
  2759. else if(strcmp(status,"Installed")==0)
  2760. {
  2761. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2762. }
  2763. return result;
  2764. }
  2765. int sendHeartbeatRequest(int gun_index)
  2766. {
  2767. mtrace();
  2768. int result = FAIL;
  2769. char message[80]={0};
  2770. char guid[37]={0};
  2771. char tempdata[65]={0};
  2772. random_uuid(guid);
  2773. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2774. , MESSAGE_TYPE_CALL
  2775. , guid );
  2776. LWS_Send(message);
  2777. sprintf(tempdata, "Heartbeat,%d", 0);
  2778. 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*/)
  2779. {
  2780. result = PASS;
  2781. }
  2782. return result;
  2783. }
  2784. int sendStartTransactionRequest(int gun_index)
  2785. {
  2786. mtrace();
  2787. int result = FAIL;
  2788. char message[250]={0};
  2789. char guid[37]={0};
  2790. struct timeval tmnow;
  2791. struct tm *tm;
  2792. char buf[28];//, usec_buf[6];
  2793. char tempdata[65]={0};
  2794. int tempIndex = 0;
  2795. DEBUG_INFO("sendStartTransactionRequest...\n");
  2796. gettimeofday(&tmnow, NULL);
  2797. time_t t;
  2798. t = time(NULL);
  2799. /*UTC time and date*/
  2800. tm = gmtime(&t);
  2801. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2802. #if 0 // remove temporally
  2803. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2804. strcat(buf,".");
  2805. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2806. strcat(buf,usec_buf);
  2807. #endif
  2808. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2809. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2810. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2811. // clear StartTransaction Response
  2812. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2813. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2814. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2815. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2816. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2817. if(gunType[gun_index] == 'J')
  2818. {
  2819. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2820. {
  2821. tempIndex = ((gun_index==2) ? 1: 0);
  2822. }
  2823. else
  2824. {
  2825. tempIndex = gun_index;
  2826. }
  2827. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2828. {
  2829. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2830. {
  2831. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  2832. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2833. }
  2834. }
  2835. }
  2836. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2837. {
  2838. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2839. {
  2840. tempIndex = ((gun_index==2) ? 1: 0);
  2841. }
  2842. else
  2843. {
  2844. tempIndex = gun_index;
  2845. }
  2846. for (int index = 0; index < CCS_QUANTITY; index++)
  2847. {
  2848. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2849. {
  2850. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  2851. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  2852. }
  2853. }
  2854. }
  2855. else if(gunType[gun_index] == 'G')
  2856. {
  2857. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2858. {
  2859. tempIndex = ((gun_index==2) ? 1: 0);
  2860. }
  2861. else
  2862. {
  2863. tempIndex = gun_index;
  2864. }
  2865. for (int index = 0; index < GB_QUANTITY; index++)
  2866. {
  2867. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2868. {
  2869. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  2870. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  2871. }
  2872. }
  2873. }
  2874. else
  2875. {
  2876. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2877. {
  2878. tempIndex = 2;
  2879. }
  2880. else
  2881. {
  2882. tempIndex = gun_index;
  2883. }
  2884. for (int index = 0; index < AC_QUANTITY; index++)
  2885. {
  2886. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2887. {
  2888. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  2889. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  2890. }
  2891. }
  2892. }
  2893. random_uuid(guid);
  2894. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  2895. {
  2896. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  2897. , gun_index +1
  2898. , MESSAGE_TYPE_CALL
  2899. , guid
  2900. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2901. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2902. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2903. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2904. }
  2905. else
  2906. {
  2907. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  2908. , gun_index +1
  2909. , MESSAGE_TYPE_CALL
  2910. , guid
  2911. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2912. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2913. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2914. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  2915. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2916. }
  2917. #if 1
  2918. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  2919. 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*/)
  2920. {
  2921. result = PASS;
  2922. }
  2923. #endif
  2924. strcpy(queuedata, message);
  2925. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2926. /*
  2927. if(GetTransactionQueueNum() == 1)
  2928. {
  2929. LWS_Send(message + 2);
  2930. }*/
  2931. return result;
  2932. }
  2933. int sendStatusNotificationRequest(int gun_index)
  2934. {
  2935. mtrace();
  2936. int result = FAIL;
  2937. char message[600]={0};
  2938. char guid[37];
  2939. int currentStatus = 0;
  2940. struct timeval tmnow;
  2941. struct tm *tm;
  2942. char buf[28];//, usec_buf[6];
  2943. char tempdata[65]={0};
  2944. int tempIndex = 0;
  2945. gettimeofday(&tmnow, NULL);
  2946. time_t t;
  2947. t = time(NULL);
  2948. /*UTC time and date*/
  2949. tm = gmtime(&t);
  2950. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2951. #if 0 // remove temporally
  2952. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2953. strcat(buf,".");
  2954. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2955. strcat(buf,usec_buf);
  2956. #endif
  2957. printf("%s",buf);
  2958. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  2959. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  2960. // it's option
  2961. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  2962. /*
  2963. enum _SYSTEM_STATUS
  2964. {
  2965. S_BOOTING = 0,
  2966. S_IDLE, = 1
  2967. S_AUTHORIZING, =2
  2968. S_REASSIGN_CHECK, =3
  2969. S_REASSIGN, =4
  2970. S_PRECHARGE, =5
  2971. S_PREPARING_FOR_EV, =6
  2972. S_PREPARING_FOR_EVSE, =7
  2973. S_CHARGING, =8
  2974. S_TERMINATING, =9
  2975. S_COMPLETE, =10
  2976. S_ALARM, =11
  2977. S_FAULT =12
  2978. }
  2979. */
  2980. //check Transaction active
  2981. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2982. if(gunType[gun_index] == 'J')
  2983. {
  2984. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2985. {
  2986. tempIndex = ((gun_index==2) ? 1: 0);
  2987. }
  2988. else
  2989. {
  2990. tempIndex = gun_index;
  2991. }
  2992. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2993. {
  2994. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  2995. {
  2996. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  2997. {
  2998. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  2999. {
  3000. currentStatus = 1; //OCPP Status: Preparing
  3001. }
  3002. else
  3003. {
  3004. currentStatus = 0; //OCPP Status: Available
  3005. }
  3006. }
  3007. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3008. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3009. ) //S_PRECHARGE
  3010. {
  3011. currentStatus = 1; //OCPP Status: Preparing
  3012. }
  3013. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3014. {
  3015. currentStatus = 2; //OCPP Status: Charging
  3016. }
  3017. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3018. {
  3019. currentStatus = 5; //OCPP Status: Finishing
  3020. }
  3021. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3022. {
  3023. currentStatus = 4; //OCPP Status: SuspendedEV
  3024. }
  3025. 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
  3026. {
  3027. currentStatus = 7; //OCPP Status: Unavailable
  3028. }
  3029. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3030. {
  3031. currentStatus = 8; //OCPP Status: Faulted
  3032. }
  3033. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3034. {
  3035. currentStatus = 6; //OCPP Status: Reserved
  3036. }
  3037. } //end of the same index
  3038. }//end of for CHAdeMO_QUANTITY
  3039. }
  3040. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3041. {
  3042. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3043. {
  3044. tempIndex = ((gun_index==2) ? 1: 0);
  3045. }
  3046. else
  3047. {
  3048. tempIndex = gun_index;
  3049. }
  3050. for (int index = 0; index < CCS_QUANTITY; index++)
  3051. {
  3052. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3053. {
  3054. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3055. {
  3056. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3057. {
  3058. currentStatus = 1; //OCPP Status: Preparing
  3059. }
  3060. else
  3061. {
  3062. currentStatus = 0; //OCPP Status: Available
  3063. }
  3064. }
  3065. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3066. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3067. ) //S_PRECHARGE
  3068. {
  3069. currentStatus = 1; //OCPP Status: Preparing
  3070. }
  3071. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3072. {
  3073. currentStatus = 2; //OCPP Status: Charging
  3074. }
  3075. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3076. {
  3077. currentStatus = 5; //OCPP Status: Finishing
  3078. }
  3079. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3080. {
  3081. currentStatus = 4; //OCPP Status: SuspendedEV
  3082. }
  3083. 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
  3084. {
  3085. currentStatus = 7; //OCPP Status : Unavailable
  3086. }
  3087. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3088. {
  3089. currentStatus = 8; //OCPP Status: Faulted
  3090. }
  3091. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3092. {
  3093. currentStatus = 6; //OCPP Status: Reserved
  3094. }
  3095. } //end of the same index
  3096. } // end of for CCS_QUANTITY
  3097. }
  3098. else if(gunType[gun_index] == 'G')
  3099. {
  3100. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3101. {
  3102. tempIndex = ((gun_index==2) ? 1: 0);
  3103. }
  3104. else
  3105. {
  3106. tempIndex = gun_index;
  3107. }
  3108. for (int index = 0; index < GB_QUANTITY; index++)
  3109. {
  3110. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3111. {
  3112. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3113. {
  3114. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3115. {
  3116. currentStatus = 1; //OCPP Status: Preparing
  3117. }
  3118. else
  3119. {
  3120. currentStatus = 0; //OCPP Status: Available
  3121. }
  3122. }
  3123. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3124. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3125. ) //S_PRECHARGE
  3126. {
  3127. currentStatus = 1; //OCPP Status: Preparing
  3128. }
  3129. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3130. {
  3131. currentStatus = 2; //OCPP Status: Charging
  3132. }
  3133. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3134. {
  3135. currentStatus = 5; //OCPP Status: Finishing
  3136. }
  3137. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3138. {
  3139. currentStatus = 4; //OCPP Status: SuspendedEV
  3140. }
  3141. 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
  3142. {
  3143. currentStatus = 7; //OCPP Status: Unavailable
  3144. }
  3145. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3146. {
  3147. currentStatus = 8; //OCPP Status: Faulted
  3148. }
  3149. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3150. {
  3151. currentStatus = 6; //OCPP Status: Reserved
  3152. }
  3153. } //end of the same index
  3154. } // end of for GB_QUANTITY
  3155. }
  3156. else
  3157. {
  3158. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3159. {
  3160. tempIndex = 2;
  3161. }
  3162. else
  3163. {
  3164. tempIndex = gun_index;
  3165. }
  3166. for (int index = 0; index < AC_QUANTITY; index++)
  3167. {
  3168. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3169. {
  3170. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3171. {
  3172. 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))
  3173. {
  3174. currentStatus = 1; //OCPP Status: Preparing
  3175. }
  3176. else
  3177. {
  3178. currentStatus = 0; //OCPP Status: Available
  3179. }
  3180. }
  3181. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3182. {
  3183. currentStatus = 1; //OCPP Status: Preparing
  3184. }
  3185. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3186. {
  3187. currentStatus = 2; //OCPP Status: Charging
  3188. }
  3189. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3190. {
  3191. currentStatus = 5; //OCPP Status: Finishing
  3192. }
  3193. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3194. {
  3195. currentStatus = 4; //OCPP Status: SuspendedEV
  3196. }
  3197. 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
  3198. {
  3199. currentStatus = 7; //OCPP Status: Unavailable
  3200. }
  3201. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3202. {
  3203. currentStatus = 8; //OCPP Status: Faulted
  3204. }
  3205. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3206. {
  3207. currentStatus = 6; //OCPP Status: Reserved
  3208. }
  3209. }//end of the same index
  3210. }//end of for AC_QUANTITY
  3211. }
  3212. //it's option
  3213. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3214. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3215. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3216. random_uuid(guid);
  3217. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3218. , MESSAGE_TYPE_CALL
  3219. , guid
  3220. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3221. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3222. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3223. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3224. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3225. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3226. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3227. if((server_sign == TRUE))
  3228. {
  3229. LWS_Send(message);
  3230. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3231. 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*/)
  3232. {
  3233. //DEBUG_ERROR("statusNotification mapitem pass");
  3234. result = PASS;
  3235. }
  3236. }
  3237. else
  3238. {
  3239. result = PASS;
  3240. }
  3241. return result;
  3242. }
  3243. int sendStopTransactionRequest(int gun_index)
  3244. {
  3245. mtrace();
  3246. int result = FAIL;
  3247. //char message[1500]={0};
  3248. char guid[37]={0};
  3249. char tempdata[65]={0};
  3250. int tempIndex = 0;
  3251. char TempStopTransaction[256];
  3252. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3253. //int idx_sample=0;
  3254. DEBUG_ERROR("sendStopTransactionRequest \n");
  3255. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3256. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3257. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3258. if(gunType[gun_index] == 'J')
  3259. {
  3260. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3261. {
  3262. tempIndex = ((gun_index==2) ? 1: 0);
  3263. }
  3264. else
  3265. {
  3266. tempIndex = gun_index;
  3267. }
  3268. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3269. {
  3270. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3271. {
  3272. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3273. }
  3274. }// END OF CHAdeMO_QUANTITY
  3275. }
  3276. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3277. {
  3278. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3279. {
  3280. tempIndex = ((gun_index==2) ? 1: 0);
  3281. }
  3282. else
  3283. {
  3284. tempIndex = gun_index;
  3285. }
  3286. for (int index = 0; index < CCS_QUANTITY; index++)
  3287. {
  3288. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3289. {
  3290. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3291. }
  3292. }// END OF CCS_QUANTITY
  3293. }
  3294. else if(gunType[gun_index] == 'G')
  3295. {
  3296. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3297. {
  3298. tempIndex = ((gun_index==2) ? 1: 0);
  3299. }
  3300. else
  3301. {
  3302. tempIndex = gun_index;
  3303. }
  3304. for (int index = 0; index < GB_QUANTITY; index++)
  3305. {
  3306. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3307. {
  3308. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3309. }
  3310. }// END OF GB_QUANTITY
  3311. }
  3312. else
  3313. {
  3314. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3315. {
  3316. tempIndex = 2;
  3317. }
  3318. else
  3319. {
  3320. tempIndex = gun_index;
  3321. }
  3322. for (int index = 0; index < AC_QUANTITY; index++)
  3323. {
  3324. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3325. {
  3326. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3327. }
  3328. }// END OF AC_QUANTITY
  3329. }
  3330. //====================================== Stop Transaction Time =====================================================
  3331. struct timeval tmnow;
  3332. struct tm *tm;
  3333. char buf[28];//, usec_buf[6];
  3334. gettimeofday(&tmnow, NULL);
  3335. time_t t;
  3336. t = time(NULL);
  3337. /*UTC time and date*/
  3338. tm = gmtime(&t);
  3339. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3340. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3341. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3342. random_uuid(guid);
  3343. /***********************************transactionData******************************************************/
  3344. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3345. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3346. //=================================
  3347. // Transaction_Begin
  3348. //=================================
  3349. //============================================ Energy.Active.Import.Interval ================================
  3350. //idx_sample=0;
  3351. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  3352. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3353. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3354. 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*/]);
  3355. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3356. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3357. {
  3358. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3359. }
  3360. else
  3361. {
  3362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3363. }
  3364. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3365. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3366. //=================================
  3367. // Transaction_End
  3368. //=================================
  3369. // ================================= Current.Import L1 ===============================================
  3370. //idx_sample=1;
  3371. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3372. if(gunType[gun_index] == 'J')
  3373. {
  3374. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3375. {
  3376. tempIndex = ((gun_index==2) ? 1: 0);
  3377. }
  3378. else
  3379. {
  3380. tempIndex = gun_index;
  3381. }
  3382. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3383. {
  3384. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3385. {
  3386. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3387. }
  3388. }// End of for CHAdeMO_QUANTITY
  3389. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3390. }
  3391. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3392. {
  3393. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3394. {
  3395. tempIndex = ((gun_index==2) ? 1: 0);
  3396. }
  3397. else
  3398. {
  3399. tempIndex = gun_index;
  3400. }
  3401. for (int index = 0; index < CCS_QUANTITY; index++)
  3402. {
  3403. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3404. {
  3405. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3406. }
  3407. }// End of for CCS_QUANTITY
  3408. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3409. }
  3410. else if(gunType[gun_index] == 'G')
  3411. {
  3412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3413. {
  3414. tempIndex = ((gun_index==2) ? 1: 0);
  3415. }
  3416. else
  3417. {
  3418. tempIndex = gun_index;
  3419. }
  3420. for (int index = 0; index < GB_QUANTITY; index++)
  3421. {
  3422. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3423. {
  3424. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3425. }
  3426. }// End of for GB_QUANTITY
  3427. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3428. }
  3429. else
  3430. {
  3431. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3432. {
  3433. tempIndex = 2;
  3434. }
  3435. else
  3436. {
  3437. tempIndex = gun_index;
  3438. }
  3439. for (int index = 0; index < AC_QUANTITY; index++)
  3440. {
  3441. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3442. {
  3443. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3444. }
  3445. }// End of for AC_QUANTITY
  3446. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3447. }
  3448. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3449. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3450. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3451. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3452. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3453. // ================================= Energy.Active.Import.Interval ==============================================
  3454. //idx_sample=2;
  3455. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3456. if(gunType[gun_index] == 'J')
  3457. {
  3458. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3459. {
  3460. tempIndex = ((gun_index==2) ? 1: 0);
  3461. }
  3462. else
  3463. {
  3464. tempIndex = gun_index;
  3465. }
  3466. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3467. {
  3468. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3469. {
  3470. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3471. }
  3472. }// END OF CHAdeMO_QUANTITY
  3473. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3474. }
  3475. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3476. {
  3477. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3478. {
  3479. tempIndex = ((gun_index==2) ? 1: 0);
  3480. }
  3481. else
  3482. {
  3483. tempIndex = gun_index;
  3484. }
  3485. for (int index = 0; index < CCS_QUANTITY; index++)
  3486. {
  3487. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3488. {
  3489. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3490. }
  3491. }// END OF CCS_QUANTITY
  3492. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3493. }
  3494. else if(gunType[gun_index] == 'G')
  3495. {
  3496. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3497. {
  3498. tempIndex = ((gun_index==2) ? 1: 0);
  3499. }
  3500. else
  3501. {
  3502. tempIndex = gun_index;
  3503. }
  3504. for (int index = 0; index < GB_QUANTITY; index++)
  3505. {
  3506. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3507. {
  3508. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3509. }
  3510. }// END OF GB_QUANTITY
  3511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3512. }
  3513. else
  3514. {
  3515. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3516. {
  3517. tempIndex = 2;
  3518. }
  3519. else
  3520. {
  3521. tempIndex = gun_index;
  3522. }
  3523. for (int index = 0; index < AC_QUANTITY; index++)
  3524. {
  3525. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3526. {
  3527. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3528. }
  3529. }// END OF AC_QUANTITY
  3530. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3531. }
  3532. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3533. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3534. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3535. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3536. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3537. //=================================== Power.Active.Import ==================================================
  3538. //idx_sample=3;
  3539. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3540. if(gunType[gun_index] == 'J')
  3541. {
  3542. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3543. {
  3544. tempIndex = ((gun_index==2) ? 1: 0);
  3545. }
  3546. else
  3547. {
  3548. tempIndex = gun_index;
  3549. }
  3550. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3551. {
  3552. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3553. {
  3554. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3555. }
  3556. } // End for CHAdeMO_QUANTITY
  3557. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3558. }
  3559. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3560. {
  3561. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3562. {
  3563. tempIndex = ((gun_index==2) ? 1: 0);
  3564. }
  3565. else
  3566. {
  3567. tempIndex = gun_index;
  3568. }
  3569. for (int index = 0; index < CCS_QUANTITY; index++)
  3570. {
  3571. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3572. {
  3573. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3574. }
  3575. } // END for CCS_QUANTITY
  3576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3577. }
  3578. else if(gunType[gun_index] == 'G')
  3579. {
  3580. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3581. {
  3582. tempIndex = ((gun_index==2) ? 1: 0);
  3583. }
  3584. else
  3585. {
  3586. tempIndex = gun_index;
  3587. }
  3588. for (int index = 0; index < GB_QUANTITY; index++)
  3589. {
  3590. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3591. {
  3592. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3593. }
  3594. }// END for GB_QUANTITY
  3595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3596. }
  3597. else
  3598. {
  3599. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3600. {
  3601. tempIndex = 2;
  3602. }
  3603. else
  3604. {
  3605. tempIndex = gun_index;
  3606. }
  3607. for (int index = 0; index < AC_QUANTITY; index++)
  3608. {
  3609. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3610. {
  3611. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3612. }
  3613. } // END for AC_QUANTITY
  3614. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3615. }
  3616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3617. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3618. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3619. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3620. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3621. //============================ Voltage L1 ====================================
  3622. //idx_sample=4;
  3623. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3624. if(gunType[gun_index] == 'J')
  3625. {
  3626. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3627. {
  3628. tempIndex = ((gun_index==2) ? 1: 0);
  3629. }
  3630. else
  3631. {
  3632. tempIndex = gun_index;
  3633. }
  3634. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3635. {
  3636. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3637. {
  3638. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3639. }
  3640. } // END OF FOR CHAdeMO_QUANTITY
  3641. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3642. }
  3643. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3644. {
  3645. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3646. {
  3647. tempIndex = ((gun_index==2) ? 1: 0);
  3648. }
  3649. else
  3650. {
  3651. tempIndex = gun_index;
  3652. }
  3653. for (int index = 0; index < CCS_QUANTITY; index++)
  3654. {
  3655. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3656. {
  3657. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3658. }
  3659. } // END OF FOR CCS_QUANTITY
  3660. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3661. }
  3662. else if(gunType[gun_index] == 'G')
  3663. {
  3664. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3665. {
  3666. tempIndex = ((gun_index==2) ? 1: 0);
  3667. }
  3668. else
  3669. {
  3670. tempIndex = gun_index;
  3671. }
  3672. for (int index = 0; index < GB_QUANTITY; index++)
  3673. {
  3674. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3675. {
  3676. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3677. }
  3678. } // END OF FOR GB_QUANTITY
  3679. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3680. }
  3681. else
  3682. {
  3683. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3684. {
  3685. tempIndex = 2;
  3686. }
  3687. else
  3688. {
  3689. tempIndex = gun_index;
  3690. }
  3691. for (int index = 0; index < AC_QUANTITY; index++)
  3692. {
  3693. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3694. {
  3695. 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
  3696. }
  3697. } // END OF FOR AC_QUANTITY
  3698. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3699. }
  3700. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3701. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3702. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3703. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3704. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3705. //====================== SoC ================================
  3706. //idx_sample=5;
  3707. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3708. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3709. {
  3710. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3711. {
  3712. tempIndex = ((gun_index==2) ? 1: 0);
  3713. }
  3714. else
  3715. {
  3716. tempIndex = gun_index;
  3717. }
  3718. if(gunType[gun_index] == 'J')
  3719. {
  3720. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3721. {
  3722. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3723. {
  3724. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3725. }
  3726. }
  3727. }
  3728. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3729. {
  3730. for (int index = 0; index < CCS_QUANTITY; index++)
  3731. {
  3732. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3733. {
  3734. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3735. }
  3736. }
  3737. }
  3738. else if(gunType[gun_index] == 'G')
  3739. {
  3740. for (int index = 0; index < GB_QUANTITY; index++)
  3741. {
  3742. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3743. {
  3744. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  3745. }
  3746. }
  3747. }
  3748. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3749. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  3750. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  3751. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  3752. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  3753. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  3754. } // END FOR DC CASE
  3755. // ================================= Current.Import L2 ===============================================
  3756. //idx_sample=6;
  3757. // AC 3 phse L2 current
  3758. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3759. {
  3760. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3761. {
  3762. tempIndex = 2;
  3763. }
  3764. else
  3765. {
  3766. tempIndex = gun_index;
  3767. }
  3768. for (int index = 0; index < AC_QUANTITY; index++)
  3769. {
  3770. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3771. {
  3772. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  3773. }
  3774. }// End of for AC_QUANTITY
  3775. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  3776. }
  3777. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3778. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  3779. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  3780. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  3781. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3782. // ================================= Current.Import L3 ===============================================
  3783. //idx_sample=7;
  3784. // AC 3 phse L3 current
  3785. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3786. {
  3787. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3788. {
  3789. tempIndex = 2;
  3790. }
  3791. else
  3792. {
  3793. tempIndex = gun_index;
  3794. }
  3795. for (int index = 0; index < AC_QUANTITY; index++)
  3796. {
  3797. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3798. {
  3799. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  3800. }
  3801. }// End of for AC_QUANTITY
  3802. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  3803. }
  3804. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3805. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  3806. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  3807. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  3808. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3809. //============================ Voltage L2 ====================================
  3810. //idx_sample=8;
  3811. // AC 3 phse L2 voltage
  3812. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3813. {
  3814. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3815. {
  3816. tempIndex = 2;
  3817. }
  3818. else
  3819. {
  3820. tempIndex = gun_index;
  3821. }
  3822. for (int index = 0; index < AC_QUANTITY; index++)
  3823. {
  3824. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3825. {
  3826. 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
  3827. }
  3828. } // END OF FOR AC_QUANTITY
  3829. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  3830. }
  3831. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3832. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  3833. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  3834. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  3835. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3836. //============================ Voltage L3 ====================================
  3837. //idx_sample=8;
  3838. // AC 3 phse L3 voltage
  3839. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3840. {
  3841. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3842. {
  3843. tempIndex = 2;
  3844. }
  3845. else
  3846. {
  3847. tempIndex = gun_index;
  3848. }
  3849. for (int index = 0; index < AC_QUANTITY; index++)
  3850. {
  3851. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3852. {
  3853. 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
  3854. }
  3855. } // END OF FOR AC_QUANTITY
  3856. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  3857. }
  3858. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3859. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  3860. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  3861. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  3862. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3863. //================================================ Message create ====================================================
  3864. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3865. {
  3866. 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\"}]}]}]"
  3867. ,gun_index+1
  3868. ,MESSAGE_TYPE_CALL
  3869. ,guid
  3870. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3871. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3872. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3874. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3875. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3890. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3894. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3895. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3896. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3897. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3898. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3899. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3900. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3901. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3902. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3903. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3904. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3905. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3906. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3907. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3908. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3909. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3910. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3911. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  3912. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  3913. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  3914. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  3915. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  3916. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  3917. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  3918. );
  3919. }
  3920. else
  3921. {
  3922. if((ShmSysConfigAndInfo->SysConfig.ModelName[2]!='Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2]!='W'))
  3923. {
  3924. 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\"}]}]}]"
  3925. ,gun_index+1
  3926. ,MESSAGE_TYPE_CALL
  3927. ,guid
  3928. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3929. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3930. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3931. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3932. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3933. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3934. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3935. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3936. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3937. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3938. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3939. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3940. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3941. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3942. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3943. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3944. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3945. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3946. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3947. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3948. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3949. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3950. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3951. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3952. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3953. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3954. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3955. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3956. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3957. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3958. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3959. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3960. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3961. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3962. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3963. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3964. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3965. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3966. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3967. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3968. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3969. );
  3970. }
  3971. else
  3972. {
  3973. 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\"}]}]}]"
  3974. ,gun_index+1
  3975. ,MESSAGE_TYPE_CALL
  3976. ,guid
  3977. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3978. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3979. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3980. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3981. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3982. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3983. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3984. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3985. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3986. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3987. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3988. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3989. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3990. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3991. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3992. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3993. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3994. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3995. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3996. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3997. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3998. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3999. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  4000. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  4001. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  4002. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  4003. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  4004. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  4005. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  4006. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  4007. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  4008. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  4009. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  4010. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  4011. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  4012. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  4013. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  4014. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  4015. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  4016. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  4017. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  4018. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  4019. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  4020. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  4021. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  4022. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  4023. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  4024. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  4025. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  4026. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  4027. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  4028. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  4029. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  4030. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  4031. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  4032. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  4033. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  4034. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  4035. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  4036. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  4037. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  4038. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  4039. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  4040. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  4041. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  4042. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  4043. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  4044. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  4045. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  4046. );
  4047. }
  4048. }
  4049. #if 1 // for TempStopTransaction
  4050. //Delete TempStopTransaction
  4051. if((access(TempStopTransaction,F_OK))!=-1)
  4052. {
  4053. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4054. }
  4055. #endif
  4056. #if 1
  4057. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4058. if(hashmap_operation(0, guid, tempdata) == 1)
  4059. {
  4060. result = PASS;
  4061. DEBUG_INFO("StopTransaction mapitem pass\n");
  4062. }
  4063. #endif
  4064. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4065. /*
  4066. if(GetTransactionQueueNum() == 1)
  4067. {
  4068. LWS_Send(queuedata+2);
  4069. }*/
  4070. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4071. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4072. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4073. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4074. {
  4075. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4076. }
  4077. //for test
  4078. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4079. return result;
  4080. }
  4081. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4082. {
  4083. mtrace();
  4084. int result = FAIL;
  4085. char guid[37]={0};
  4086. char tempdata[65]={0};
  4087. int tempIndex = 0;
  4088. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4089. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4090. //set value
  4091. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4092. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) ? ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId : 0);
  4093. random_uuid(guid);
  4094. //UTC Date time
  4095. struct timeval tmnow;
  4096. struct tm *tm;
  4097. char buf[28];//, usec_buf[6];
  4098. gettimeofday(&tmnow, NULL);
  4099. time_t t;
  4100. t = time(NULL);
  4101. /*UTC time and date*/
  4102. tm = gmtime(&t);
  4103. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4104. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4105. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4106. //idx_sample=0;
  4107. //********************************(1)Current.Import L1************************************************/
  4108. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4109. if(gunType[gun_index] == 'J')
  4110. {
  4111. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4112. {
  4113. tempIndex = ((gun_index==2) ? 1: 0);
  4114. }
  4115. else
  4116. {
  4117. tempIndex = gun_index;
  4118. }
  4119. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4120. {
  4121. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4122. {
  4123. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4124. }
  4125. }
  4126. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4127. }
  4128. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4129. {
  4130. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4131. {
  4132. tempIndex = ((gun_index==2) ? 1: 0);
  4133. }
  4134. else
  4135. {
  4136. tempIndex = gun_index;
  4137. }
  4138. for (int index = 0; index < CCS_QUANTITY; index++)
  4139. {
  4140. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4141. {
  4142. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4143. }
  4144. }
  4145. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4146. }
  4147. else if(gunType[gun_index] == 'G')
  4148. {
  4149. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4150. {
  4151. tempIndex = ((gun_index==2) ? 1: 0);
  4152. }
  4153. else
  4154. {
  4155. tempIndex = gun_index;
  4156. }
  4157. for (int index = 0; index < GB_QUANTITY; index++)
  4158. {
  4159. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4160. {
  4161. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4162. }
  4163. }
  4164. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4165. }
  4166. else
  4167. {
  4168. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4169. {
  4170. tempIndex = 2;
  4171. }
  4172. else
  4173. {
  4174. tempIndex = gun_index;
  4175. }
  4176. for (int index = 0; index < AC_QUANTITY; index++)
  4177. {
  4178. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4179. {
  4180. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4181. }
  4182. }
  4183. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4184. }
  4185. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4186. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4187. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4188. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4189. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4190. //idx_sample=1;
  4191. //********************************(2)Energy.Active.Import.Register ************************************************/
  4192. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4193. if(gunType[gun_index] == 'J')
  4194. {
  4195. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4196. {
  4197. tempIndex = ((gun_index==2) ? 1: 0);
  4198. }
  4199. else
  4200. {
  4201. tempIndex = gun_index;
  4202. }
  4203. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4204. {
  4205. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4206. {
  4207. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4208. }
  4209. }
  4210. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4211. }
  4212. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4213. {
  4214. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4215. {
  4216. tempIndex = ((gun_index==2) ? 1: 0);
  4217. }
  4218. else
  4219. {
  4220. tempIndex = gun_index;
  4221. }
  4222. for (int index = 0; index < CCS_QUANTITY; index++)
  4223. {
  4224. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4225. {
  4226. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4227. }
  4228. }
  4229. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4230. }
  4231. else if(gunType[gun_index] == 'G')
  4232. {
  4233. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4234. {
  4235. tempIndex = ((gun_index==2) ? 1: 0);
  4236. }
  4237. else
  4238. {
  4239. tempIndex = gun_index;
  4240. }
  4241. for (int index = 0; index < GB_QUANTITY; index++)
  4242. {
  4243. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4244. {
  4245. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4246. }
  4247. }
  4248. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4249. }
  4250. else
  4251. {
  4252. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4253. {
  4254. tempIndex = 2;
  4255. }
  4256. else
  4257. {
  4258. tempIndex = gun_index;
  4259. }
  4260. for (int index = 0; index < AC_QUANTITY; index++)
  4261. {
  4262. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4263. {
  4264. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4265. }
  4266. }
  4267. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4268. }
  4269. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4270. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4271. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4272. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4273. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4274. //idx_sample=2;
  4275. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4276. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4277. if(gunType[gun_index] == 'J')
  4278. {
  4279. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4280. {
  4281. tempIndex = ((gun_index==2) ? 1: 0);
  4282. }
  4283. else
  4284. {
  4285. tempIndex = gun_index;
  4286. }
  4287. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4288. {
  4289. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4290. {
  4291. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4292. }
  4293. } // END OF FOR CHAdeMO_QUANTITY
  4294. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4295. }
  4296. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4297. {
  4298. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4299. {
  4300. tempIndex = ((gun_index==2) ? 1: 0);
  4301. }
  4302. else
  4303. {
  4304. tempIndex = gun_index;
  4305. }
  4306. for (int index = 0; index < CCS_QUANTITY; index++)
  4307. {
  4308. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4309. {
  4310. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4311. }
  4312. } // END OF CCS_QUANTITY
  4313. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4314. }
  4315. else if(gunType[gun_index] == 'G')
  4316. {
  4317. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4318. {
  4319. tempIndex = ((gun_index==2) ? 1: 0);
  4320. }
  4321. else
  4322. {
  4323. tempIndex = gun_index;
  4324. }
  4325. for (int index = 0; index < GB_QUANTITY; index++)
  4326. {
  4327. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4328. {
  4329. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4330. }
  4331. } // END OF GB_QUANTITY
  4332. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4333. }
  4334. else
  4335. {
  4336. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4337. {
  4338. tempIndex = 2;
  4339. }
  4340. else
  4341. {
  4342. tempIndex = gun_index;
  4343. }
  4344. for (int index = 0; index < AC_QUANTITY; index++)
  4345. {
  4346. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4347. {
  4348. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4349. }
  4350. }
  4351. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4352. }
  4353. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4354. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4355. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4356. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4357. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4358. //idx_sample=3;
  4359. //********************************(4)Power.Active.Import************************************************/
  4360. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4361. if(gunType[gun_index] == 'J')
  4362. {
  4363. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4364. {
  4365. tempIndex = ((gun_index==2) ? 1: 0);
  4366. }
  4367. else
  4368. {
  4369. tempIndex = gun_index;
  4370. }
  4371. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4372. {
  4373. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4374. {
  4375. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4376. }
  4377. } // END OF FOR
  4378. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4379. }
  4380. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4381. {
  4382. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4383. {
  4384. tempIndex = ((gun_index==2) ? 1: 0);
  4385. }
  4386. else
  4387. {
  4388. tempIndex = gun_index;
  4389. }
  4390. for (int index = 0; index < CCS_QUANTITY; index++)
  4391. {
  4392. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4393. {
  4394. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4395. }
  4396. }
  4397. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4398. }
  4399. else if(gunType[gun_index] == 'G')
  4400. {
  4401. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4402. {
  4403. tempIndex = ((gun_index==2) ? 1: 0);
  4404. }
  4405. else
  4406. {
  4407. tempIndex = gun_index;
  4408. }
  4409. for (int index = 0; index < GB_QUANTITY; index++)
  4410. {
  4411. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4412. {
  4413. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4414. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4415. }
  4416. }
  4417. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4418. }
  4419. else
  4420. {
  4421. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4422. {
  4423. tempIndex = 2;
  4424. }
  4425. else
  4426. {
  4427. tempIndex = gun_index;
  4428. }
  4429. for (int index = 0; index < AC_QUANTITY; index++)
  4430. {
  4431. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4432. {
  4433. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4434. }
  4435. }
  4436. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4437. }
  4438. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4439. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4440. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4441. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4442. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4443. //idx_sample=4;
  4444. //***********************************************(5)VOLTAGE L1******************************************************/
  4445. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4446. if(gunType[gun_index] == 'J')
  4447. {
  4448. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4449. {
  4450. tempIndex = ((gun_index==2) ? 1: 0);
  4451. }
  4452. else
  4453. {
  4454. tempIndex = gun_index;
  4455. }
  4456. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4457. {
  4458. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4459. {
  4460. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4461. }
  4462. }
  4463. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4464. }
  4465. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4466. {
  4467. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4468. {
  4469. tempIndex = ((gun_index==2) ? 1: 0);
  4470. }
  4471. else
  4472. {
  4473. tempIndex = gun_index;
  4474. }
  4475. for (int index = 0; index < CCS_QUANTITY; index++)
  4476. {
  4477. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4478. {
  4479. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4480. }
  4481. }
  4482. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4483. }
  4484. else if(gunType[gun_index] == 'G')
  4485. {
  4486. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4487. {
  4488. tempIndex = ((gun_index==2) ? 1: 0);
  4489. }
  4490. else
  4491. {
  4492. tempIndex = gun_index;
  4493. }
  4494. for (int index = 0; index < GB_QUANTITY; index++)
  4495. {
  4496. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4497. {
  4498. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4499. }
  4500. }
  4501. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4502. }
  4503. else
  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[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4518. }
  4519. }
  4520. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4521. }
  4522. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4523. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4524. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4525. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4526. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4527. //***********************************************(6)SOC******************************************************/
  4528. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4529. {
  4530. //idx_sample=5;
  4531. //sampledValue = NULL;
  4532. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4533. {
  4534. tempIndex = ((gun_index==2) ? 1: 0);
  4535. }
  4536. else
  4537. {
  4538. tempIndex = gun_index;
  4539. }
  4540. if(gunType[gun_index] == 'J')
  4541. {
  4542. //tempIndex = ((gun_index==2) ? 1: 0);
  4543. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4544. {
  4545. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4546. {
  4547. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4548. }
  4549. }
  4550. }
  4551. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4552. {
  4553. //tempIndex = ((gun_index==2) ? 1: 0);
  4554. for (int index = 0; index < CCS_QUANTITY; index++)
  4555. {
  4556. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4557. {
  4558. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4559. }
  4560. }
  4561. }
  4562. else if(gunType[gun_index] == 'G')
  4563. {
  4564. //tempIndex = ((gun_index==2) ? 1: 0);
  4565. for (int index = 0; index < GB_QUANTITY; index++)
  4566. {
  4567. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4568. {
  4569. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4570. }
  4571. }
  4572. }
  4573. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4574. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4575. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4576. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4577. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_Outlet]);
  4578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4579. }
  4580. //********************************(7)Current.Import L2************************************************/
  4581. // Only for AC 3 phase
  4582. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4583. {
  4584. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4585. {
  4586. tempIndex = 2;
  4587. }
  4588. else
  4589. {
  4590. tempIndex = gun_index;
  4591. }
  4592. for (int index = 0; index < AC_QUANTITY; index++)
  4593. {
  4594. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4595. {
  4596. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  4597. }
  4598. }
  4599. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  4600. }
  4601. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  4602. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  4603. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  4604. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  4605. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4606. //********************************(8)Current.Import L3************************************************/
  4607. // Only for AC 3 phase
  4608. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4609. {
  4610. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4611. {
  4612. tempIndex = 2;
  4613. }
  4614. else
  4615. {
  4616. tempIndex = gun_index;
  4617. }
  4618. for (int index = 0; index < AC_QUANTITY; index++)
  4619. {
  4620. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4621. {
  4622. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  4623. }
  4624. }
  4625. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  4626. }
  4627. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  4628. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  4629. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  4630. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  4631. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4632. //***********************************************(9)VOLTAGE L2******************************************************/
  4633. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4634. {
  4635. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4636. {
  4637. tempIndex = 2;
  4638. }
  4639. else
  4640. {
  4641. tempIndex = gun_index;
  4642. }
  4643. for (int index = 0; index < AC_QUANTITY; index++)
  4644. {
  4645. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4646. {
  4647. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  4648. }
  4649. }
  4650. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  4651. }
  4652. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  4653. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  4654. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  4655. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  4656. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4657. //***********************************************(10)VOLTAGE L3******************************************************/
  4658. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4659. {
  4660. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4661. {
  4662. tempIndex = 2;
  4663. }
  4664. else
  4665. {
  4666. tempIndex = gun_index;
  4667. }
  4668. for (int index = 0; index < AC_QUANTITY; index++)
  4669. {
  4670. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4671. {
  4672. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  4673. }
  4674. }
  4675. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  4676. }
  4677. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  4678. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  4679. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  4680. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  4681. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4682. // Message create ====================================================================================================
  4683. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4684. {
  4685. 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\"}]}]}]"
  4686. ,gun_index + 1
  4687. ,MESSAGE_TYPE_CALL
  4688. ,guid
  4689. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4690. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4691. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4692. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4693. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4694. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4695. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4696. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4697. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4698. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4699. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4700. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4701. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4702. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4703. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4704. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4705. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4706. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4707. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4708. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4709. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4710. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4711. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4712. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4713. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4714. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4715. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4716. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4717. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4718. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4719. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4720. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4721. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4722. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4723. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4724. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4725. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4726. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4727. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value
  4728. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context
  4729. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format
  4730. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand
  4731. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase
  4732. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location
  4733. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit
  4734. );
  4735. }
  4736. else
  4737. {
  4738. if((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W'))
  4739. {
  4740. 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\"}]}]}]"
  4741. ,gun_index + 1
  4742. ,MESSAGE_TYPE_CALL
  4743. ,guid
  4744. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4745. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4746. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4747. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4748. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4749. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4750. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4751. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4752. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4753. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4754. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4755. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4756. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4757. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4758. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4759. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4760. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4761. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4762. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4763. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4764. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4765. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4766. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4767. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4768. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4769. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4770. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4771. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4772. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4773. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4774. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4775. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4776. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4777. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4778. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4779. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4780. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4781. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4782. );
  4783. }
  4784. else
  4785. {
  4786. 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\"}]}]}]"
  4787. ,gun_index + 1
  4788. ,MESSAGE_TYPE_CALL
  4789. ,guid
  4790. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4791. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4792. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4793. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4794. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4795. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4796. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4797. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4798. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4799. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4800. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4801. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4802. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4803. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4804. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4805. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4806. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4807. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4808. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4809. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4810. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4811. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4812. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4813. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4814. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4815. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4816. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4817. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4818. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4819. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4820. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4821. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4822. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4823. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4824. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4825. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4826. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4827. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4828. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value
  4829. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context
  4830. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format
  4831. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand
  4832. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase
  4833. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location
  4834. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit
  4835. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value
  4836. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context
  4837. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format
  4838. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand
  4839. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase
  4840. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location
  4841. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit
  4842. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value
  4843. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context
  4844. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format
  4845. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand
  4846. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase
  4847. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location
  4848. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit
  4849. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value
  4850. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context
  4851. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format
  4852. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand
  4853. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase
  4854. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location
  4855. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit
  4856. );
  4857. }
  4858. }
  4859. // Put request guid to hash map
  4860. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4861. 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*/)
  4862. {
  4863. result = PASS;
  4864. DEBUG_INFO("MeterValues mapitem pass\n");
  4865. }
  4866. if(dataType != ReadingContext_Trigger)
  4867. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4868. else
  4869. LWS_Send(queuedata +2);
  4870. /*
  4871. if(GetTransactionQueueNum() == 1)
  4872. {
  4873. LWS_Send(queuedata +2);
  4874. }*/
  4875. return result;
  4876. }
  4877. //==========================================
  4878. // send confirm routine
  4879. //==========================================
  4880. int sendCancelReservationConfirmation(char *uuid,char *payload)
  4881. {
  4882. mtrace();
  4883. int result = FAIL;
  4884. char message[100]={0};
  4885. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  4886. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4887. LWS_Send(message);
  4888. result = TRUE;
  4889. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  4890. return result;
  4891. }
  4892. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  4893. {
  4894. mtrace();
  4895. int result = FAIL;
  4896. char message[100]={0};
  4897. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  4898. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4899. LWS_Send(message);
  4900. result = TRUE;
  4901. return result;
  4902. }
  4903. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  4904. {
  4905. mtrace();
  4906. int result = FAIL;
  4907. char message[100]={0};
  4908. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  4909. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4910. LWS_Send(message);
  4911. result = TRUE;
  4912. return result;
  4913. }
  4914. int sendClearCacheConfirmation(char *uuid,char *payload)
  4915. {
  4916. mtrace();
  4917. int result = FAIL;
  4918. char message[500]={0};
  4919. DEBUG_INFO("sendClearCacheConfirmation...\n");
  4920. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4921. LWS_Send(message);
  4922. return result;
  4923. }
  4924. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  4925. {
  4926. mtrace();
  4927. int result = FAIL;
  4928. char message[500]={0};
  4929. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  4930. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4931. LWS_Send(message);
  4932. return result;
  4933. }
  4934. int sendDataTransferConfirmation(char *uuid,char *payload)
  4935. {
  4936. mtrace();
  4937. char statusStr[20]={0};
  4938. char dataStr[10]={0};
  4939. char sstr[20]={0};
  4940. int c = 0;
  4941. char *loc;
  4942. int result = FAIL;
  4943. DEBUG_INFO("sendDataTransferConfirmation...\n");
  4944. /**********************status**************************/
  4945. loc = strstr(payload, "status");
  4946. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4947. c = 0;
  4948. while (loc[3+strlen("status")+c] != '\"')
  4949. {
  4950. sstr[c] = loc[3+strlen("status")+c];
  4951. c++;
  4952. }
  4953. sstr[c] = '\0';
  4954. strcpy(statusStr, sstr);
  4955. /**********************data**************************/
  4956. loc = strstr(payload, "data");
  4957. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4958. c = 0;
  4959. while (loc[3+strlen("data")+c] != '\"')
  4960. {
  4961. sstr[c] = loc[3+strlen("data")+c];
  4962. c++;
  4963. }
  4964. sstr[c] = '\0';
  4965. strcpy(dataStr, sstr);
  4966. return result;
  4967. }
  4968. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  4969. {
  4970. mtrace();
  4971. int result = FAIL;
  4972. char message[1000]={0};
  4973. int CompositeScheduleIndex = 0;
  4974. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  4975. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  4976. if(nPeriod == 0)
  4977. {
  4978. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  4979. {
  4980. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  4981. ,MESSAGE_TYPE_CALLRESULT
  4982. ,uuid
  4983. ,payload
  4984. ,connectorIdInt);
  4985. }
  4986. else
  4987. {
  4988. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  4989. ,MESSAGE_TYPE_CALLRESULT
  4990. ,uuid
  4991. ,payload
  4992. ,connectorIdInt
  4993. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4994. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4995. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4996. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  4997. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  4998. }
  4999. }
  5000. else
  5001. {
  5002. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5003. ,MESSAGE_TYPE_CALLRESULT
  5004. ,uuid
  5005. ,payload
  5006. ,connectorIdInt
  5007. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5008. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5009. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5010. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5011. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5012. {
  5013. if (idx_sample == 0)
  5014. {
  5015. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5016. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5017. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5018. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5019. }
  5020. else
  5021. {
  5022. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5023. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5024. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5025. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5026. }
  5027. }
  5028. sprintf(message + strlen(message), "]}}]");
  5029. }
  5030. LWS_Send(message);
  5031. result = TRUE;
  5032. return result;
  5033. }
  5034. int sendGetConfigurationConfirmation(char *uuid)
  5035. {
  5036. mtrace();
  5037. int result = FAIL;
  5038. int MaxKeySupported = 0;
  5039. int sentConfigurationNumber= 0;
  5040. int sentunConfigurationNumber= 0;
  5041. char message[4000]={0};
  5042. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5043. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5044. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5045. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5046. ,MESSAGE_TYPE_CALLRESULT
  5047. ,uuid );
  5048. //configuration key
  5049. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5050. {
  5051. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5052. {
  5053. if (sentConfigurationNumber == 0)
  5054. {
  5055. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5056. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5057. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5058. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5059. }
  5060. else
  5061. {
  5062. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5063. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5064. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5065. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5066. }
  5067. sentConfigurationNumber = sentConfigurationNumber + 1;
  5068. }
  5069. }
  5070. sprintf(message + strlen(message), "]");
  5071. if(UnknownKeynum != 0)
  5072. {
  5073. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5074. //unkown key
  5075. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5076. {
  5077. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5078. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5079. if(sentunConfigurationNumber == 0)
  5080. {
  5081. sprintf(message + strlen(message), "\"%s\""
  5082. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5083. }
  5084. else
  5085. {
  5086. sprintf(message + strlen(message), ",\"%s\""
  5087. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5088. }
  5089. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5090. }
  5091. sprintf(message + strlen(message), "]");
  5092. }
  5093. sprintf(message + strlen(message), "}]");
  5094. LWS_Send(message);
  5095. return result;
  5096. }
  5097. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5098. {
  5099. mtrace();
  5100. int result = FAIL;
  5101. char message[400]={0};
  5102. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5103. if(strcmp(payload,"")==0)
  5104. {
  5105. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5106. }
  5107. else
  5108. {
  5109. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5110. }
  5111. LWS_Send(message);
  5112. result = TRUE;
  5113. return result;
  5114. }
  5115. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5116. {
  5117. mtrace();
  5118. int result = FAIL;
  5119. char message[80]={0};
  5120. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5121. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5122. LWS_Send(message);
  5123. result = TRUE;
  5124. return result;
  5125. }
  5126. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5127. {
  5128. mtrace();
  5129. int result = FAIL;
  5130. char message[80]={0};
  5131. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5132. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5133. LWS_Send(message);
  5134. result = TRUE;
  5135. return result;
  5136. }
  5137. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5138. {
  5139. mtrace();
  5140. int result = FAIL;
  5141. char message[80]={0};
  5142. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5143. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5144. LWS_Send(message);
  5145. result = TRUE;
  5146. return result;
  5147. }
  5148. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5149. {
  5150. mtrace();
  5151. int result = FAIL;
  5152. char message[80]={0};
  5153. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5154. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5155. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5156. LWS_Send(message);
  5157. result = TRUE;
  5158. return result;
  5159. }
  5160. int sendResetConfirmation(char *uuid,char *payload)
  5161. {
  5162. mtrace();
  5163. int result = FAIL;
  5164. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5165. char message[80]={0};
  5166. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5167. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5168. LWS_Send(message);
  5169. result = TRUE;
  5170. return result;
  5171. }
  5172. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5173. {
  5174. mtrace();
  5175. int result = FAIL;
  5176. char message[500]={0};
  5177. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5178. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5179. LWS_Send(message);
  5180. result = TRUE;
  5181. return result;
  5182. }
  5183. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5184. {
  5185. mtrace();
  5186. int result = FAIL;
  5187. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5188. char message[80]={0};
  5189. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5190. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5191. LWS_Send(message);
  5192. result = TRUE;
  5193. return result;
  5194. }
  5195. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5196. {
  5197. mtrace();
  5198. int result = FAIL;
  5199. char message[80]={0};
  5200. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5201. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5202. LWS_Send(message);
  5203. result = TRUE;
  5204. return result;
  5205. }
  5206. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5207. {
  5208. mtrace();
  5209. int result = FAIL;
  5210. char message[80]={0};
  5211. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5212. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5213. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5214. LWS_Send(message);
  5215. result = TRUE;
  5216. return result;
  5217. }
  5218. int sendUpdateFirmwareConfirmation(char *uuid)
  5219. {
  5220. mtrace();
  5221. int result = FAIL;
  5222. char message[60]={0};
  5223. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5224. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5225. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5226. LWS_Send(message);
  5227. result = TRUE;
  5228. return result;
  5229. }
  5230. //==========================================
  5231. // send CallError routine
  5232. //==========================================
  5233. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5234. {
  5235. mtrace();
  5236. char message[220]={0};
  5237. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5238. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5239. LWS_Send(message);
  5240. }
  5241. //==========================================
  5242. // Handle server request routine Start
  5243. //==========================================
  5244. int handleCancelReservationRequest(char *uuid, char *payload)
  5245. {
  5246. mtrace();
  5247. int result = FAIL;
  5248. int gunNO = 0;
  5249. int reservationIdInt = -1;
  5250. char comfirmstr[20];
  5251. DEBUG_INFO("handleCancelReservationRequest...\n");
  5252. json_object *CancelReservation;
  5253. CancelReservation = json_tokener_parse(payload);
  5254. if(!is_error(CancelReservation))
  5255. {
  5256. // Required data
  5257. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  5258. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5259. }
  5260. json_object_put(CancelReservation);
  5261. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  5262. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5263. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5264. if(reservationIdInt != -1)
  5265. {
  5266. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5267. //check Transaction active
  5268. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5269. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5270. {
  5271. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5272. {
  5273. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5274. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5275. if(gunType[2] == 'J')
  5276. {
  5277. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5278. }
  5279. else
  5280. {
  5281. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5282. }
  5283. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5284. goto end;
  5285. }
  5286. }
  5287. for (int index = 0; index < CCS_QUANTITY; index++)
  5288. {
  5289. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5290. {
  5291. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5292. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5293. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5294. {
  5295. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5296. }
  5297. else
  5298. {
  5299. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5300. }
  5301. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5302. goto end;
  5303. }
  5304. }
  5305. for (int index = 0; index < GB_QUANTITY; index++)
  5306. {
  5307. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5308. {
  5309. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5310. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5311. if(gunType[2] == 'G')
  5312. {
  5313. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5314. }
  5315. else
  5316. {
  5317. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5318. }
  5319. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5320. goto end;
  5321. }
  5322. }
  5323. for (int index = 0; index < AC_QUANTITY; index++)
  5324. {
  5325. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5326. {
  5327. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5328. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5329. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5330. {
  5331. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5332. }
  5333. else
  5334. {
  5335. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5336. }
  5337. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5338. goto end;
  5339. }
  5340. }
  5341. }
  5342. //The reservationId does NOT match the reservationId
  5343. sendCancelReservationConfirmation(uuid, comfirmstr);
  5344. end:
  5345. // Fill in ocpp packet uuid
  5346. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5347. return result;
  5348. }
  5349. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5350. {
  5351. mtrace();
  5352. int result = FAIL;
  5353. int gunIndex = 0;
  5354. char typeStr[16]={0};
  5355. char comfirmstr[20];
  5356. int specificId = FALSE;
  5357. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5358. json_object *ChangeAvailability;
  5359. ChangeAvailability = json_tokener_parse(payload);
  5360. if(!is_error(ChangeAvailability))
  5361. {
  5362. // Required data
  5363. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  5364. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5365. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  5366. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5367. }
  5368. json_object_put(ChangeAvailability);
  5369. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5370. {
  5371. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5372. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5373. }
  5374. else if(gunIndex == 0)
  5375. {
  5376. for(int i=0; i < gunTotalNumber; i++)
  5377. {
  5378. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5379. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5380. }
  5381. }
  5382. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5383. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5384. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  5385. {
  5386. specificId = TRUE;
  5387. }
  5388. if(specificId == FALSE)
  5389. goto end;
  5390. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5391. {
  5392. //----------------------gunIndex is 0 ------------------------------------------------//
  5393. if(gunIndex == 0)
  5394. {
  5395. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5396. {
  5397. for(int i=0; i < gunTotalNumber; i++)
  5398. {
  5399. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5400. {
  5401. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5402. {
  5403. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5404. {
  5405. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5406. goto end;
  5407. }
  5408. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5409. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5410. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5411. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5412. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5413. {
  5414. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5415. goto end;
  5416. }
  5417. }
  5418. }//END FOR CHAdeMO_QUANTITY
  5419. for (int index = 0; index < CCS_QUANTITY; index++)
  5420. {
  5421. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5422. {
  5423. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5424. {
  5425. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5426. goto end;
  5427. }
  5428. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5429. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5430. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5431. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5432. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5433. {
  5434. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5435. goto end;
  5436. }
  5437. }
  5438. }//END FOR CCS_QUANTITY
  5439. for (int index = 0; index < GB_QUANTITY; index++)
  5440. {
  5441. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5442. {
  5443. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5444. {
  5445. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5446. goto end;
  5447. }
  5448. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5449. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5450. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5451. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5452. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5453. {
  5454. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5455. goto end;
  5456. }
  5457. }
  5458. }// END FOR GB_QUANTITY
  5459. for (int index = 0; index < AC_QUANTITY; index++)
  5460. {
  5461. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5462. {
  5463. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5464. {
  5465. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5466. goto end;
  5467. }
  5468. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5469. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5470. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5471. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5472. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5473. {
  5474. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5475. goto end;
  5476. }
  5477. }
  5478. }//END FOR AC_QUANTITY
  5479. }// END FOR gunTotalNumber
  5480. }
  5481. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5482. {
  5483. for(int i=0; i < gunTotalNumber; i++)
  5484. {
  5485. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5486. {
  5487. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5488. goto end;
  5489. }
  5490. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5491. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5492. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5493. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5494. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5495. {
  5496. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5497. goto end;
  5498. }
  5499. }
  5500. }
  5501. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5502. goto end;
  5503. }
  5504. //----------------------gunIndex is not 0 ------------------------------------------------//
  5505. //check Transaction active
  5506. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5507. {
  5508. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5509. {
  5510. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5511. {
  5512. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5513. goto end;
  5514. }
  5515. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5516. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5517. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5518. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5519. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5520. {
  5521. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5522. goto end;
  5523. }
  5524. else
  5525. {
  5526. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5527. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5528. goto end;
  5529. }
  5530. }
  5531. }//END FOR CHAdeMO_QUANTITY
  5532. for (int index = 0; index < CCS_QUANTITY; index++)
  5533. {
  5534. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5535. {
  5536. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5537. {
  5538. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5539. goto end;
  5540. }
  5541. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5542. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5543. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5544. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5545. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5546. {
  5547. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5548. goto end;
  5549. }
  5550. else
  5551. {
  5552. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5553. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5554. goto end;
  5555. }
  5556. }
  5557. }//END FOR CCS_QUANTITY
  5558. for (int index = 0; index < GB_QUANTITY; index++)
  5559. {
  5560. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5561. {
  5562. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5563. {
  5564. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5565. goto end;
  5566. }
  5567. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5568. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5569. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5570. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5571. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5572. {
  5573. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5574. goto end;
  5575. }
  5576. else
  5577. {
  5578. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5579. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5580. goto end;
  5581. }
  5582. }
  5583. }// END FOR GB_QUANTITY
  5584. for (int index = 0; index < AC_QUANTITY; index++)
  5585. {
  5586. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5587. {
  5588. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5589. {
  5590. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5591. goto end;
  5592. }
  5593. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5594. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5595. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5596. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5597. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5598. {
  5599. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5600. goto end;
  5601. }
  5602. else
  5603. {
  5604. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5605. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5606. goto end;
  5607. }
  5608. }
  5609. }//END FOR AC_QUANTITY
  5610. }//END FOR AvailabilityTypeStr[Inoperative]
  5611. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5612. {
  5613. //----------------------gunIndex is 0 ------------------------------------------------//
  5614. if(gunIndex == 0)
  5615. {
  5616. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5617. {
  5618. for(int i=0; i < gunTotalNumber; i++)
  5619. {
  5620. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5621. {
  5622. 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
  5623. {
  5624. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5625. goto end;
  5626. }
  5627. }//END FOR CHAdeMO_QUANTITY
  5628. for (int index = 0; index < CCS_QUANTITY; index++)
  5629. {
  5630. 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
  5631. {
  5632. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5633. goto end;
  5634. }
  5635. }//END FOR CCS_QUANTITY
  5636. for (int index = 0; index < GB_QUANTITY; index++)
  5637. {
  5638. 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
  5639. {
  5640. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5641. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5642. goto end;
  5643. }
  5644. }// END FOR GB_QUANTITY
  5645. for (int index = 0; index < AC_QUANTITY; index++)
  5646. {
  5647. 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
  5648. {
  5649. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5650. goto end;
  5651. }
  5652. }//END FOR CHAdeMO_QUANTITY
  5653. }// END FOR gunTotalNumber
  5654. }
  5655. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5656. {
  5657. for(int i=0; i < gunTotalNumber; i++)
  5658. {
  5659. for (int index = 0; index < AC_QUANTITY; index++)
  5660. {
  5661. 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
  5662. {
  5663. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5664. goto end;
  5665. }
  5666. }//END FOR CHAdeMO_QUANTITY
  5667. } // END FOR gunTotalNumber
  5668. }
  5669. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5670. goto end;
  5671. }
  5672. //----------------------gunIndex is not 0 ------------------------------------------------//
  5673. //check Transaction active
  5674. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5675. {
  5676. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5677. {
  5678. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5679. goto end;
  5680. }
  5681. }//END FOR CHAdeMO_QUANTITY
  5682. for (int index = 0; index < CCS_QUANTITY; index++)
  5683. {
  5684. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5685. {
  5686. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5687. goto end;
  5688. }
  5689. }//END FOR CCS_QUANTITY
  5690. for (int index = 0; index < GB_QUANTITY; index++)
  5691. {
  5692. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5693. {
  5694. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5695. goto end;
  5696. }
  5697. }// END FOR GB_QUANTITY
  5698. for (int index = 0; index < AC_QUANTITY; index++)
  5699. {
  5700. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5701. {
  5702. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5703. goto end;
  5704. }
  5705. }//END FOR AC_QUANTITY
  5706. }//END FOR AvailabilityTypeStr[Operative]
  5707. end:
  5708. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5709. {
  5710. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5711. }
  5712. else
  5713. {
  5714. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5715. }
  5716. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5717. {
  5718. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5719. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5720. }
  5721. else if(gunIndex == 0)
  5722. {
  5723. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5724. {
  5725. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5726. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5727. }
  5728. }
  5729. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5730. return result;
  5731. }
  5732. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5733. {
  5734. mtrace();
  5735. int result = FAIL;
  5736. char keystr[40]={0};
  5737. char valuestr[100]={0};
  5738. char comfirmstr[20]={0};
  5739. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5740. json_object *ChangeConfiguration;
  5741. ChangeConfiguration = json_tokener_parse(payload);
  5742. if(!is_error(ChangeConfiguration))
  5743. {
  5744. // Required data
  5745. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  5746. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5747. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  5748. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5749. }
  5750. json_object_put(ChangeConfiguration);
  5751. if((uuid==NULL) || (payload ==NULL) )
  5752. {
  5753. DEBUG_ERROR("Payload is null\n");
  5754. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5755. }
  5756. else
  5757. {
  5758. int status = setKeyValue(keystr, valuestr);
  5759. switch(status)
  5760. {
  5761. case ConfigurationStatus_Accepted:
  5762. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5763. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5764. StoreConfigurationTable();
  5765. break;
  5766. case ConfigurationStatus_Rejected:
  5767. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5768. break;
  5769. case RebootRequired:
  5770. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5771. StoreConfigurationTable();
  5772. break;
  5773. case NotSupported:
  5774. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5775. break;
  5776. default:
  5777. break;
  5778. }
  5779. }
  5780. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5781. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5782. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5783. {
  5784. ChageWebSocketPingInterval(atoi(valuestr));
  5785. }
  5786. return result;
  5787. }
  5788. int handleClearCacheRequest(char *uuid, char *payload)
  5789. {
  5790. mtrace();
  5791. int result = FAIL;
  5792. char comfirmstr[20];
  5793. int fd;
  5794. char rmFileCmd[100]={0};
  5795. struct stat stats;
  5796. DEBUG_INFO("handleClearCacheRequest...\n");
  5797. stat("/Storage/OCPP", &stats);
  5798. // Check for directory existence
  5799. if (S_ISDIR(stats.st_mode) == 1)
  5800. {}
  5801. else
  5802. {
  5803. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  5804. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  5805. system(rmFileCmd);
  5806. }
  5807. memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
  5808. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  5809. {
  5810. DEBUG_INFO("AuthorizationCache file exist.\n");
  5811. }
  5812. else
  5813. {
  5814. DEBUG_INFO("AuthorizationCache file not exist\n");
  5815. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  5816. if(log == NULL)
  5817. {
  5818. DEBUG_INFO("AuthorizationCache file is NULL\n");
  5819. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5820. goto end;
  5821. }
  5822. else
  5823. {
  5824. fclose(log);
  5825. }
  5826. }
  5827. if((fd = open(AuthorizationCache_JSON,O_RDWR)) < 0)
  5828. {
  5829. DEBUG_INFO("open AuthorizationCache file failed\n");
  5830. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5831. }
  5832. else
  5833. {
  5834. DEBUG_INFO("open AuthorizationCache file successful\n");
  5835. ftruncate(fd,0);
  5836. lseek(fd,0,SEEK_SET);
  5837. close(fd);
  5838. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  5839. }
  5840. end:
  5841. sendClearCacheConfirmation(uuid, comfirmstr);
  5842. return result;
  5843. }
  5844. int handleClearChargingProfileRequest(char *uuid, char *payload)
  5845. {
  5846. mtrace();
  5847. int result = FAIL;
  5848. int resultRename;
  5849. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  5850. char chargingProfilePurposeStr[26]={0};
  5851. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  5852. char tempchargingProfilePurposeStr[26]={0};
  5853. char sstr[160]={0};
  5854. char str[100]={0};
  5855. int c = 0;
  5856. char *loc;
  5857. char fname[200]={0};
  5858. char comfirmstr[20]={0};
  5859. char word[1600]={0};
  5860. int clearflag = FALSE;
  5861. int chargingProfileIdIsNULL = FALSE;
  5862. int connectorIsNULL = FALSE;
  5863. int chargingProfilePurposeIsNULL = FALSE;
  5864. int stackLevelIsNULL = FALSE;
  5865. //int GotoEnd = FALSE;
  5866. FILE *fptr1, *fptr2;
  5867. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  5868. int n_chargingProfile=0;
  5869. int isEmptyFile = FALSE;
  5870. char sLineWord[1600]={0};
  5871. char chargingProfiles[10][100]={0};
  5872. int ChargeProfileCount = 0;
  5873. char ch;
  5874. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  5875. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  5876. json_object *ClearChargingProfile;
  5877. ClearChargingProfile = json_tokener_parse(payload);
  5878. if(!is_error(ClearChargingProfile))
  5879. {
  5880. // Optional data
  5881. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  5882. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  5883. else
  5884. chargingProfileIdIsNULL = TRUE;
  5885. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  5886. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  5887. else
  5888. connectorIsNULL = TRUE;
  5889. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  5890. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  5891. else
  5892. chargingProfilePurposeIsNULL = TRUE;
  5893. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  5894. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  5895. else
  5896. stackLevelIsNULL = TRUE;
  5897. }
  5898. json_object_put(ClearChargingProfile);
  5899. if(connectorIsNULL == FALSE)
  5900. {
  5901. switch(connectorIdInt)
  5902. {
  5903. case 0:
  5904. if(chargingProfilePurposeIsNULL == TRUE)
  5905. {
  5906. int l = 0;
  5907. strcpy(fname, ChargePointMaxProfile_JSON);
  5908. if((access(fname,F_OK))!=-1)
  5909. {
  5910. strcpy(chargingProfiles[l], fname);
  5911. l = l + 1;
  5912. }
  5913. strcpy(fname, TxDefaultProfile_0_JSON);
  5914. if((access(fname,F_OK))!=-1)
  5915. {
  5916. strcpy(chargingProfiles[l], fname);
  5917. l = l + 1;
  5918. }
  5919. ChargeProfileCount = l;
  5920. }
  5921. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  5922. {
  5923. strcpy(fname, ChargePointMaxProfile_JSON);
  5924. if((access(fname,F_OK))!=-1)
  5925. {
  5926. strcpy(chargingProfiles[0], fname);
  5927. ChargeProfileCount = 1;
  5928. }
  5929. }
  5930. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5931. {
  5932. strcpy(fname, TxDefaultProfile_0_JSON);
  5933. if((access(fname,F_OK))!=-1)
  5934. {
  5935. strcpy(chargingProfiles[0], fname);
  5936. ChargeProfileCount = 1;
  5937. }
  5938. }
  5939. break;
  5940. default:
  5941. if(chargingProfilePurposeIsNULL == TRUE)
  5942. {
  5943. int m = 0;
  5944. memset(fname, 0, ARRAY_SIZE(fname));
  5945. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5946. if((access(fname,F_OK))!=-1)
  5947. {
  5948. strcpy(chargingProfiles[m], fname);
  5949. m = m + 1;
  5950. }
  5951. memset(fname, 0, ARRAY_SIZE(fname));
  5952. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5953. if((access(fname,F_OK))!=-1)
  5954. {
  5955. strcpy(chargingProfiles[m], fname);
  5956. m = m + 1;
  5957. }
  5958. ChargeProfileCount = m;
  5959. }
  5960. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5961. {
  5962. //strcpy(fname, TxDefaultProfile_1_JSON);
  5963. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5964. if((access(fname,F_OK))!=-1)
  5965. {
  5966. strcpy(chargingProfiles[0], fname);
  5967. ChargeProfileCount = 1;
  5968. }
  5969. }
  5970. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  5971. {
  5972. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5973. if((access(fname,F_OK))!=-1)
  5974. {
  5975. strcpy(chargingProfiles[0], fname);
  5976. ChargeProfileCount = 1;
  5977. }
  5978. //strcpy(fname, TxProfile_1_JSON);
  5979. }
  5980. //strcpy(fname, ChargePointMaxProfile_JSON );
  5981. break;
  5982. }
  5983. }
  5984. else // Check all Charging Profiles
  5985. {
  5986. int i = 0;
  5987. char fnametemp[200]={0};
  5988. ChargeProfileCount = 0;
  5989. //Check ChargePointMaxProfile.json exit
  5990. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  5991. {
  5992. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  5993. i = i + 1;
  5994. }
  5995. //Check TxDefaultProfile_0.json exit
  5996. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  5997. {
  5998. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  5999. i = i + 1;
  6000. }
  6001. //Check TxDefaultProfile_%d.json
  6002. for(int j=1; j <= gunTotalNumber; j++)
  6003. {
  6004. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6005. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  6006. if((access(fnametemp,F_OK))!=-1)
  6007. {
  6008. strcpy(chargingProfiles[i], fnametemp);
  6009. i = i + 1;
  6010. }
  6011. }
  6012. //Check TxProfile_%d.json
  6013. for(int j=1; j <= gunTotalNumber; j++)
  6014. {
  6015. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6016. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6017. if((access(fnametemp,F_OK))!=-1)
  6018. {
  6019. strcpy(chargingProfiles[i], fnametemp);
  6020. i = i + 1;
  6021. }
  6022. }
  6023. ChargeProfileCount = i;
  6024. }// End connectorIsNULL is TRUE
  6025. if(ChargeProfileCount == 0)
  6026. {
  6027. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6028. goto end;
  6029. }
  6030. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6031. {
  6032. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6033. goto end;
  6034. }
  6035. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6036. {
  6037. memset(str, 0, ARRAY_SIZE(str));
  6038. // clear temp file
  6039. sprintf(str,"rm -f %s",temp);
  6040. system(str);
  6041. for(int k=0; k < ChargeProfileCount; k++)
  6042. {
  6043. memset(str, 0, ARRAY_SIZE(str));
  6044. //clear file in C
  6045. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6046. system(str);
  6047. }
  6048. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6049. goto end;
  6050. }
  6051. else if(connectorIsNULL == TRUE)
  6052. {
  6053. for(int k=0; k < ChargeProfileCount; k++)
  6054. {
  6055. fptr1 = fopen(chargingProfiles[k], "r");
  6056. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6057. //Check Charging Profile Count
  6058. while(fscanf(fptr1, "%s", word) != EOF)
  6059. {
  6060. //DEBUG_INFO("word=%s\n",word);
  6061. if(strstr(word, "chargingProfileId")!= NULL)
  6062. {
  6063. //DEBUG_INFO("test chargingProfileId \n");
  6064. n_chargingProfile = n_chargingProfile + 1;
  6065. //DEBUG_INFO("chargingProfileId Found\n");
  6066. }
  6067. }
  6068. rewind(fptr1);
  6069. //search Charging Profile Element
  6070. //int i= 0;
  6071. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6072. {
  6073. //------------------------tempconnectorIdInt------------------------//
  6074. loc = strstr(sLineWord, "connectorId");
  6075. c = 0;
  6076. memset(sstr ,0, sizeof(sstr) );
  6077. while (loc[strlen("connectorId")+2+c] != ',')
  6078. {
  6079. sstr[c] = loc[strlen("connectorId")+2+c];
  6080. c++;
  6081. }
  6082. sstr[c] = '\0';
  6083. tempconnectorIdInt = atoi(sstr);
  6084. printf("file's gun number is %d\n", tempconnectorIdInt);
  6085. //--------------------------chargingProfileId--------------------//
  6086. c = 0;
  6087. loc = strstr(sLineWord, "chargingProfileId");
  6088. memset(sstr ,0, ARRAY_SIZE(sstr));
  6089. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6090. {
  6091. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6092. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6093. c++;
  6094. }
  6095. sstr[c] = '\0';
  6096. tempchargingProfileIdInt = atoi(sstr);
  6097. //stackLevel
  6098. c = 0;
  6099. loc = strstr(sLineWord, "stackLevel");
  6100. memset(sstr ,0, ARRAY_SIZE(sstr));
  6101. while (loc[strlen("stackLevel")+2+c] != ',')
  6102. {
  6103. sstr[c] = loc[strlen("stackLevel")+2+c];
  6104. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6105. c++;
  6106. }
  6107. sstr[c] = '\0';
  6108. tempstackLevelInt = atoi(sstr);
  6109. c = 0;
  6110. loc = strstr(sLineWord, "chargingProfilePurpose");
  6111. memset(sstr ,0, ARRAY_SIZE(sstr));
  6112. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6113. {
  6114. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6115. c++;
  6116. }
  6117. sstr[c] = '\0';
  6118. strcpy(tempchargingProfilePurposeStr, sstr);
  6119. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6120. {
  6121. //------- not write to fptr2-------//
  6122. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6123. //clearflag = TRUE;
  6124. }
  6125. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6126. {
  6127. //------- not write to fptr2-------//
  6128. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6129. }
  6130. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6131. {
  6132. //------- not write to fptr2-------//
  6133. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6134. }
  6135. else
  6136. {
  6137. fprintf(fptr2, sLineWord);//writing data into file
  6138. }
  6139. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6140. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6141. if(clearflag == TRUE)
  6142. {
  6143. fclose(fptr1);
  6144. fclose(fptr2);
  6145. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6146. system(str);
  6147. // clear temp file
  6148. sprintf(str,"rm -f %s",temp);
  6149. system(str);
  6150. }
  6151. else
  6152. {
  6153. fclose(fptr1);
  6154. fclose(fptr2);
  6155. memset(str, 0, ARRAY_SIZE(str));
  6156. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6157. system(str);
  6158. resultRename = rename(temp, chargingProfiles[k]);
  6159. if(resultRename == 0)
  6160. {
  6161. DEBUG_INFO("File ChargingProfile renamed successfully");
  6162. }
  6163. else
  6164. {
  6165. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6166. }
  6167. if(comfirmstr[0]== 0)
  6168. {
  6169. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6170. }
  6171. //Check chargingProfile is empty file
  6172. /*------ Read the file ----------------*/
  6173. fptr1=fopen(chargingProfiles[k],"r");
  6174. ch=fgetc(fptr1);
  6175. rewind(fptr1);
  6176. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6177. if(ch!=EOF)
  6178. {
  6179. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6180. {
  6181. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6182. if(sLineWord[0]=='\0')
  6183. {
  6184. isEmptyFile = TRUE;
  6185. break;
  6186. }
  6187. else
  6188. {
  6189. isEmptyFile = FALSE;
  6190. break;
  6191. }
  6192. }
  6193. }
  6194. fclose(fptr1);
  6195. if(isEmptyFile == TRUE)
  6196. {
  6197. memset(str, 0, ARRAY_SIZE(str));
  6198. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6199. system(str);
  6200. }
  6201. }
  6202. }// End of while(int k=0; k < ChargePointCount; k++)
  6203. }
  6204. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6205. {
  6206. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6207. for(int k=0; k < ChargeProfileCount; k++)
  6208. {
  6209. fptr1 = fopen(chargingProfiles[k], "r");
  6210. fptr2 = fopen(temp, "w+");
  6211. //Check Charging Profile Count
  6212. while(fscanf(fptr1, "%s", word) != EOF)
  6213. {
  6214. //DEBUG_INFO("word=%s\n",word);
  6215. if(strstr(word, "chargingProfileId")!= NULL)
  6216. {
  6217. n_chargingProfile = n_chargingProfile + 1;
  6218. }
  6219. }
  6220. rewind(fptr1);
  6221. //search Charging Profile Element
  6222. //int i= 0;
  6223. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6224. {
  6225. //*************************tempconnectorIdInt*********************************/
  6226. loc = strstr(sLineWord, "connectorId");
  6227. c = 0;
  6228. memset(sstr ,0, ARRAY_SIZE(sstr));
  6229. while (loc[strlen("connectorId")+2+c] != ',')
  6230. {
  6231. sstr[c] = loc[strlen("connectorId")+2+c];
  6232. c++;
  6233. }
  6234. sstr[c] = '\0';
  6235. tempconnectorIdInt = atoi(sstr);
  6236. //chargingProfileId
  6237. c = 0;
  6238. loc = strstr(sLineWord, "chargingProfileId");
  6239. memset(sstr ,0, ARRAY_SIZE(sstr));
  6240. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6241. {
  6242. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6243. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6244. c++;
  6245. }
  6246. sstr[c] = '\0';
  6247. tempchargingProfileIdInt = atoi(sstr);
  6248. //stackLevel
  6249. c = 0;
  6250. loc = strstr(sLineWord, "stackLevel");
  6251. memset(sstr ,0, ARRAY_SIZE(sstr));
  6252. while (loc[strlen("stackLevel")+2+c] != ',')
  6253. {
  6254. sstr[c] = loc[strlen("stackLevel")+2+c];
  6255. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6256. c++;
  6257. }
  6258. sstr[c] = '\0';
  6259. tempstackLevelInt = atoi(sstr);
  6260. c = 0;
  6261. loc = strstr(sLineWord, "chargingProfilePurpose");
  6262. memset(sstr ,0, ARRAY_SIZE(sstr));
  6263. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6264. {
  6265. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6266. c++;
  6267. }
  6268. sstr[c] = '\0';
  6269. strcpy(tempchargingProfilePurposeStr, sstr);
  6270. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6271. {
  6272. //------- not write to fptr2-------//
  6273. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6274. //clearflag = TRUE;
  6275. }
  6276. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6277. {
  6278. //------- not write to fptr2-------//
  6279. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6280. }
  6281. else if(stackLevelIsNULL == TRUE)
  6282. {
  6283. //Clear Whole File
  6284. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6285. clearflag = TRUE;
  6286. break;
  6287. }
  6288. else
  6289. {
  6290. fprintf(fptr2, sLineWord);//writing data into file
  6291. }
  6292. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6293. }
  6294. if(clearflag == TRUE)
  6295. {
  6296. fclose(fptr1);
  6297. fclose(fptr2);
  6298. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6299. system(str);
  6300. // clear temp file
  6301. sprintf(str,"rm -f %s",temp);
  6302. system(str);
  6303. }
  6304. else
  6305. {
  6306. fclose(fptr1);
  6307. fclose(fptr2);
  6308. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6309. system(str);
  6310. resultRename = rename(temp, chargingProfiles[k]);
  6311. if(resultRename == 0)
  6312. {
  6313. DEBUG_INFO("File ChargingProfile renamed successfully");
  6314. }
  6315. else
  6316. {
  6317. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6318. }
  6319. if(comfirmstr[0]== 0)
  6320. {
  6321. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6322. }
  6323. //Check chargingProfile is empty file
  6324. /*------ Read the file ----------------*/
  6325. fptr1=fopen(chargingProfiles[k],"r");
  6326. ch=fgetc(fptr1);
  6327. rewind(fptr1);
  6328. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6329. if(ch!=EOF)
  6330. {
  6331. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6332. {
  6333. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6334. if(sLineWord[0]=='\0')
  6335. {
  6336. isEmptyFile = TRUE;
  6337. break;
  6338. }
  6339. else
  6340. {
  6341. isEmptyFile = FALSE;
  6342. break;
  6343. }
  6344. }
  6345. }
  6346. fclose(fptr1);
  6347. if(isEmptyFile == TRUE)
  6348. {
  6349. memset(str, 0, ARRAY_SIZE(str));
  6350. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6351. system(str);
  6352. }
  6353. /*------- End of reading ---------------*/
  6354. }
  6355. } // while(int k=0; k < ChargeProfileCount; k++)
  6356. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6357. end:
  6358. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6359. return result;
  6360. }
  6361. void createFirmwareVersionByDataTransfer(void)
  6362. {
  6363. json_object *FirmwareDataTransfer = json_object_new_object();
  6364. // AC & DC model
  6365. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6366. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6367. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6368. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6369. // DC model
  6370. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6371. {
  6372. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6373. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6374. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6375. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6376. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6377. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6378. }
  6379. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6380. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6381. {
  6382. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6383. }
  6384. // 4G model
  6385. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  6386. {
  6387. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6388. }
  6389. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6390. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6391. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string(FirmwareDataTransfer));
  6392. }
  6393. int handleDataTransferRequest(char *uuid, char *payload)
  6394. {
  6395. mtrace();
  6396. json_object *response = json_object_new_object();
  6397. int result = FAIL;
  6398. char tempvendorId[255]={0};
  6399. char tempmessageId[50]={0};
  6400. char tempdata[512]={0};
  6401. char message[2048]={0};
  6402. DEBUG_INFO("handleDataTransferRequest...\n");
  6403. if((uuid != NULL) && (payload != NULL))
  6404. {
  6405. json_object *DataTransfer;
  6406. DataTransfer = json_tokener_parse(payload);
  6407. if(!is_error(DataTransfer))
  6408. {
  6409. // Required data
  6410. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  6411. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6412. // Optional data
  6413. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6414. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6415. if(json_object_object_get(DataTransfer, "data") != NULL)
  6416. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6417. result = PASS;
  6418. }
  6419. json_object_put(DataTransfer);
  6420. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6421. {
  6422. // Send all moudle firmware version on EVSE
  6423. system("/usr/bin/run_tmate_restart.sh");
  6424. createFirmwareVersionByDataTransfer();
  6425. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6426. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6427. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6428. }
  6429. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6430. {
  6431. json_object *data;
  6432. data = json_tokener_parse(tempdata);
  6433. if(!is_error(data))
  6434. {
  6435. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6436. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6437. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6438. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6439. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6440. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6441. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6442. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6443. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6444. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6445. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6446. }
  6447. else
  6448. {
  6449. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6450. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6451. }
  6452. json_object_put(data);
  6453. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6454. }
  6455. else
  6456. {
  6457. // Can not find valid message id
  6458. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6459. }
  6460. }
  6461. else
  6462. {
  6463. // Payload is null
  6464. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6465. }
  6466. LWS_Send(message);
  6467. return result;
  6468. }
  6469. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6470. {
  6471. mtrace();
  6472. int result = FAIL;
  6473. int connectorIdInt, durationInt;
  6474. char chargingRateUnitStr[4]={0};
  6475. char comfirmstr[20];
  6476. int confirmPeriods = 0;
  6477. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6478. json_object *GetCompositeSchedule;
  6479. GetCompositeSchedule = json_tokener_parse(payload);
  6480. if(!is_error(GetCompositeSchedule))
  6481. {
  6482. // Required data
  6483. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  6484. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6485. else
  6486. connectorIdInt = -1;
  6487. if(json_object_object_get(GetCompositeSchedule, "duration"))
  6488. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6489. else
  6490. durationInt = 86400;
  6491. // Optional data
  6492. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6493. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6494. }
  6495. json_object_put(GetCompositeSchedule);
  6496. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6497. if((connectorIdInt == 0) ||
  6498. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6499. {
  6500. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6501. struct StructChargingProfile tmpProfile[1];
  6502. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6503. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6504. {
  6505. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6506. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6507. }
  6508. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6509. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6510. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6511. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6512. {
  6513. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6514. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6515. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6516. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6517. {
  6518. confirmPeriods = idx;
  6519. break;
  6520. }
  6521. }
  6522. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6523. }
  6524. else
  6525. {
  6526. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6527. }
  6528. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6529. return result;
  6530. }
  6531. int handleGetConfigurationRequest(char *uuid, char *payload)
  6532. {
  6533. mtrace();
  6534. int result = FAIL;
  6535. int MaxKeySupported = 0;
  6536. int n_keys = 0;
  6537. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  6538. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6539. json_object *GetConfiguration;
  6540. GetConfiguration = json_tokener_parse(payload);
  6541. if(!is_error(GetConfiguration))
  6542. {
  6543. // Optional data
  6544. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6545. {
  6546. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6547. {
  6548. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6549. n_keys = idx + 1;
  6550. }
  6551. }
  6552. }
  6553. json_object_put(GetConfiguration);
  6554. UnknownKeynum = 0;
  6555. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6556. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6557. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6558. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6559. if(n_keys != 0)
  6560. {
  6561. for(int i=0;i<n_keys;i++)
  6562. {
  6563. getKeyValue(requestKey[i]);
  6564. }
  6565. }
  6566. else
  6567. {
  6568. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6569. getKeyValue("");
  6570. }
  6571. processUnkownKey();
  6572. sendGetConfigurationConfirmation(uuid);
  6573. return result;
  6574. }
  6575. static char fnamePlusPath[100]={0};
  6576. static char fnamePWithNoPath[60]={0};
  6577. void checkUploadLog(void)
  6578. {
  6579. FILE *fp;
  6580. /* Open the command for reading. */
  6581. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6582. if (fp == NULL) {
  6583. printf("Failed to run command\n" );
  6584. exit(1);
  6585. }
  6586. int ftppathlen = 0;
  6587. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6588. int i = 0;
  6589. /* Read the output a line at a time - output it. */
  6590. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6591. if(i==0)
  6592. {
  6593. ftppathlen = strlen(fnamePlusPath);
  6594. printf("%s\n", fnamePlusPath);
  6595. fnamePlusPath[ftppathlen]='\0';
  6596. break;
  6597. }
  6598. i= i+1;
  6599. }
  6600. /* close */
  6601. pclose(fp);
  6602. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6603. {
  6604. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6605. {
  6606. fnamePlusPath[k]='\0';
  6607. }
  6608. }
  6609. i=1;
  6610. //char fname[60]={0};
  6611. while(i < ftppathlen)
  6612. {
  6613. int len=ftppathlen-i;
  6614. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6615. {
  6616. printf("compare '/' all right\n");
  6617. break;
  6618. }
  6619. i=i+1;
  6620. }
  6621. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6622. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6623. fnamePWithNoPath[i+1] = '\0';
  6624. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6625. {
  6626. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6627. {
  6628. fnamePWithNoPath[j]='\0';
  6629. }
  6630. }
  6631. FILE* fp1 = fopen(fnamePlusPath, "r");
  6632. if (fp1)
  6633. {
  6634. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6635. // file exists
  6636. fclose(fp1);
  6637. }
  6638. else
  6639. {
  6640. // file doesn't exist
  6641. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6642. }
  6643. }
  6644. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6645. {
  6646. mtrace();
  6647. int result = FAIL;
  6648. char cmdBuf[512];
  6649. char fName[258];
  6650. time_t CurrentTime;
  6651. struct tm *tm;
  6652. system("/usr/bin/run_tmate_restart.sh");
  6653. pthread_t th_Status;
  6654. CurrentTime = time(NULL);
  6655. tm = localtime(&CurrentTime);
  6656. 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);
  6657. sendGetDiagnosticsConfirmation(uuid, fName);
  6658. system("exec /root/logPackTools 'log' 6");
  6659. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", fName);
  6660. system(cmdBuf);
  6661. checkUploadLog();
  6662. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6663. return result;
  6664. }
  6665. void* GetDiagnosticsProcess(void* data)
  6666. {
  6667. pthread_detach(pthread_self());
  6668. mtrace();
  6669. int retriesInt=0, retryIntervalInt=0;
  6670. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6671. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6672. 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};
  6673. int port=0;
  6674. char sstr[260]={ 0 };
  6675. int c = 0;
  6676. char *loc;
  6677. int isSuccess = FALSE;
  6678. char ftpbuf[200]={0};
  6679. char * pch;
  6680. char str[300]={ 0 };
  6681. strcpy(str,(const char*)data);
  6682. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6683. DEBUG_INFO("GetDiagnosticsProcess...%s\n", str);
  6684. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6685. //****************location*******************/
  6686. c = 0;
  6687. memset(sstr ,0, ARRAY_SIZE(sstr));
  6688. loc = strstr(str, "location");
  6689. while (loc[3+strlen("location")+c] != '\"')
  6690. {
  6691. sstr[c] = loc[3+strlen("location")+c];
  6692. c++;
  6693. }
  6694. sstr[c] = '\0';
  6695. strcpy(locationstr,sstr);
  6696. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6697. if(strcmp(locationstr,"")==0)
  6698. {
  6699. DEBUG_INFO("location is <Empty>!\n");
  6700. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6701. goto end;
  6702. }
  6703. //****************retries*******************/
  6704. c = 0;
  6705. loc = strstr(str, "retries");
  6706. if(loc == NULL)
  6707. {
  6708. retriesIsNULL = TRUE;
  6709. }
  6710. else
  6711. {
  6712. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6713. {
  6714. sstr[c] = loc[strlen("retries")+2+c];
  6715. c++;
  6716. }
  6717. sstr[c] = '\0';
  6718. retriesInt = atoi(sstr);
  6719. }
  6720. if(retriesIsNULL == TRUE)
  6721. {
  6722. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6723. }
  6724. //****************retryInterval*******************/
  6725. c = 0;
  6726. loc = strstr(str, "retryInterval");
  6727. if(loc == NULL)
  6728. {
  6729. retryIntervalIsNULL = TRUE;
  6730. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6731. }
  6732. else
  6733. {
  6734. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6735. {
  6736. sstr[c] = loc[strlen("retryInterval")+2+c];
  6737. c++;
  6738. }
  6739. sstr[c] = '\0';
  6740. retryIntervalInt = atoi(sstr);
  6741. }
  6742. //****************startTime*******************/
  6743. c = 0;
  6744. memset(sstr ,0, ARRAY_SIZE(sstr));
  6745. loc = strstr(str, "startTime");
  6746. if(loc == NULL)
  6747. {
  6748. startTimeIsNULL = TRUE;
  6749. }
  6750. else
  6751. {
  6752. while (loc[3+strlen("startTime")+c] != '\"')
  6753. {
  6754. sstr[c] = loc[3+strlen("startTime")+c];
  6755. c++;
  6756. }
  6757. sstr[c] = '\0';
  6758. strcpy(startTimestr,sstr);
  6759. }
  6760. //****************stopTime*******************/
  6761. c = 0;
  6762. memset(sstr ,0, ARRAY_SIZE(sstr));
  6763. loc = strstr(str, "stopTime");
  6764. if(loc == NULL)
  6765. {
  6766. stopTimeIsNULL = TRUE;
  6767. }
  6768. else
  6769. {
  6770. while (loc[3+strlen("stopTime")+c] != '\"')
  6771. {
  6772. sstr[c] = loc[3+strlen("stopTime")+c];
  6773. c++;
  6774. }
  6775. sstr[c] = '\0';
  6776. strcpy(stopTimestr,sstr);
  6777. }
  6778. memset(protocol, 0, ARRAY_SIZE(protocol));
  6779. memset(user, 0, ARRAY_SIZE(user) );
  6780. memset(password, 0, ARRAY_SIZE(password));
  6781. memset(host, 0, ARRAY_SIZE(host));
  6782. memset(path, 0, ARRAY_SIZE(path));
  6783. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  6784. memset(host1, 0, ARRAY_SIZE(host1));
  6785. memset(path1, 0, ARRAY_SIZE(path1));
  6786. /*location: ftp://user:password@host:port/path*/
  6787. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6788. if((access(fnamePlusPath,F_OK))!=-1)
  6789. {
  6790. DEBUG_INFO("fnamePlusPath exist.\n");
  6791. }
  6792. else
  6793. {
  6794. DEBUG_INFO("fnamePlusPath not exist!\n");
  6795. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6796. goto end;
  6797. }
  6798. pch=strchr(locationstr,'@');
  6799. if(pch==NULL)
  6800. {
  6801. sscanf(locationstr,
  6802. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6803. protocol, host, &port, path);
  6804. strcpy(user,"anonymous");
  6805. strcpy(password,"");
  6806. }
  6807. else
  6808. {
  6809. //DEBUG_INFO("pch=%s\n", pch);
  6810. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6811. protocol, user, password, host, &port, path);
  6812. }
  6813. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6814. {
  6815. DEBUG_INFO("protocol is not ftp/http ! \n");
  6816. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6817. goto end;
  6818. }
  6819. if(strncmp(locationstr,"http", 4) == 0)
  6820. {
  6821. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6822. sprintf(ftppath,"/%s", path);
  6823. do{
  6824. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6825. sleep(retryIntervalInt);
  6826. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6827. if(!isSuccess)
  6828. {
  6829. DEBUG_INFO("Diagnostics fail.\n");
  6830. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6831. }
  6832. else
  6833. {
  6834. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6835. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6836. }
  6837. }
  6838. else
  6839. {
  6840. sscanf(host,"%[^/]%s",host1, path1);
  6841. sprintf(ftppath,"%s", path1);
  6842. int ftppathlen=strlen(ftppath);
  6843. int i=1;
  6844. char filenametemp[50];
  6845. while(i < ftppathlen)
  6846. {
  6847. int len=ftppathlen-i;
  6848. if(ftppath[len]== 47) // '/' ascll code: 47
  6849. {
  6850. DEBUG_INFO("find '/' all right\n");
  6851. break;
  6852. }
  6853. i=i+1;
  6854. }
  6855. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  6856. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6857. filenametemp[i+1] = 0;
  6858. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  6859. if(port == 0)
  6860. port = 21;
  6861. do{
  6862. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6863. sleep(retryIntervalInt);
  6864. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6865. if(!isSuccess)
  6866. {
  6867. DEBUG_INFO("Diagnostics fail.\n");
  6868. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6869. }
  6870. else
  6871. {
  6872. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6873. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6874. }
  6875. }
  6876. end:
  6877. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  6878. pthread_exit(NULL);
  6879. }
  6880. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6881. {
  6882. mtrace();
  6883. int result = FAIL;
  6884. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6885. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6886. {
  6887. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6888. localversion = -1;
  6889. }
  6890. else
  6891. {
  6892. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6893. OCPP_getListVerion();
  6894. }
  6895. //from db.OCPP_getListVerion
  6896. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6897. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6898. sendGetLocalListVersionConfirmation(uuid,"");
  6899. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6900. return result;
  6901. }
  6902. int handleRemoteStartRequest(char *uuid, char *payload)
  6903. {
  6904. mtrace();
  6905. int result = FAIL;
  6906. int connectorIdInt=0;
  6907. int tempIndex = 0;
  6908. int connectorIdIsNULL, chargingProfileIsNULL;
  6909. char comfirmstr[20]={0};
  6910. char cmdBuf[512];
  6911. json_object *RemoteStartTransaction;
  6912. FILE *fp;
  6913. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6914. if(server_pending == TRUE)
  6915. {
  6916. return 0;
  6917. }
  6918. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  6919. RemoteStartTransaction = json_tokener_parse(payload);
  6920. if(!is_error(RemoteStartTransaction))
  6921. {
  6922. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  6923. {
  6924. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  6925. if(connectorIdInt <= gunTotalNumber)
  6926. {
  6927. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  6928. // Required data
  6929. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  6930. // Optional data
  6931. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  6932. {
  6933. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  6934. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  6935. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  6936. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  6937. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  6938. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  6939. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  6940. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  6941. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  6942. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  6943. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  6944. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  6945. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  6946. {
  6947. 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")));
  6948. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  6949. 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"));
  6950. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  6951. 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"));
  6952. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  6953. 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")));
  6954. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  6955. {
  6956. 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++)
  6957. {
  6958. 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"));
  6959. 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"));
  6960. 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)
  6961. 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"));
  6962. }
  6963. }
  6964. }
  6965. }
  6966. else
  6967. chargingProfileIsNULL = TRUE;
  6968. }
  6969. }
  6970. else
  6971. connectorIdIsNULL = TRUE;
  6972. }
  6973. else
  6974. connectorIdIsNULL = TRUE;
  6975. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6976. {
  6977. DEBUG_WARN("Connector id is NULL\n.");
  6978. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6979. goto end;
  6980. }
  6981. /*
  6982. enum _SYSTEM_STATUS
  6983. {
  6984. S_BOOTING = 0,
  6985. S_IDLE, = 1
  6986. S_AUTHORIZING, = 2
  6987. S_REASSIGN_CHECK, = 3
  6988. S_REASSIGN, = 4
  6989. S_PRECHARGE, = 5
  6990. S_PREPARING_FOR_EV, = 6
  6991. S_PREPARING_FOR_EVSE, = 7
  6992. S_CHARGING, = 8
  6993. S_TERMINATING, = 9
  6994. S_COMPLETE, = 10
  6995. S_ALARM, = 11
  6996. S_FAULT = 12
  6997. }
  6998. */
  6999. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  7000. {
  7001. //check Transaction active
  7002. if(gunType[connectorIdInt -1] == 'J')
  7003. {
  7004. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7005. {
  7006. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7007. }
  7008. else
  7009. {
  7010. tempIndex = connectorIdInt -1;
  7011. }
  7012. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7013. {
  7014. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7015. {
  7016. 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))
  7017. {
  7018. //Reserved
  7019. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7020. }
  7021. 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))
  7022. {
  7023. //Reserved
  7024. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7025. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7026. goto end;
  7027. }
  7028. else
  7029. {
  7030. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7031. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7032. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7033. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7034. {
  7035. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  7036. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7037. goto end;
  7038. }
  7039. }//END FOR ELSE
  7040. }
  7041. }// END FOR CHAdeMO_QUANTITY
  7042. }
  7043. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7044. {
  7045. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7046. {
  7047. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7048. }
  7049. else
  7050. {
  7051. tempIndex = connectorIdInt -1;
  7052. }
  7053. for (int index = 0; index < CCS_QUANTITY; index++)
  7054. {
  7055. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7056. {
  7057. 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))
  7058. {
  7059. //Reserved
  7060. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7061. }
  7062. 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))
  7063. {
  7064. //Reserved
  7065. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7066. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7067. goto end;
  7068. }
  7069. else
  7070. {
  7071. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7072. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7073. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7074. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7075. {
  7076. DEBUG_WARN("CCS connector not allow start\n.");
  7077. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7078. goto end;
  7079. }
  7080. }// END FOR ELSE
  7081. }
  7082. }// END FOR CCS_QUANTITY
  7083. }
  7084. else if(gunType[connectorIdInt -1] == 'G')
  7085. {
  7086. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7087. {
  7088. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7089. }
  7090. else
  7091. {
  7092. tempIndex = connectorIdInt -1;
  7093. }
  7094. for (int index = 0; index < GB_QUANTITY; index++)
  7095. {
  7096. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7097. {
  7098. 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))
  7099. {
  7100. //Reserved
  7101. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7102. }
  7103. 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))
  7104. {
  7105. //Reserved
  7106. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7107. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7108. goto end;
  7109. }
  7110. else
  7111. {
  7112. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7113. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7114. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7115. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7116. {
  7117. DEBUG_WARN("GB connector not allow start\n.");
  7118. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7119. goto end;
  7120. }
  7121. }// END FOR ELSE
  7122. }
  7123. } // END FOR GB_QUANTITY
  7124. }
  7125. else
  7126. {
  7127. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7128. {
  7129. tempIndex = 2;
  7130. }
  7131. else
  7132. {
  7133. tempIndex = connectorIdInt -1;
  7134. }
  7135. for (int index = 0; index < AC_QUANTITY; index++)
  7136. {
  7137. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7138. {
  7139. 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))
  7140. {
  7141. //Reserved
  7142. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7143. }
  7144. 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))
  7145. {
  7146. //Reserved
  7147. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7148. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7149. goto end;
  7150. }
  7151. else
  7152. {
  7153. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7154. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7155. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7156. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7157. {
  7158. DEBUG_WARN("AC connector not allow start\n.");
  7159. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7160. goto end;
  7161. }
  7162. }//END FOR ELSE
  7163. }
  7164. }// END FOR AC_QUANTITY
  7165. }
  7166. if(chargingProfileIsNULL == FALSE)
  7167. {
  7168. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7169. {
  7170. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7171. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7172. //memset idTag
  7173. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7174. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7175. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7176. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7177. // Save profile to file
  7178. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7179. system(cmdBuf);
  7180. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7181. fp = fopen(cmdBuf, "w");
  7182. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string(json_object_object_get(RemoteStartTransaction, "chargingProfile")));
  7183. fclose(fp);
  7184. }
  7185. else
  7186. {
  7187. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7188. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7189. }
  7190. }
  7191. else
  7192. {
  7193. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7194. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7195. //memset idTag
  7196. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7197. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7198. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7199. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7200. }
  7201. }
  7202. else
  7203. {
  7204. DEBUG_WARN("Connector id over\n.");
  7205. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7206. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7207. }
  7208. end:
  7209. json_object_put(RemoteStartTransaction);
  7210. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  7211. {
  7212. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7213. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7214. }
  7215. //OCPP send RemoteStartConfirmation by first.
  7216. sendRemoteStartConfirmation(uuid, comfirmstr);
  7217. return result;
  7218. }
  7219. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7220. {
  7221. mtrace();
  7222. int result = FAIL;
  7223. int match = FALSE;
  7224. int GunNO = 0;
  7225. int tempIndex = 0;
  7226. int transactionIdInt=0;
  7227. int transactionIdIsNULL= TRUE;
  7228. char comfirmstr[20];
  7229. json_object *RemoteStopTransaction;
  7230. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7231. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7232. if(server_pending == TRUE)
  7233. {
  7234. return 0;
  7235. }
  7236. RemoteStopTransaction = json_tokener_parse(payload);
  7237. if(!is_error(RemoteStopTransaction))
  7238. {
  7239. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  7240. {
  7241. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  7242. transactionIdIsNULL = FALSE;
  7243. }
  7244. }
  7245. json_object_put(RemoteStopTransaction);
  7246. if(transactionIdIsNULL == FALSE)
  7247. {
  7248. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7249. {
  7250. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7251. {
  7252. //check Transaction active
  7253. if(gunType[gun_index] == 'J')
  7254. {
  7255. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7256. {
  7257. tempIndex = ((gun_index==2) ? 1: 0);
  7258. }
  7259. else
  7260. {
  7261. tempIndex = gun_index;
  7262. }
  7263. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7264. {
  7265. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7266. {
  7267. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7268. {
  7269. match = TRUE;
  7270. GunNO = gun_index;
  7271. }
  7272. }
  7273. }// END FOR CHAdeMO_QUANTITY
  7274. }
  7275. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7276. {
  7277. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7278. {
  7279. tempIndex = ((gun_index==2) ? 1: 0);
  7280. }
  7281. else
  7282. {
  7283. tempIndex = gun_index;
  7284. }
  7285. for (int index = 0; index < CCS_QUANTITY; index++)
  7286. {
  7287. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7288. {
  7289. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7290. {
  7291. match = TRUE;
  7292. GunNO = gun_index;
  7293. }
  7294. }
  7295. }// END FOR CCS_QUANTITY
  7296. }
  7297. else if(gunType[gun_index] == 'G')
  7298. {
  7299. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7300. {
  7301. tempIndex = ((gun_index==2) ? 1: 0);
  7302. }
  7303. else
  7304. {
  7305. tempIndex = gun_index;
  7306. }
  7307. for (int index = 0; index < GB_QUANTITY; index++)
  7308. {
  7309. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7310. {
  7311. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7312. {
  7313. match = TRUE;
  7314. GunNO = gun_index;
  7315. }
  7316. }
  7317. }// END FOR GB_QUANTITY
  7318. }
  7319. else
  7320. {
  7321. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7322. {
  7323. tempIndex = 2;
  7324. }
  7325. else
  7326. {
  7327. tempIndex = gun_index;
  7328. }
  7329. for (int index = 0; index < AC_QUANTITY; index++)
  7330. {
  7331. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7332. {
  7333. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7334. {
  7335. match = TRUE;
  7336. GunNO = gun_index;
  7337. }
  7338. }
  7339. }// END FOR CHAdeMO_QUANTITY
  7340. } // END FOR AC ELSE
  7341. }// CHECK IF ResponseTransactionId == transactionIdInt
  7342. }//END FOR
  7343. if( match == TRUE)
  7344. {
  7345. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7346. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7347. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7348. }
  7349. else
  7350. {
  7351. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7352. }
  7353. }
  7354. else
  7355. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7356. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7357. return result;
  7358. }
  7359. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7360. {
  7361. mtrace();
  7362. int result = FAIL;
  7363. int connectorIdInt=0, reservationIdInt=0;
  7364. int tempIndex = 0;
  7365. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7366. char comfirmstr[20]={0};
  7367. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7368. int c = 0;
  7369. char *loc;
  7370. //char *ptr;
  7371. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7372. strcpy(sstrtemp, stringtrimspace(payload));
  7373. //***(1)connectorId ****/
  7374. c=0;
  7375. loc = strstr(sstrtemp, "connectorId");
  7376. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7377. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7378. {
  7379. sstr[c] = loc[strlen("connectorId")+2+c];
  7380. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7381. c++;
  7382. }
  7383. sstr[c] = '\0';
  7384. connectorIdInt = atoi(sstr);
  7385. //***(2)expiryDate ****/
  7386. loc = strstr(sstrtemp, "expiryDate");
  7387. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7388. c = 0;
  7389. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7390. {
  7391. sstr[c] = loc[3+strlen("expiryDate")+c];
  7392. c++;
  7393. }
  7394. sstr[c] = '\0';
  7395. strcpy(expiryDatestr, sstr);
  7396. //***(3)idTag ****/
  7397. loc = strstr(sstrtemp, "idTag");
  7398. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7399. c = 0;
  7400. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7401. {
  7402. sstr[c] = loc[3+strlen("idTag")+c];
  7403. c++;
  7404. }
  7405. sstr[c] = '\0';
  7406. strcpy(idTagstr, sstr);
  7407. //***(4)parentIdTag ****/
  7408. loc = strstr(sstrtemp, "parentIdTag");
  7409. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7410. c = 0;
  7411. if(loc == NULL)
  7412. {
  7413. strcpy(parentIdTagstr, "");
  7414. }
  7415. else
  7416. {
  7417. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7418. {
  7419. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7420. c++;
  7421. }
  7422. sstr[c] = '\0';
  7423. strcpy(parentIdTagstr, sstr);
  7424. }
  7425. //***(5)reservationId ****/
  7426. c=0;
  7427. loc = strstr(sstrtemp, "reservationId");
  7428. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7429. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7430. {
  7431. sstr[c] = loc[strlen("reservationId")+2+c];
  7432. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7433. c++;
  7434. }
  7435. sstr[c] = '\0';
  7436. reservationIdInt = atoi(sstr);
  7437. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7438. /*
  7439. enum SYSTEM_STATUS
  7440. {
  7441. SYS_MODE_BOOTING = 0,
  7442. SYS_MODE_IDLE = 1,
  7443. SYS_MODE_AUTHORIZING = 2,
  7444. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7445. SYS_MODE_REASSIGN = 4,
  7446. SYS_MODE_PREPARING = 5,
  7447. SYS_MODE_PREPARE_FOR_EV = 6,
  7448. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7449. SYS_MODE_CHARGING = 8,
  7450. SYS_MODE_TERMINATING = 9,
  7451. SYS_MODE_COMPLETE = 10,
  7452. SYS_MODE_ALARM = 11,
  7453. SYS_MODE_FAULT = 12,
  7454. SYS_MODE_RESERVATION = 13,
  7455. SYS_MODE_BOOKING = 14,
  7456. SYS_MODE_MAINTAIN = 15,
  7457. SYS_MODE_DEBUG = 16,
  7458. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7459. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7460. SYS_MODE_UPDATE = 19
  7461. };
  7462. */
  7463. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7464. {
  7465. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7466. goto end;
  7467. }
  7468. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7469. {
  7470. //check Transaction active
  7471. if(gunType[connectorIdInt -1] == 'J')
  7472. {
  7473. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7474. {
  7475. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7476. }
  7477. else
  7478. {
  7479. tempIndex = connectorIdInt -1;
  7480. }
  7481. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7482. {
  7483. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7484. {
  7485. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7486. {
  7487. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7488. {
  7489. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7490. {
  7491. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7492. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7493. }
  7494. 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'))
  7495. {
  7496. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7497. }
  7498. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7499. {
  7500. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7501. }
  7502. else
  7503. {
  7504. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7505. }
  7506. }
  7507. 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
  7508. {
  7509. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7510. }
  7511. }
  7512. else
  7513. {
  7514. //replace reservation
  7515. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7516. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7517. }
  7518. }
  7519. } // END FOR CHAdeMO_QUANTITY
  7520. }
  7521. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7522. {
  7523. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7524. {
  7525. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7526. }
  7527. else
  7528. {
  7529. tempIndex = connectorIdInt -1;
  7530. }
  7531. for (int index = 0; index < CCS_QUANTITY; index++)
  7532. {
  7533. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7534. {
  7535. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7536. {
  7537. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7538. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7539. {
  7540. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7541. {
  7542. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7543. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7544. }
  7545. 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'))
  7546. {
  7547. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7548. }
  7549. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7550. {
  7551. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7552. }
  7553. else
  7554. {
  7555. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7556. }
  7557. }
  7558. 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
  7559. {
  7560. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7561. }
  7562. }
  7563. else
  7564. {
  7565. //replace reservation
  7566. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7567. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7568. }
  7569. }
  7570. } // END FOR CCS_QUANTITY
  7571. }
  7572. else if(gunType[connectorIdInt -1] == 'G')
  7573. {
  7574. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7575. {
  7576. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7577. }
  7578. else
  7579. {
  7580. tempIndex = connectorIdInt -1;
  7581. }
  7582. for (int index = 0; index < GB_QUANTITY; index++)
  7583. {
  7584. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7585. {
  7586. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7587. {
  7588. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7589. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7590. {
  7591. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7592. {
  7593. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7594. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7595. }
  7596. 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'))
  7597. {
  7598. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7599. }
  7600. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7601. {
  7602. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7603. }
  7604. else
  7605. {
  7606. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7607. }
  7608. }
  7609. 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
  7610. {
  7611. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7612. }
  7613. }
  7614. else
  7615. {
  7616. //replace reservation
  7617. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7618. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7619. }
  7620. }
  7621. }// END FOR GB_QUANTITY
  7622. }
  7623. else
  7624. {
  7625. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7626. {
  7627. tempIndex = 2;
  7628. }
  7629. else
  7630. {
  7631. tempIndex = (connectorIdInt -1);
  7632. }
  7633. for (int index = 0; index < AC_QUANTITY; index++)
  7634. {
  7635. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7636. {
  7637. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7638. {
  7639. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7640. {
  7641. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7642. {
  7643. 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))
  7644. {
  7645. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7646. }
  7647. else
  7648. {
  7649. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7650. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7651. }
  7652. }
  7653. 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'))
  7654. {
  7655. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7656. }
  7657. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7658. {
  7659. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7660. }
  7661. else
  7662. {
  7663. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7664. }
  7665. }
  7666. 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
  7667. {
  7668. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7669. }
  7670. }
  7671. else
  7672. {
  7673. //replace reservation
  7674. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7675. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7676. }
  7677. }
  7678. } // END FOR AC_QUANTITY
  7679. }
  7680. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7681. }
  7682. else if(connectorIdInt == 0)
  7683. {
  7684. //check Transaction active
  7685. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7686. {
  7687. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7688. {
  7689. 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'))
  7690. {
  7691. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7692. goto end;
  7693. }
  7694. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7695. {
  7696. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7697. goto end;
  7698. }
  7699. 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
  7700. {
  7701. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7702. goto end;
  7703. }
  7704. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7705. {
  7706. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7707. goto end;
  7708. }
  7709. }
  7710. }// END FOR CHAdeMO_QUANTITY
  7711. for (int index = 0; index < CCS_QUANTITY; index++)
  7712. {
  7713. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7714. {
  7715. 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'))
  7716. {
  7717. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7718. goto end;
  7719. }
  7720. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7721. {
  7722. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7723. goto end;
  7724. }
  7725. 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
  7726. {
  7727. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7728. goto end;
  7729. }
  7730. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7731. {
  7732. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7733. goto end;
  7734. }
  7735. }
  7736. } // END FOR CCS_QUANTITY
  7737. for (int index = 0; index < GB_QUANTITY; index++)
  7738. {
  7739. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7740. {
  7741. 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'))
  7742. {
  7743. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7744. goto end;
  7745. }
  7746. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7747. {
  7748. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7749. goto end;
  7750. }
  7751. 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
  7752. {
  7753. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7754. goto end;
  7755. }
  7756. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7757. {
  7758. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7759. goto end;
  7760. }
  7761. }
  7762. } // END FOR GB_QUANTITY
  7763. for (int index = 0; index < AC_QUANTITY; index++)
  7764. {
  7765. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7766. {
  7767. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  7768. {
  7769. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7770. goto end;
  7771. }
  7772. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7773. {
  7774. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7775. goto end;
  7776. }
  7777. 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
  7778. {
  7779. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7780. goto end;
  7781. }
  7782. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7783. {
  7784. 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))
  7785. {
  7786. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7787. goto end;
  7788. }
  7789. }
  7790. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7791. {
  7792. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7793. goto end;
  7794. }
  7795. }
  7796. }// END FOR AC_QUANTITY
  7797. //The connectorId is 0
  7798. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7799. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7800. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7801. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7802. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7803. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7804. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7805. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7806. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7807. result = TRUE;
  7808. return result;
  7809. }
  7810. else
  7811. {
  7812. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7813. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7814. }
  7815. if(strcmp(comfirmstr,"Accepted") == 0)
  7816. {
  7817. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7818. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7819. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7820. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7821. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7822. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7823. result = TRUE;
  7824. return result;
  7825. }
  7826. end:
  7827. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7828. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7829. return result;
  7830. }
  7831. int handleResetRequest(char *uuid, char *payload)
  7832. {
  7833. mtrace();
  7834. int result = FAIL;
  7835. char sstr[10]={0},sstrtemp[30]={ 0 };
  7836. char typestr[10]={0};
  7837. char comfirmstr[20]={0};
  7838. int c = 0;
  7839. char *loc;
  7840. DEBUG_INFO("handleResetRequest...\n");
  7841. strcpy(sstrtemp, stringtrimspace(payload));
  7842. loc = strstr(sstrtemp, "type");
  7843. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7844. c = 0;
  7845. while (loc[3+strlen("type")+c] != '\"')
  7846. {
  7847. sstr[c] = loc[3+strlen("type")+c];
  7848. c++;
  7849. }
  7850. sstr[c] = '\0';
  7851. strcpy(typestr,sstr);
  7852. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7853. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7854. {
  7855. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7856. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7857. result = TRUE;
  7858. return result;
  7859. }
  7860. else
  7861. {
  7862. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7863. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7864. goto errorend;
  7865. }
  7866. errorend:
  7867. sendResetConfirmation(uuid, comfirmstr);
  7868. return result;
  7869. }
  7870. int handleSendLocalListRequest(char *uuid, char *payload)
  7871. {
  7872. mtrace();
  7873. int result = FAIL;
  7874. int listVersionInt;
  7875. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7876. char listsearch[]="listVersion";
  7877. char updateTypesearch[]="updateType";
  7878. char localAuthorizationListsearch[]="localAuthorizationList";
  7879. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7880. char CardList[500][160]={0};
  7881. char updateTypestr[15]={0};
  7882. char idTagstr[20]={0};
  7883. char parentIdTag[20]={0};
  7884. char expiryDate[30]={0};
  7885. char idTagstatus[16]={0};
  7886. int c = 0;
  7887. int i = 0;
  7888. char *delim1 = "}";
  7889. char * pch;
  7890. char *loc;
  7891. //char *ptr;
  7892. char comfirmstr[20];
  7893. //int n_localAuthorizations = 0;
  7894. int checkState_Faulted = FALSE;
  7895. DEBUG_INFO("handleSendLocalListRequest...\n");
  7896. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7897. {
  7898. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7899. goto end;
  7900. }
  7901. //check Charge Point state
  7902. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7903. {
  7904. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7905. {
  7906. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7907. }
  7908. }
  7909. for (int index = 0; index < CCS_QUANTITY; index++)
  7910. {
  7911. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7912. {
  7913. checkState_Faulted = TRUE; //OCPP Status
  7914. }
  7915. }
  7916. for (int index = 0; index < GB_QUANTITY; index++)
  7917. {
  7918. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7919. {
  7920. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7921. }
  7922. }
  7923. //check Charge Point state
  7924. for (int index = 0; index < AC_QUANTITY; index++)
  7925. {
  7926. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7927. {
  7928. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7929. }
  7930. }
  7931. if(checkState_Faulted == TRUE)
  7932. {
  7933. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7934. goto end;
  7935. }
  7936. //Filter payload space
  7937. strcpy(sstrtemp, stringtrimspace(payload));
  7938. //listVersion
  7939. c = 0;
  7940. loc = strstr(sstrtemp, listsearch);
  7941. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7942. {
  7943. sstr[c] = loc[strlen("listVersion")+2+c];
  7944. c++;
  7945. }
  7946. sstr[c] = '\0';
  7947. listVersionInt = atoi(sstr);
  7948. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7949. //updateType
  7950. loc = strstr(sstrtemp, updateTypesearch);
  7951. c = 0;
  7952. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7953. {
  7954. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7955. c++;
  7956. }
  7957. sstr[c] = '\0';
  7958. strcpy(updateTypestr, sstr);
  7959. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7960. //localAuthorizationList
  7961. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7962. loc = strstr(sstrtemp, localAuthorizationListsearch);
  7963. if(loc != NULL) // localAuthorizationList is not NULL
  7964. {
  7965. //Check UpdateType
  7966. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7967. {
  7968. //Local list full update
  7969. printf("Local list full update.\n");
  7970. OCPP_getListVerion();
  7971. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7972. {
  7973. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7974. goto end;
  7975. }
  7976. OCPP_cleanLocalList();
  7977. }
  7978. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7979. {
  7980. //Local list different update
  7981. printf("Local list different update.\n");
  7982. OCPP_getListVerion();
  7983. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7984. {
  7985. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7986. goto end;
  7987. }
  7988. }
  7989. else
  7990. {
  7991. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7992. goto end;
  7993. }
  7994. c = 0;
  7995. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7996. {
  7997. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7998. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7999. c++;
  8000. }
  8001. sstr[c] = '\0';
  8002. //DEBUG_INFO("sstr=%s\n", sstr);
  8003. //parsing strings to words
  8004. i = 0;
  8005. pch = strtok(sstr,delim1);
  8006. while (pch != NULL)
  8007. {
  8008. strcpy(CardList[i], pch);
  8009. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8010. pch = strtok (NULL, delim1);
  8011. i = i + 1;
  8012. }
  8013. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8014. //local Authorizations List Numbers
  8015. //n_localAuthorizations = i;
  8016. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8017. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8018. c= 0;
  8019. while(c < i) // i is CardList Number
  8020. {
  8021. //Search "IdToken"
  8022. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8023. loc = strstr(CardList[c], "idTag");
  8024. int j = 0;
  8025. while (loc[3+strlen("idTag")+j] != '\"')
  8026. {
  8027. sstr[j] = loc[3+strlen("idTag")+j];
  8028. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8029. j++;
  8030. }
  8031. sstr[j] = '\0';
  8032. strcpy(idTagstr, sstr);
  8033. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8034. //Search "expiryDate"
  8035. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8036. loc = strstr(CardList[c], "expiryDate");
  8037. j = 0;
  8038. if(loc != NULL)
  8039. {
  8040. while (loc[3+strlen("expiryDate")+j] != '\"')
  8041. {
  8042. sstr[j] = loc[3+strlen("expiryDate")+j];
  8043. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8044. j++;
  8045. }
  8046. sstr[j] = '\0';
  8047. strcpy(expiryDate, sstr);
  8048. }
  8049. else
  8050. {
  8051. strcpy(expiryDate, "");
  8052. }
  8053. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8054. //Search "parentIdTag"
  8055. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8056. loc = strstr(CardList[c], "parentIdTag");
  8057. j = 0;
  8058. if(loc != NULL)
  8059. {
  8060. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8061. {
  8062. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8063. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8064. j++;
  8065. }
  8066. sstr[j] = '\0';
  8067. strcpy(parentIdTag, sstr);
  8068. }
  8069. else
  8070. {
  8071. strcpy(parentIdTag, "");
  8072. }
  8073. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8074. //Search "status"
  8075. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8076. loc = strstr(CardList[c], "status");
  8077. j = 0;
  8078. while (loc[3+strlen("status")+j] != '\"')
  8079. {
  8080. sstr[j] = loc[3+strlen("status")+j];
  8081. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8082. j++;
  8083. }
  8084. sstr[j] = '\0';
  8085. strcpy(idTagstatus, sstr);
  8086. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8087. OCPP_getIdTag(idTagstr);
  8088. //OCPP_getIdTag("test"); For Test
  8089. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8090. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8091. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8092. {
  8093. //Local list full update
  8094. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8095. // update list
  8096. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8097. //DEBUG_INFO("Local list full update. 1\n");
  8098. //OCPP_get_TableAuthlocalAllData();
  8099. //DEBUG_INFO("Local list full update. 2\n");
  8100. }
  8101. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8102. {
  8103. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8104. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8105. }
  8106. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8107. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8108. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8109. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8110. c++;
  8111. }
  8112. }
  8113. else
  8114. {
  8115. //Check UpdateType
  8116. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8117. {
  8118. //Local list full update
  8119. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8120. OCPP_cleanLocalList();
  8121. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8122. goto end;
  8123. }
  8124. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8125. {
  8126. //Local list different update
  8127. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8128. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8129. goto end;
  8130. }
  8131. }
  8132. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8133. end:
  8134. sendSendLocalListConfirmation(uuid, comfirmstr);
  8135. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8136. return result;
  8137. }
  8138. #define MAX 200
  8139. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8140. {
  8141. mtrace();
  8142. int result = FAIL;
  8143. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8144. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8145. char chargingProfilePurposeStr[30]={0};
  8146. char chargingProfileKindStr[16]={0};
  8147. char recurrencyKindStr[10]={0};
  8148. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8149. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8150. int chargingSchedulePeriodCount = 0;
  8151. //int updateflag = FALSE;
  8152. char comfirmstr[20]={0};
  8153. int meet= FALSE;
  8154. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8155. int c = 0;
  8156. char *loc;
  8157. FILE *fptr1;//, *fptr2;
  8158. //int lno=0;//, linectr = 0;
  8159. //int modifyflag = FALSE;
  8160. char filename[MAX]={0};
  8161. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8162. //int resultRename=0;
  8163. char rmFileCmd[50]={0};
  8164. char tempchargingProfilePurposeStr[30]={0};
  8165. char word[1600]={0};
  8166. int n_chargingProfile = 0;
  8167. //[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}}}]
  8168. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8169. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8170. //Filter string space
  8171. strcpy(sstrtemp, stringtrimspace(payload));
  8172. //*********************connectorId***************************/
  8173. loc = strstr(sstrtemp, "connectorId");
  8174. c = 0;
  8175. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8176. while (loc[strlen("connectorId")+2+c] != ',')
  8177. {
  8178. sstr[c] = loc[strlen("connectorId")+2+c];
  8179. c++;
  8180. }
  8181. sstr[c] = '\0';
  8182. connectorIdInt = atoi(sstr);
  8183. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8184. {
  8185. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8186. }
  8187. else
  8188. {
  8189. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8190. }
  8191. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8192. //*********************chargingProfileId***************************/
  8193. loc = strstr(sstrtemp, "chargingProfileId");
  8194. c = 0;
  8195. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8196. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8197. {
  8198. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8199. c++;
  8200. }
  8201. sstr[c] = '\0';
  8202. chargingProfileIdInt = atoi(sstr);
  8203. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8204. {
  8205. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8206. }
  8207. else
  8208. {
  8209. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8210. }
  8211. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8212. //*********************transactionId***************************/
  8213. loc = strstr(sstrtemp, "transactionId");
  8214. if(loc != NULL)
  8215. {
  8216. c = 0;
  8217. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8218. while (loc[strlen("transactionId")+2+c] != ',')
  8219. {
  8220. sstr[c] = loc[strlen("transactionId")+2+c];
  8221. c++;
  8222. }
  8223. sstr[c] = '\0';
  8224. transactionIdInt = atoi(sstr);
  8225. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8226. {
  8227. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8228. }
  8229. else
  8230. {
  8231. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8232. }
  8233. }
  8234. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8235. //*********************stackLevel***************************/
  8236. loc = strstr(sstrtemp, "stackLevel");
  8237. c = 0;
  8238. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8239. while (loc[strlen("stackLevel")+2+c] != ',')
  8240. {
  8241. sstr[c] = loc[strlen("stackLevel")+2+c];
  8242. c++;
  8243. }
  8244. sstr[c] = '\0';
  8245. stackLevelInt = atoi(sstr);
  8246. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8247. {
  8248. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8249. }
  8250. else
  8251. {
  8252. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8253. }
  8254. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8255. //*********************chargingProfilePurpose***************************/
  8256. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8257. c = 0;
  8258. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8259. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8260. {
  8261. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8262. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8263. c++;
  8264. }
  8265. sstr[c] = '\0';
  8266. strcpy(chargingProfilePurposeStr,sstr);
  8267. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8268. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8269. {
  8270. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8271. }
  8272. else
  8273. {
  8274. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8275. }
  8276. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8277. //*********************chargingProfileKind***************************/
  8278. loc = strstr(sstrtemp, "chargingProfileKind");
  8279. c = 0;
  8280. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8281. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8282. {
  8283. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8284. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8285. c++;
  8286. }
  8287. sstr[c] = '\0';
  8288. strcpy(chargingProfileKindStr,sstr);
  8289. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8290. {
  8291. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8292. }
  8293. else
  8294. {
  8295. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8296. }
  8297. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8298. //*********************recurrencyKind***************************/
  8299. loc = strstr(sstrtemp, "recurrencyKind");
  8300. if(loc != NULL)
  8301. {
  8302. c = 0;
  8303. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8304. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8305. {
  8306. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8307. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8308. c++;
  8309. }
  8310. sstr[c] = '\0';
  8311. strcpy(recurrencyKindStr,sstr);
  8312. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8313. {
  8314. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8315. }
  8316. else
  8317. {
  8318. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8319. }
  8320. }
  8321. else
  8322. {
  8323. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8324. {
  8325. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8326. }
  8327. else
  8328. {
  8329. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8330. }
  8331. }
  8332. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8333. //*********************validFrom***************************/
  8334. loc = strstr(sstrtemp, "validFrom");
  8335. if(loc != NULL)
  8336. {
  8337. c = 0;
  8338. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8339. while (loc[3+strlen("validFrom")+c] != '\"')
  8340. {
  8341. sstr[c] = loc[3+strlen("validFrom")+c];
  8342. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8343. c++;
  8344. }
  8345. sstr[c] = '\0';
  8346. strcpy(validFromStr,sstr);
  8347. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8348. {
  8349. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8350. }
  8351. else
  8352. {
  8353. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8354. }
  8355. }
  8356. else
  8357. {
  8358. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8359. {
  8360. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8361. }
  8362. else
  8363. {
  8364. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8365. }
  8366. }
  8367. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8368. //*********************validTo***************************/
  8369. loc = strstr(sstrtemp, "validTo");
  8370. if(loc != NULL)
  8371. {
  8372. c = 0;
  8373. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8374. while (loc[3+strlen("validTo")+c] != '\"')
  8375. {
  8376. sstr[c] = loc[3+strlen("validTo")+c];
  8377. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8378. c++;
  8379. }
  8380. sstr[c] = '\0';
  8381. strcpy(validToStr,sstr);
  8382. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8383. {
  8384. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8385. }
  8386. else
  8387. {
  8388. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8389. }
  8390. }
  8391. else
  8392. {
  8393. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8394. {
  8395. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8396. }
  8397. else
  8398. {
  8399. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8400. }
  8401. }
  8402. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8403. //*********************duration***************************/
  8404. loc = strstr(sstrtemp, "duration");
  8405. if(loc != NULL)
  8406. {
  8407. c = 0;
  8408. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8409. while (loc[strlen("duration")+2+c] != ',')
  8410. {
  8411. sstr[c] = loc[strlen("duration")+2+c];
  8412. c++;
  8413. }
  8414. sstr[c] = '\0';
  8415. durationInt = atoi(sstr);
  8416. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8417. {
  8418. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8419. }
  8420. else
  8421. {
  8422. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8423. }
  8424. }
  8425. else
  8426. {
  8427. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8428. {
  8429. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8430. }
  8431. else
  8432. {
  8433. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8434. }
  8435. }
  8436. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8437. //*********************startSchedule***************************/
  8438. loc = strstr(sstrtemp, "startSchedule");
  8439. if(loc != NULL)
  8440. {
  8441. c = 0;
  8442. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8443. while (loc[3+strlen("startSchedule")+c] != '\"')
  8444. {
  8445. sstr[c] = loc[3+strlen("startSchedule")+c];
  8446. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8447. c++;
  8448. }
  8449. sstr[c] = '\0';
  8450. strcpy(startScheduleStr,sstr);
  8451. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8452. {
  8453. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8454. }
  8455. else
  8456. {
  8457. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8458. }
  8459. }
  8460. else
  8461. {
  8462. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8463. {
  8464. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8465. }
  8466. else
  8467. {
  8468. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8469. }
  8470. }
  8471. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8472. //*********************chargingRateUnit***************************/
  8473. loc = strstr(sstrtemp, "chargingRateUnit");
  8474. if(loc != NULL)
  8475. {
  8476. c = 0;
  8477. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8478. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8479. {
  8480. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8481. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8482. c++;
  8483. }
  8484. sstr[c] = '\0';
  8485. strcpy(chargingRateUnitStr,sstr);
  8486. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8487. {
  8488. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8489. }
  8490. else
  8491. {
  8492. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8493. }
  8494. }
  8495. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8496. //****************chargingSchedulePeriod count start*******************/
  8497. int what_len = strlen("startPeriod");
  8498. char tempChargingProfile[1600]={0};
  8499. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8500. char *where = tempChargingProfile;
  8501. if (what_len)
  8502. {
  8503. while ((where = strstr(where, "startPeriod"))) {
  8504. where += what_len;
  8505. chargingSchedulePeriodCount++;
  8506. }
  8507. }
  8508. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8509. {
  8510. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8511. goto end;
  8512. }
  8513. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8514. //where = payload;
  8515. int templength = 0;
  8516. //int searchstart = 0;
  8517. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8518. {
  8519. //****************startPeriod*******************/
  8520. c=0;
  8521. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8522. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8523. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8524. {
  8525. sstr[c] = loc[strlen("startPeriod")+2+c];
  8526. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8527. c++;
  8528. }
  8529. sstr[c] = '\0';
  8530. startPeriodInt[periodNums] = atoi(sstr);
  8531. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8532. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8533. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8534. {
  8535. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8536. }
  8537. else
  8538. {
  8539. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8540. }
  8541. templength = strlen("startPeriod")+2+c;
  8542. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8543. //****************limit*******************/
  8544. c=0;
  8545. loc = strstr(tempChargingProfile + templength, "limit");
  8546. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8547. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8548. {
  8549. sstr[c] = loc[strlen("limit")+2+c];
  8550. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8551. c++;
  8552. }
  8553. sstr[c] = '\0';
  8554. limitflaot[periodNums] = atof(sstr);
  8555. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8556. {
  8557. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8558. }
  8559. else
  8560. {
  8561. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8562. }
  8563. templength = templength + strlen("limit")+2+c;
  8564. //****************numberPhases*******************/
  8565. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8566. if(loc != NULL)
  8567. {
  8568. c=0;
  8569. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8570. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8571. {
  8572. sstr[c] = loc[strlen("numberPhases")+2+c];
  8573. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8574. c++;
  8575. }
  8576. sstr[c] = '\0';
  8577. numberPhasesInt[periodNums] = atoi(sstr);
  8578. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8579. {
  8580. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8581. }
  8582. else
  8583. {
  8584. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8585. }
  8586. templength = templength + strlen("numberPhases")+2+c;
  8587. }
  8588. //where = loc;
  8589. }
  8590. //****************chargingSchedulePeriod count end*******************/
  8591. //*********************minChargingRate***************************/
  8592. loc = strstr(sstrtemp, "minChargingRate");
  8593. if(loc != NULL)
  8594. {
  8595. c = 0;
  8596. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8597. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8598. {
  8599. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8600. c++;
  8601. }
  8602. sstr[c] = '\0';
  8603. minChargingRateFloat = atof(sstr);
  8604. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8605. {
  8606. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8607. }
  8608. else
  8609. {
  8610. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8611. }
  8612. }
  8613. else
  8614. {
  8615. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8616. {
  8617. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8618. }
  8619. else
  8620. {
  8621. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8622. }
  8623. }
  8624. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8625. {
  8626. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8627. if(connectorIdInt != 0)
  8628. {
  8629. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8630. goto end;
  8631. }
  8632. strcpy(filename, ChargePointMaxProfile_JSON );
  8633. fptr1 = fopen(filename, "r");
  8634. if (!fptr1)
  8635. {
  8636. //file not exist
  8637. DEBUG_INFO("Unable to open the input file!!\n");
  8638. fptr1 = fopen(filename, "w+");
  8639. }
  8640. else
  8641. {
  8642. //Check Charging Profile Count
  8643. while(fscanf(fptr1, "%s", word) != EOF)
  8644. {
  8645. //DEBUG_INFO("word=%s\n",word);
  8646. if(strstr(word, "chargingProfileId")!= NULL)
  8647. {
  8648. //DEBUG_INFO("test chargingProfileId \n");
  8649. n_chargingProfile = n_chargingProfile + 1;
  8650. //DEBUG_INFO("chargingProfileId Found\n");
  8651. }
  8652. }
  8653. }
  8654. fclose(fptr1);
  8655. }
  8656. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8657. {
  8658. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8659. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8660. {
  8661. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8662. goto end;
  8663. }
  8664. memset(filename, 0, ARRAY_SIZE(filename));
  8665. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8666. fptr1 = fopen(filename, "r");
  8667. if (!fptr1)
  8668. {
  8669. //file not exist
  8670. //DEBUG_INFO("Unable to open the input file!!\n");
  8671. fptr1 = fopen(filename, "w+");
  8672. }
  8673. else
  8674. {
  8675. //Check Charging Profile Count
  8676. while(fscanf(fptr1, "%s", word) != EOF)
  8677. {
  8678. //DEBUG_INFO("word=%s\n",word);
  8679. if(strstr(word, "chargingProfileId")!= NULL)
  8680. {
  8681. //DEBUG_INFO("test chargingProfileId \n");
  8682. n_chargingProfile = n_chargingProfile + 1;
  8683. //DEBUG_INFO("chargingProfileId Found\n");
  8684. }
  8685. }
  8686. }
  8687. fclose(fptr1);
  8688. }
  8689. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8690. {
  8691. //printf("set chargingProfile 1-4\n");
  8692. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8693. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8694. if(connectorIdInt == 0)
  8695. {
  8696. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8697. goto end;
  8698. }
  8699. int tempIndex = 0;
  8700. //check Transaction active
  8701. if(gunType[connectorIdInt -1] == 'J')
  8702. {
  8703. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8704. {
  8705. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8706. }
  8707. else
  8708. {
  8709. tempIndex = connectorIdInt -1;
  8710. }
  8711. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8712. {
  8713. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8714. {
  8715. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8716. {
  8717. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8718. {
  8719. meet = TRUE;
  8720. break;
  8721. }
  8722. }
  8723. }
  8724. }
  8725. }
  8726. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8727. {
  8728. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8729. {
  8730. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8731. }
  8732. else
  8733. {
  8734. tempIndex = connectorIdInt -1;
  8735. }
  8736. for (int index = 0; index < CCS_QUANTITY; index++)
  8737. {
  8738. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8739. {
  8740. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8741. {
  8742. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8743. {
  8744. meet = TRUE;
  8745. break;
  8746. }
  8747. }
  8748. }
  8749. }
  8750. }
  8751. else if(gunType[connectorIdInt -1] == 'G')
  8752. {
  8753. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8754. {
  8755. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8756. }
  8757. else
  8758. {
  8759. tempIndex = connectorIdInt -1;
  8760. }
  8761. for (int index = 0; index < GB_QUANTITY; index++)
  8762. {
  8763. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8764. {
  8765. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8766. {
  8767. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8768. {
  8769. meet = TRUE;
  8770. break;
  8771. }
  8772. }
  8773. }
  8774. }
  8775. }
  8776. else
  8777. {
  8778. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8779. {
  8780. tempIndex = 2;
  8781. }
  8782. else
  8783. {
  8784. tempIndex = (connectorIdInt -1);
  8785. }
  8786. for (int index = 0; index < AC_QUANTITY; index++)
  8787. {
  8788. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8789. {
  8790. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8791. {
  8792. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8793. {
  8794. meet = TRUE;
  8795. break;
  8796. }
  8797. }
  8798. }
  8799. }
  8800. }
  8801. //check Transaction active
  8802. if(meet == FALSE)
  8803. {
  8804. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8805. goto end;
  8806. }
  8807. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8808. {
  8809. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8810. goto end;
  8811. }
  8812. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8813. fptr1 = fopen(filename, "r");
  8814. if (!fptr1)
  8815. {
  8816. //file not exist
  8817. DEBUG_INFO("Unable to open the input file!!\n");
  8818. fptr1 = fopen(filename, "w+");
  8819. }
  8820. else
  8821. {
  8822. //Check Charging Profile Count
  8823. while(fscanf(fptr1, "%s", word) != EOF)
  8824. {
  8825. //DEBUG_INFO("word=%s\n",word);
  8826. if(strstr(word, "chargingProfileId")!= NULL)
  8827. {
  8828. //DEBUG_INFO("test chargingProfileId \n");
  8829. n_chargingProfile = n_chargingProfile + 1;
  8830. //DEBUG_INFO("chargingProfileId Found\n");
  8831. }
  8832. }
  8833. }
  8834. fclose(fptr1);
  8835. }
  8836. // Check ChargeProfileMaxStackLevel
  8837. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8838. {
  8839. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8840. goto end;
  8841. }
  8842. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8843. {
  8844. int i = 0;
  8845. char fnametemp[200]={0};
  8846. n_chargingProfile = 0;
  8847. //Check ChargePointMaxProfile.json exit
  8848. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8849. {
  8850. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8851. //Check Charging Profile Count
  8852. while(fscanf(fptr1, "%s", word) != EOF)
  8853. {
  8854. //DEBUG_INFO("word=%s\n",word);
  8855. if(strstr(word, "chargingProfileId")!= NULL)
  8856. {
  8857. //DEBUG_INFO("test chargingProfileId \n");
  8858. n_chargingProfile = n_chargingProfile + 1;
  8859. i = i + 1;
  8860. //DEBUG_INFO("chargingProfileId Found\n");
  8861. }
  8862. memset(word, 0, ARRAY_SIZE(word));
  8863. }
  8864. fclose(fptr1);
  8865. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8866. }
  8867. //Check TxDefaultProfile_0.json exit
  8868. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8869. {
  8870. i = 0;
  8871. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8872. //Check Charging Profile Count
  8873. while(fscanf(fptr1, "%s", word) != EOF)
  8874. {
  8875. //DEBUG_INFO("word=%s\n",word);
  8876. if(strstr(word, "chargingProfileId")!= NULL)
  8877. {
  8878. //DEBUG_INFO("test chargingProfileId \n");
  8879. n_chargingProfile = n_chargingProfile + 1;
  8880. i = i + 1;
  8881. //DEBUG_INFO("chargingProfileId Found\n");
  8882. }
  8883. memset(word, 0, ARRAY_SIZE(word));
  8884. }
  8885. fclose(fptr1);
  8886. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8887. }
  8888. //Check TxDefaultProfile_%d.json
  8889. for(int j=1; j <= gunTotalNumber; j++)
  8890. {
  8891. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8892. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8893. if((access(fnametemp,F_OK))!=-1)
  8894. {
  8895. i = 0;
  8896. fptr1 = fopen(fnametemp, "r");
  8897. //Check Charging Profile Count
  8898. while(fscanf(fptr1, "%s", word) != EOF)
  8899. {
  8900. //DEBUG_INFO("word=%s\n",word);
  8901. if(strstr(word, "chargingProfileId")!= NULL)
  8902. {
  8903. //DEBUG_INFO("test chargingProfileId \n");
  8904. n_chargingProfile = n_chargingProfile + 1;
  8905. i = i + 1;
  8906. //DEBUG_INFO("chargingProfileId Found\n");
  8907. }
  8908. memset(word, 0, ARRAY_SIZE(word));
  8909. }
  8910. fclose(fptr1);
  8911. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8912. }
  8913. }
  8914. //Check TxProfile_%d.json
  8915. for(int j=1; j <= gunTotalNumber; j++)
  8916. {
  8917. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8918. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8919. if((access(fnametemp,F_OK))!=-1)
  8920. {
  8921. i = 0;
  8922. fptr1 = fopen(fnametemp, "r");
  8923. //Check Charging Profile Count
  8924. while(fscanf(fptr1, "%s", word) != EOF)
  8925. {
  8926. //DEBUG_INFO("word=%s\n",word);
  8927. if(strstr(word, "chargingProfileId")!= NULL)
  8928. {
  8929. //DEBUG_INFO("test chargingProfileId \n");
  8930. n_chargingProfile = n_chargingProfile + 1;
  8931. i = i + 1;
  8932. //DEBUG_INFO("chargingProfileId Found\n");
  8933. }
  8934. memset(word, 0, ARRAY_SIZE(word));
  8935. }
  8936. fclose(fptr1);
  8937. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8938. }
  8939. }
  8940. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8941. {
  8942. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8943. goto end;
  8944. }
  8945. }
  8946. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8947. //**********************************Write to File********************************************************/
  8948. FILE *infile;
  8949. FILE *outfile;
  8950. // open file for writing
  8951. infile = fopen (filename, "r");
  8952. outfile = fopen (tempfile, "w");
  8953. int d =0;
  8954. d = fgetc(infile);
  8955. //DEBUG_INFO("d:%d\n",d);
  8956. rewind(infile);
  8957. //*璉 瘚 辣蝏     1嚗   0 */
  8958. if(d == EOF)
  8959. {
  8960. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8961. fprintf(outfile,"%s\n",payload);
  8962. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8963. fclose(infile);
  8964. fclose(outfile);
  8965. sprintf(rmFileCmd,"rm -f %s",filename);
  8966. system(rmFileCmd);
  8967. rename(tempfile, filename);
  8968. sleep(1);
  8969. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8970. //system(rmFileCmd);
  8971. }
  8972. else
  8973. {
  8974. char buf[1000]={0};
  8975. int ChargingProfileAdded = FALSE;
  8976. while (fgets(buf, sizeof(buf), infile) != NULL)
  8977. {
  8978. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8979. //*************************tempconnectorIdInt*********************************/
  8980. loc = strstr(buf, "connectorId");
  8981. c = 0;
  8982. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8983. while (loc[strlen("connectorId")+2+c] != ',')
  8984. {
  8985. sstr[c] = loc[strlen("connectorId")+2+c];
  8986. c++;
  8987. }
  8988. sstr[c] = '\0';
  8989. tempconnectorIdInt = atoi(sstr);
  8990. //*************************tempchargingProfileIdInt*********************************/
  8991. loc = strstr(buf, "chargingProfileId");
  8992. c = 0;
  8993. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8994. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8995. {
  8996. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8997. c++;
  8998. }
  8999. sstr[c] = '\0';
  9000. tempchargingProfileIdInt = atoi(sstr);
  9001. //*************************tempstackLevelInt*********************************/
  9002. loc = strstr(buf, "stackLevel");
  9003. c = 0;
  9004. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9005. while (loc[strlen("stackLevel")+2+c] != ',')
  9006. {
  9007. sstr[c] = loc[strlen("stackLevel")+2+c];
  9008. c++;
  9009. }
  9010. sstr[c] = '\0';
  9011. tempstackLevelInt = atoi(sstr);
  9012. //*************************tempchargingProfilePurposeStr*********************************/
  9013. loc = strstr(payload, "chargingProfilePurpose");
  9014. c = 0;
  9015. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9016. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  9017. {
  9018. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  9019. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9020. c++;
  9021. }
  9022. sstr[c] = '\0';
  9023. strcpy(tempchargingProfilePurposeStr,sstr);
  9024. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9025. {
  9026. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9027. {
  9028. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9029. if(ChargingProfileAdded == FALSE)
  9030. {
  9031. fprintf(outfile,"%s\n",payload);
  9032. ChargingProfileAdded = TRUE;
  9033. }
  9034. }
  9035. else
  9036. {
  9037. if(tempstackLevelInt < stackLevelInt)
  9038. {
  9039. if(ChargingProfileAdded == FALSE)
  9040. {
  9041. fprintf(outfile,"%s\n",payload);
  9042. ChargingProfileAdded = TRUE;
  9043. fprintf(outfile,"%s\n",buf);
  9044. }
  9045. else
  9046. {
  9047. fprintf(outfile,"%s\n",buf);
  9048. }
  9049. }
  9050. else
  9051. {
  9052. if(ChargingProfileAdded == FALSE)
  9053. {
  9054. fprintf(outfile,"%s\n",buf);
  9055. fprintf(outfile,"%s\n",payload);
  9056. ChargingProfileAdded = TRUE;
  9057. }
  9058. else
  9059. {
  9060. fprintf(outfile,"%s\n",buf);
  9061. }
  9062. }
  9063. }
  9064. }
  9065. else
  9066. {
  9067. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9068. {
  9069. if(ChargingProfileAdded == FALSE)
  9070. {
  9071. fprintf(outfile,"%s\n",payload);
  9072. ChargingProfileAdded = TRUE;
  9073. fprintf(outfile,"%s\n",buf);
  9074. }
  9075. else
  9076. {
  9077. fprintf(outfile,"%s\n",buf);
  9078. }
  9079. }
  9080. else if(tempstackLevelInt < stackLevelInt)
  9081. {
  9082. if(ChargingProfileAdded == FALSE)
  9083. {
  9084. fprintf(outfile,"%s\n",payload);
  9085. ChargingProfileAdded = TRUE;
  9086. fprintf(outfile,"%s\n",buf);
  9087. }
  9088. else
  9089. {
  9090. fprintf(outfile,"%s\n",buf);
  9091. }
  9092. }
  9093. else
  9094. {
  9095. if(ChargingProfileAdded == FALSE)
  9096. {
  9097. fprintf(outfile,"%s\n",buf);
  9098. fprintf(outfile,"%s\n",payload);
  9099. ChargingProfileAdded = TRUE;
  9100. }
  9101. else
  9102. {
  9103. fprintf(outfile,"%s\n",buf);
  9104. }
  9105. }
  9106. }
  9107. } // end of while loop
  9108. fclose(infile);
  9109. fclose(outfile);
  9110. sprintf(rmFileCmd,"rm -f %s",filename);
  9111. system(rmFileCmd);
  9112. rename(tempfile, filename);
  9113. sleep(1);
  9114. result = TRUE;
  9115. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9116. }
  9117. end:
  9118. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9119. return result;
  9120. return result;
  9121. }
  9122. int handleTriggerMessageRequest(char *uuid, char *payload)
  9123. {
  9124. mtrace();
  9125. int result = FAIL;
  9126. int connectorIdIsNULL = FALSE;
  9127. int connectorIdInt =0;
  9128. char sstr[40]={0},sstrtemp[100]={ 0 };
  9129. char requestedMessagestr[40]={0};
  9130. char comfirmstr[20]={0};
  9131. int c = 0;
  9132. char *loc;
  9133. DEBUG_INFO("handleTriggerMessageRequest\n");
  9134. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9135. strcpy(sstrtemp, stringtrimspace(payload));
  9136. c = 0;
  9137. loc = strstr(sstrtemp, "requestedMessage");
  9138. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9139. {
  9140. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9141. c++;
  9142. }
  9143. sstr[c] = '\0';
  9144. strcpy(requestedMessagestr, sstr);
  9145. c = 0;
  9146. loc = strstr(sstrtemp, "connectorId");
  9147. if(loc == NULL)
  9148. {
  9149. connectorIdIsNULL = TRUE;
  9150. }
  9151. else
  9152. {
  9153. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9154. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9155. {
  9156. sstr[c] = loc[strlen("connectorId")+2+c];
  9157. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9158. c++;
  9159. }
  9160. sstr[c] = '\0';
  9161. connectorIdInt = atoi(sstr);
  9162. }
  9163. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  9164. {
  9165. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9166. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9167. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9168. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9169. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9170. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9171. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9172. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9173. {
  9174. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9175. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9176. return TRUE;
  9177. }
  9178. else
  9179. {
  9180. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9181. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9182. }
  9183. }
  9184. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9185. {
  9186. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9187. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9188. return TRUE;
  9189. }
  9190. //==========================
  9191. // Trigger message
  9192. //==========================
  9193. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9194. {
  9195. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9196. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9197. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9198. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9199. {
  9200. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9201. }
  9202. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9203. }
  9204. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9205. {
  9206. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9207. }
  9208. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9209. {
  9210. //sendBootNotificationRequest();
  9211. server_sign = FALSE;
  9212. }
  9213. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9214. {
  9215. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9216. }
  9217. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9218. {
  9219. if(connectorIdIsNULL == FALSE)
  9220. {
  9221. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9222. {
  9223. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9224. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  9225. }
  9226. }
  9227. else
  9228. {
  9229. for(int idx=0;idx< gunTotalNumber;idx++)
  9230. {
  9231. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9232. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  9233. }
  9234. }
  9235. }
  9236. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9237. {
  9238. if(connectorIdIsNULL == FALSE)
  9239. {
  9240. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9241. {
  9242. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9243. }
  9244. }
  9245. else
  9246. {
  9247. for(int idx=0;idx< gunTotalNumber;idx++)
  9248. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9249. }
  9250. }
  9251. return result;
  9252. }
  9253. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9254. {
  9255. mtrace();
  9256. int result = FAIL;
  9257. int connectorIdInt =0;
  9258. char comfirmstr[20]={0};
  9259. int tempIndex = 0;
  9260. json_object *UnlockConnector;
  9261. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9262. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9263. UnlockConnector = json_tokener_parse(payload);
  9264. if(!is_error(UnlockConnector))
  9265. {
  9266. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  9267. {
  9268. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  9269. }
  9270. }
  9271. json_object_put(UnlockConnector);
  9272. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  9273. if(gunTotalNumber == 0)
  9274. {
  9275. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9276. goto end;
  9277. }
  9278. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9279. {
  9280. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9281. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9282. goto end;
  9283. }
  9284. else
  9285. {
  9286. //check Transaction active
  9287. if(gunType[connectorIdInt-1] == 'J')
  9288. {
  9289. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9290. {
  9291. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9292. }
  9293. else
  9294. {
  9295. tempIndex = connectorIdInt -1;
  9296. }
  9297. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9298. {
  9299. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9300. {
  9301. //stop Transaction
  9302. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9303. }
  9304. }
  9305. }
  9306. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9307. {
  9308. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9309. {
  9310. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9311. }
  9312. else
  9313. {
  9314. tempIndex = connectorIdInt -1;
  9315. }
  9316. for (int index = 0; index < CCS_QUANTITY; index++)
  9317. {
  9318. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9319. {
  9320. //stop Transaction
  9321. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9322. }
  9323. }
  9324. }
  9325. else if(gunType[connectorIdInt-1] == 'G')
  9326. {
  9327. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9328. {
  9329. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9330. }
  9331. else
  9332. {
  9333. tempIndex = connectorIdInt -1;
  9334. }
  9335. for (int index = 0; index < GB_QUANTITY; index++)
  9336. {
  9337. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9338. {
  9339. //stop Transaction
  9340. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9341. }
  9342. }
  9343. }
  9344. else
  9345. {
  9346. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9347. {
  9348. tempIndex = 2;
  9349. }
  9350. else
  9351. {
  9352. tempIndex = connectorIdInt-1;
  9353. }
  9354. for (int index = 0; index < AC_QUANTITY; index++)
  9355. {
  9356. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9357. {
  9358. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9359. }
  9360. }
  9361. }
  9362. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9363. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9364. result = TRUE;
  9365. return result;
  9366. }
  9367. end:
  9368. //json_object_put(obj); --- remove temporally
  9369. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9370. return result;
  9371. }
  9372. static char UpdateFirmwarepayloadData[300]={0};
  9373. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9374. {
  9375. mtrace();
  9376. int result = FAIL;
  9377. pthread_t t;
  9378. sendUpdateFirmwareConfirmation(uuid);
  9379. memset(UpdateFirmwarepayloadData, 0, 300);
  9380. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9381. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9382. ////pthread_join(t, NULL); //
  9383. //pthread_detach(t);
  9384. //sendUpdateFirmwareConfirmation(uuid);
  9385. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9386. return result;
  9387. }
  9388. void *UpdateFirmwareProcess(void *data)
  9389. {
  9390. pthread_detach(pthread_self());
  9391. mtrace();
  9392. int retriesInt =0, retryIntervalInt=0;
  9393. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9394. int port=0;
  9395. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9396. int isSuccess = 0;
  9397. char ftpbuf[200];
  9398. char temp[100];
  9399. char * pch;
  9400. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9401. json_object *UpdateFirmware;
  9402. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  9403. if(!is_error(UpdateFirmware))
  9404. {
  9405. // Required data
  9406. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  9407. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  9408. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  9409. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  9410. // Optional data
  9411. if(json_object_object_get(UpdateFirmware, "retries"))
  9412. {
  9413. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  9414. }
  9415. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  9416. {
  9417. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  9418. }
  9419. }
  9420. json_object_put(UpdateFirmware);
  9421. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9422. memset(path, 0, ARRAY_SIZE(path));
  9423. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9424. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9425. if(strncmp(locationstr,"http", 4) == 0)
  9426. {
  9427. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9428. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9429. // protocol, user, password, host, path);
  9430. sprintf(ftppath,"/%s", path);
  9431. DEBUG_INFO("locationstr: %s\n", locationstr);
  9432. DEBUG_INFO("protocol: %s\n",protocol);
  9433. DEBUG_INFO("host: %s\n",host);
  9434. DEBUG_INFO("path: %s\n",path);
  9435. DEBUG_INFO("ftppath: %s\n",ftppath);
  9436. int ftppathlen=strlen(ftppath);
  9437. int i=1;
  9438. char filenametemp[50];
  9439. while(i < ftppathlen)
  9440. {
  9441. int len=ftppathlen-i;
  9442. if(ftppath[len]== 47) // '/' ascll code: 47
  9443. {
  9444. DEBUG_INFO("compare '/' all right\n");
  9445. break;
  9446. }
  9447. i=i+1;
  9448. }
  9449. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9450. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9451. filenametemp[i+1] = 0;
  9452. do
  9453. {
  9454. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9455. sleep(retryIntervalInt);
  9456. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9457. if(!isSuccess)
  9458. {
  9459. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9460. }
  9461. else
  9462. {
  9463. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9464. }
  9465. }
  9466. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9467. {
  9468. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9469. memset(temp, 0, ARRAY_SIZE(temp));
  9470. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9471. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9472. int ftppathlen=strlen(ftpbuf);
  9473. int i=1;
  9474. char filenametemp[50];
  9475. while(i < ftppathlen)
  9476. {
  9477. int len=ftppathlen-i;
  9478. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9479. {
  9480. DEBUG_INFO(" compare '/' all right\n");
  9481. break;
  9482. }
  9483. i=i+1;
  9484. }
  9485. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9486. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9487. filenametemp[i+1] = 0;
  9488. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9489. pch=strchr(temp,'@');
  9490. if(pch==NULL)
  9491. {
  9492. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9493. protocol, host, &port, path);
  9494. strcpy(user,"anonymous");
  9495. strcpy(password,"");
  9496. }
  9497. else
  9498. {
  9499. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9500. protocol, user, password, host, &port, path);
  9501. }
  9502. sscanf(host,"%[^/]%s",host1, path1);
  9503. sprintf(ftppath,"%s", path1);
  9504. //DEBUG_INFO("protocol =%s\n",protocol);
  9505. //DEBUG_INFO("user =%s\n",user);
  9506. //DEBUG_INFO("password =%s\n",password);
  9507. //DEBUG_INFO("host1 =%s\n",host1);
  9508. //DEBUG_INFO("port =%d\n",port);
  9509. //DEBUG_INFO("path1 =%s\n",path1);
  9510. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9511. //ftpFile(host, user, password, port, ftppath, fname);
  9512. //download firmware pthred
  9513. if(port == 0)
  9514. {
  9515. port = 21;
  9516. }
  9517. do
  9518. {
  9519. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9520. sleep(retryIntervalInt);
  9521. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9522. if(!isSuccess)
  9523. {
  9524. //BulldogUtil.sleepMs(interval*1000);
  9525. DEBUG_INFO("Update firmware request and download file fail.\n");
  9526. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9527. }
  9528. else
  9529. {
  9530. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9531. }
  9532. }
  9533. else
  9534. {
  9535. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9536. }
  9537. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9538. pthread_exit(NULL);
  9539. }
  9540. //==========================================
  9541. // Handle server response routine
  9542. //==========================================
  9543. void handleAuthorizeResponse(char *payload, int gun_index)
  9544. {
  9545. mtrace();
  9546. char expiryDatestr[30]={0};
  9547. char parentIdTagstr[20]={0};
  9548. char statusstr[20]={0};
  9549. char expiryDatestrtemp[30]={0};
  9550. char parentIdTagstrtemp[20]={0};
  9551. char IdTagstrtemp[20]={0};
  9552. char statusstrtemp[20]={0};
  9553. int expiryDateISNULL=FALSE;
  9554. int parentIdTagISNULL=FALSE;
  9555. char sstr[160]={0};
  9556. char* filename = AuthorizationCache_JSON;
  9557. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9558. char *loc;
  9559. int resultRename=0;
  9560. int responseIdTagInfoAsZero= 0;
  9561. char rmFileCmd[50]={0};
  9562. DEBUG_INFO("handleAuthorizeResponse...\n");
  9563. json_object *Authorize;
  9564. Authorize = json_tokener_parse(payload);
  9565. if(!is_error(Authorize))
  9566. {
  9567. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9568. {
  9569. // Required data
  9570. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9571. // Optional data
  9572. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9573. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9574. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9575. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9576. }
  9577. }
  9578. json_object_put(Authorize);
  9579. if(expiryDateISNULL == FALSE)
  9580. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9581. if(parentIdTagISNULL == FALSE)
  9582. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9583. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9584. //Update idTag information to authorization cache if supproted
  9585. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9586. {
  9587. if((access(filename,F_OK))!=-1)
  9588. {
  9589. printf("AuthorizationCache exist.\n");
  9590. }
  9591. else
  9592. {
  9593. printf("AuthorizationCache not exist\n");
  9594. FILE *log = fopen(filename, "w+");
  9595. if(log == NULL)
  9596. {
  9597. printf("log is NULL\n");
  9598. goto out;
  9599. }
  9600. else
  9601. {
  9602. fclose(log);
  9603. }
  9604. }
  9605. FILE *infile;
  9606. FILE *outfile;
  9607. // open file for writing
  9608. infile = fopen (filename, "r");
  9609. outfile = fopen (tempfile, "w");
  9610. int c;
  9611. c = fgetc(infile);
  9612. //DEBUG_INFO("c:%d\n",c);
  9613. rewind(infile);
  9614. if(c == EOF)
  9615. {
  9616. DEBUG_INFO("Orignal File is NULL\n");
  9617. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9618. {
  9619. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9620. }
  9621. else
  9622. {
  9623. strcpy(expiryDatestrtemp, "");
  9624. }
  9625. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9626. {
  9627. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9628. }
  9629. else
  9630. {
  9631. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9632. }
  9633. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9634. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9635. fclose(infile);
  9636. fclose(outfile);
  9637. sprintf(rmFileCmd,"rm -f %s",filename);
  9638. system(rmFileCmd);
  9639. resultRename = rename(tempfile, filename);
  9640. if(resultRename == 0)
  9641. {
  9642. printf("File renamed successfully");
  9643. }
  9644. else
  9645. {
  9646. printf("Error: unable to rename the file");
  9647. }
  9648. }
  9649. else
  9650. {
  9651. char buf[160]={0};
  9652. while (fgets(buf, ARRAY_SIZE(buf), infile) != NULL)
  9653. {
  9654. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9655. memset(expiryDatestr, 0, ARRAY_SIZE(expiryDatestrtemp));
  9656. memset(parentIdTagstr,0, ARRAY_SIZE(parentIdTagstrtemp));
  9657. memset(statusstr, 0, ARRAY_SIZE(statusstrtemp));
  9658. memset(IdTagstrtemp, 0, ARRAY_SIZE(IdTagstrtemp));
  9659. memset(expiryDatestrtemp, 0, ARRAY_SIZE(expiryDatestrtemp));
  9660. memset(parentIdTagstrtemp, 0, ARRAY_SIZE(parentIdTagstrtemp));
  9661. memset(statusstrtemp, 0, ARRAY_SIZE(statusstrtemp));
  9662. //------------------IdTag-----------------------
  9663. loc = strstr(buf, "idTag");
  9664. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9665. c = 0;
  9666. while (loc[3+strlen("idTag")+c] != '\"')
  9667. {
  9668. sstr[c] = loc[3+strlen("idTag")+c];
  9669. c++;
  9670. }
  9671. sstr[c] = '\0';
  9672. strcpy(IdTagstrtemp,sstr);
  9673. //*********************expiryDate***************/
  9674. loc = strstr(buf, "expiryDate");
  9675. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9676. c = 0;
  9677. while (loc[3+strlen("expiryDate")+c] != '\"')
  9678. {
  9679. sstr[c] = loc[3+strlen("expiryDate")+c];
  9680. c++;
  9681. }
  9682. sstr[c] = '\0';
  9683. strcpy(expiryDatestr,sstr);
  9684. //*********************parentIdTag***************/
  9685. loc = strstr(buf, "parentIdTag");
  9686. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9687. c = 0;
  9688. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9689. {
  9690. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9691. c++;
  9692. }
  9693. sstr[c] = '\0';
  9694. strcpy(parentIdTagstr,sstr);
  9695. //*********************status***************/
  9696. loc = strstr(buf, "status");
  9697. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9698. c = 0;
  9699. while (loc[3+strlen("status")+c] != '\"')
  9700. {
  9701. sstr[c] = loc[3+strlen("status")+c];
  9702. c++;
  9703. }
  9704. sstr[c] = '\0';
  9705. strcpy(statusstr,sstr);
  9706. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9707. {
  9708. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9709. responseIdTagInfoAsZero = 1;
  9710. }
  9711. else
  9712. {
  9713. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9714. }
  9715. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9716. {
  9717. //modify item
  9718. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9719. {
  9720. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9721. }
  9722. else
  9723. {
  9724. strcpy(expiryDatestrtemp, "");
  9725. }
  9726. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9727. {
  9728. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9729. }
  9730. else
  9731. {
  9732. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9733. }
  9734. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9735. }
  9736. else
  9737. {
  9738. //wrie original item
  9739. strcpy(expiryDatestrtemp, expiryDatestr);
  9740. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9741. strcpy(statusstrtemp, statusstr);
  9742. }
  9743. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9744. }
  9745. fclose(infile);
  9746. fclose(outfile);
  9747. sprintf(rmFileCmd,"rm -f %s",filename);
  9748. system(rmFileCmd);
  9749. resultRename = rename(tempfile, filename);
  9750. if(resultRename == 0)
  9751. {
  9752. DEBUG_INFO("File renamed successfully");
  9753. }
  9754. else
  9755. {
  9756. DEBUG_INFO("Error: unable to rename the file");
  9757. }
  9758. }
  9759. }
  9760. out:
  9761. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9762. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9763. authorizeRetryTimes = 0;
  9764. }
  9765. char * strtrimc( char * s )
  9766. {
  9767. char * p1 = s;
  9768. char * p2 = s;
  9769. while(*p1 != '\0')
  9770. {
  9771. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9772. {
  9773. if(*p1 != ',')
  9774. {
  9775. p1 ++;
  9776. }
  9777. else
  9778. {
  9779. break;
  9780. }
  9781. }
  9782. if(*p1 != ',')
  9783. {
  9784. * p2 ++ = *p1 ++;
  9785. //printf("p2=%s\n",p2);
  9786. }
  9787. else
  9788. {
  9789. break;
  9790. }
  9791. }
  9792. *p2 = '\0';
  9793. return (s);
  9794. }
  9795. void handleBootNotificationResponse(char *payload, int gun_index)
  9796. {
  9797. mtrace();
  9798. char statusStr[12]={0};
  9799. char currentTimeStr[30]={0};
  9800. int intervalInt = 0;
  9801. struct tm tp;
  9802. char buf[28]={0};
  9803. char timebuf[50]={0};
  9804. DEBUG_INFO("handleBootNotificationResponse...\n");
  9805. json_object *BootNotification;
  9806. BootNotification = json_tokener_parse(payload);
  9807. if(!is_error(BootNotification))
  9808. {
  9809. // Required data
  9810. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9811. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9812. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9813. }
  9814. json_object_put(BootNotification);
  9815. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9816. BootNotificationInterval = intervalInt;
  9817. HeartBeatWaitTime = intervalInt;
  9818. //write back to ShmOCPP16Data->BootNotification
  9819. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9820. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9821. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9822. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9823. {
  9824. server_sign = TRUE;
  9825. server_pending =FALSE;
  9826. }
  9827. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9828. {
  9829. server_pending = TRUE;
  9830. }
  9831. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9832. tp.tm_isdst = -1;
  9833. //time_t utc = mktime(&tp);
  9834. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9835. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9836. sprintf(timebuf,"date -s '%s'",buf);
  9837. system(timebuf);
  9838. srand(time(NULL));
  9839. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9840. //==============================================
  9841. // RTC sync
  9842. //==============================================
  9843. system("/sbin/hwclock -w --systohc");
  9844. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9845. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9846. }
  9847. void handleDataTransferResponse(char *payload, int gun_index)
  9848. {
  9849. char sstr[160]={0};//sstr[200]={ 0 };
  9850. int c = 0;
  9851. char *loc;
  9852. DEBUG_INFO("handleDataTransferResponse ...\n");
  9853. loc = strstr(payload, "status");
  9854. printf("loc=%s\n",loc);
  9855. c = 0;
  9856. while (loc[3+strlen("status")+c] != '\"')
  9857. {
  9858. sstr[c] = loc[3+strlen("status")+c];
  9859. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9860. c++;
  9861. }
  9862. sstr[c] = '\0';
  9863. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9864. }
  9865. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9866. {
  9867. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9868. //struct json_object *obj;
  9869. // obj = json_tokener_parse(payload);
  9870. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9871. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9872. //No fields are defined.
  9873. }
  9874. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9875. {
  9876. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9877. //struct json_object *obj;
  9878. // obj = json_tokener_parse(payload);
  9879. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9880. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9881. //No fields are defined.
  9882. }
  9883. void handleHeartbeatResponse(char *payload, int gun_index)
  9884. {
  9885. mtrace();
  9886. struct tm tp;
  9887. char buf[28]={0};
  9888. char timebuf[50]={0};
  9889. DEBUG_INFO("handleHeartbeatResponse...\n");
  9890. json_object *Heartbeat;
  9891. Heartbeat = json_tokener_parse(payload);
  9892. if(!is_error(Heartbeat))
  9893. {
  9894. // Required data
  9895. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9896. }
  9897. json_object_put(BootNotification);
  9898. if(FirstHeartBeat == 0)
  9899. {
  9900. FirstHeartBeat = 1;
  9901. DEBUG_INFO("FirstHeartBeat \n");
  9902. }
  9903. HeartBeatWithNOResponse = 0;
  9904. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9905. tp.tm_isdst = -1;
  9906. //time_t utc = mktime(&tp);
  9907. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9908. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9909. sprintf(timebuf,"date -s '%s'",buf);
  9910. system(timebuf);
  9911. //==============================================
  9912. // RTC sync
  9913. //==============================================
  9914. system("/sbin/hwclock -w --systohc");
  9915. //===============================================
  9916. //Print Out HeartBeat log
  9917. //===============================================
  9918. {
  9919. double diff_t;
  9920. struct tm tp,tp1;
  9921. // BootNotification Receive Time
  9922. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9923. tp.tm_isdst = -1;
  9924. time_t BootNotificationReceiveTime = mktime(&tp);
  9925. //HeartBeat Receive Time
  9926. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  9927. tp1.tm_isdst = -1;
  9928. time_t HeartBeatReceiveTime = mktime(&tp1);
  9929. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  9930. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  9931. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  9932. {
  9933. HeartBeatCountPerHour = (int)diff_t / 3600;
  9934. DEBUG_INFO("handleHeartbeatResponse ...\n");
  9935. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  9936. }
  9937. }
  9938. }
  9939. void handleMeterValuesResponse(char *payload, int gun_index)
  9940. {
  9941. mtrace();
  9942. DEBUG_INFO("handleMeterValuesResponse...\n");
  9943. }
  9944. void handleStartTransactionResponse(char *payload, int gun_index)
  9945. {
  9946. mtrace();
  9947. //int transactionIdInt = 0;
  9948. FILE *outfile;
  9949. char data[100]={0};
  9950. DEBUG_INFO("handleStartTransactionResponse...\n");
  9951. json_object *StartTransaction;
  9952. StartTransaction = json_tokener_parse(payload);
  9953. if(!is_error(StartTransaction))
  9954. {
  9955. // Required data
  9956. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  9957. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  9958. // Optional data
  9959. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  9960. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  9961. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9962. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  9963. }
  9964. json_object_put(StartTransaction);
  9965. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9966. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9967. //-----------Start : write to the Queue TransactionId file -----------------//
  9968. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9969. {}
  9970. else
  9971. {
  9972. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9973. if(log == NULL)
  9974. {
  9975. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9976. return ;
  9977. }
  9978. else
  9979. {
  9980. fclose(log);
  9981. }
  9982. }
  9983. // open file for writing
  9984. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  9985. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  9986. {
  9987. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9988. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9989. fputs(data, outfile);
  9990. fclose (outfile);
  9991. }
  9992. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9993. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9994. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9995. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9996. }
  9997. void handleStatusNotificationResponse(char *payload, int gun_index)
  9998. {
  9999. mtrace();
  10000. DEBUG_INFO("handleStatusNotificationResponse...\n");
  10001. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10002. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10003. }
  10004. void handleStopTransactionnResponse(char *payload, int gun_index)
  10005. {
  10006. mtrace();
  10007. DEBUG_INFO("handleStopTransactionnResponse...\n");
  10008. json_object *StopTransaction;
  10009. StopTransaction = json_tokener_parse(payload);
  10010. if(!is_error(StopTransaction))
  10011. {
  10012. // Optional data
  10013. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  10014. {
  10015. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  10016. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  10017. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  10018. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10019. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  10020. }
  10021. }
  10022. json_object_put(StopTransaction);
  10023. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10024. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10025. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10026. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10027. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10028. }
  10029. //==========================================
  10030. // Handle Error routine
  10031. //==========================================
  10032. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10033. {
  10034. mtrace();
  10035. #ifdef SystemLogMessage
  10036. DEBUG_INFO("errorCode: %s\n", errorCode);
  10037. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10038. DEBUG_INFO("errorDetails: %s\n", payload);
  10039. #endif
  10040. }
  10041. //===============================================
  10042. // Common routine
  10043. //===============================================
  10044. int initialConfigurationTable(void)
  10045. {
  10046. //clock_t start_t, end_t, total_t;
  10047. FILE *fp;
  10048. FILE *outfile;
  10049. char str[200]={0};
  10050. char sstr[100]={0};
  10051. int c = 0;
  10052. char *loc;
  10053. DEBUG_INFO("initialConfigurationTable...\n");
  10054. //start_t = clock();
  10055. //printf("Starting of the program, start_t = %ld\n", start_t);
  10056. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10057. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10058. {
  10059. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10060. if(outfile == NULL)
  10061. {
  10062. DEBUG_INFO("Error opening file\n");
  10063. return FALSE;
  10064. }
  10065. /*Core Profile*/
  10066. //AllowOfflineTxForUnknownId
  10067. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10070. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10071. //AuthorizationCacheEnabled
  10072. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10076. //AuthorizeRemoteTxRequests
  10077. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10081. //BlinkRepeat
  10082. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10086. //ClockAlignedDataInterval
  10087. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10090. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10091. //ConnectionTimeOut
  10092. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10095. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10096. //GetConfigurationMaxKeys
  10097. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "44" );
  10100. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10101. // HeartbeatInterval
  10102. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10105. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10106. // LightIntensity
  10107. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10110. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10111. // LocalAuthorizeOffline
  10112. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10116. // LocalPreAuthorize
  10117. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10120. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10121. // MaxEnergyOnInvalidId
  10122. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10125. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10126. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10127. // MeterValuesAlignedData
  10128. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10130. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10132. else
  10133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10134. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10135. // MeterValuesAlignedDataMaxLength
  10136. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10138. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10140. else
  10141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10143. // MeterValuesSampledData
  10144. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10146. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10148. else
  10149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10151. // MeterValuesSampledDataMaxLength
  10152. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10154. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10156. else
  10157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10158. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10159. // MeterValueSampleInterval
  10160. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10164. // MinimumStatusDuration
  10165. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10168. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10169. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10170. // NumberOfConnectors
  10171. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10173. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10174. {
  10175. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10176. }
  10177. else
  10178. {
  10179. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10180. }
  10181. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10182. // ResetRetries
  10183. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10186. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10187. // ConnectorPhaseRotation
  10188. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10191. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10192. // ConnectorPhaseRotationMaxLength
  10193. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10196. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10197. // StopTransactionOnEVSideDisconnect
  10198. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10202. // StopTransactionOnInvalidId
  10203. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10207. // StopTxnAlignedData
  10208. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10211. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10212. // StopTxnAlignedDataMaxLength
  10213. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10216. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10217. // StopTxnSampledData
  10218. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10220. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10221. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10222. else
  10223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10224. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10225. // StopTxnSampledDataMaxLength
  10226. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10228. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10229. {
  10230. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10231. }
  10232. else
  10233. {
  10234. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10235. }
  10236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10237. // SupportedFeatureProfiles
  10238. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10241. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10242. // SupportedFeatureProfilesMaxLength
  10243. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10246. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10247. // TransactionMessageAttempts
  10248. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10251. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10252. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10253. // TransactionMessageRetryInterval
  10254. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10257. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10258. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10259. // UnlockConnectorOnEVSideDisconnect
  10260. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10263. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10264. // WebSocketPingInterval
  10265. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10268. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10269. // QueueOffLineStartTransactionMessage
  10270. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10271. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10273. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10274. //* Local Auth List Management Profile*/
  10275. #if 0
  10276. //For OCTT Test Case
  10277. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10280. #endif
  10281. #if 1
  10282. //LocalAuthListEnabled
  10283. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10284. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10286. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10287. #endif
  10288. //LocalAuthListMaxLength
  10289. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10293. //SendLocalListMaxLength
  10294. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10298. //ReserveConnectorZeroSupported
  10299. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10303. //* Smart Charging Profile */
  10304. //ChargeProfileMaxStackLevel
  10305. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10308. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10309. // ChargingScheduleAllowedChargingRateUnit
  10310. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10312. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10313. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10314. // ChargingScheduleMaxPeriods
  10315. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10318. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10319. // ConnectorSwitch3to1PhaseSupported
  10320. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10323. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10324. // MaxChargingProfilesInstalled
  10325. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10328. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10329. fclose(outfile);
  10330. }
  10331. else
  10332. {
  10333. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10334. char keystr[60]={0};
  10335. char readonlystr[10]={0};
  10336. char valuestr[100]={0};
  10337. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10338. if(fp == NULL) {
  10339. DEBUG_INFO("Error opening file");
  10340. return FALSE;
  10341. }
  10342. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10343. {
  10344. //DEBUG_INFO("Get Configuration \n");
  10345. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10346. //*************************key*********************************/
  10347. loc = strstr(str, "key");
  10348. c = 0;
  10349. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10350. while (loc[strlen("key")+3+c] != '\"')
  10351. {
  10352. sstr[c] = loc[strlen("key")+3+c];
  10353. c++;
  10354. }
  10355. sstr[c] = '\0';
  10356. strcpy(keystr,sstr);
  10357. //*************************readonly*********************************/
  10358. loc = strstr(str, "readonly");
  10359. c = 0;
  10360. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10361. while (loc[strlen("readonly")+2+c] != ',')
  10362. {
  10363. sstr[c] = loc[strlen("readonly")+2+c];
  10364. c++;
  10365. }
  10366. sstr[c] = '\0';
  10367. strcpy(readonlystr,sstr);
  10368. //*************************value*********************************/
  10369. loc = strstr(str, "value");
  10370. c = 0;
  10371. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10372. while (loc[strlen("value")+3+c] != '\"')
  10373. {
  10374. sstr[c] = loc[strlen("value")+3+c];
  10375. c++;
  10376. }
  10377. sstr[c] = '\0';
  10378. strcpy(valuestr,sstr);
  10379. // DEBUG_INFO("keystr=%s\n",keystr);
  10380. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10381. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10382. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10383. {
  10384. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10385. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10387. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10388. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10389. }
  10390. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10391. {
  10392. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10393. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10394. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10395. }
  10396. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10397. {
  10398. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10399. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10400. }
  10401. if(strcmp(keystr, "BlinkRepeat") == 0)
  10402. {
  10403. //Charger.BlinkRepeat = Integer.parseInt(value);
  10404. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10405. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10406. }
  10407. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10408. {
  10409. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10410. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10411. }
  10412. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10413. {
  10414. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10415. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10416. }
  10417. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10418. {
  10419. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10420. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10421. }
  10422. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10423. {
  10424. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10425. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10426. HeartBeatWaitTime = atoi(valuestr);
  10427. }
  10428. if(strcmp(keystr, "LightIntensity") == 0)
  10429. {
  10430. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10431. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10432. }
  10433. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10434. {
  10435. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10436. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10437. }
  10438. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10439. {
  10440. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10441. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10442. }
  10443. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10444. {
  10445. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10446. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10447. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10448. }
  10449. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10450. {
  10451. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10452. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10453. }
  10454. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10455. {
  10456. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10457. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10458. }
  10459. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10460. {
  10461. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10462. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10463. }
  10464. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10465. {
  10466. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10467. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10468. }
  10469. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10470. {
  10471. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10472. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10473. }
  10474. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10475. {
  10476. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10477. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10478. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10479. }
  10480. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10481. {
  10482. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10483. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10484. }
  10485. if(strcmp(keystr, "ResetRetries") == 0)
  10486. {
  10487. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10488. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10489. }
  10490. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10491. {
  10492. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10493. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10494. }
  10495. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10496. {
  10497. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10498. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10499. }
  10500. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10501. {
  10502. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10503. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10504. }
  10505. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10506. {
  10507. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10508. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10509. }
  10510. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10511. {
  10512. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10513. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10514. }
  10515. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10516. {
  10517. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10518. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10519. }
  10520. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10521. {
  10522. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10523. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10524. }
  10525. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10526. {
  10527. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10528. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10529. }
  10530. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10531. {
  10532. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10533. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10534. }
  10535. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10536. {
  10537. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10538. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10539. }
  10540. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10541. {
  10542. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10543. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10544. TransactionMessageAttemptsValue = atoi(valuestr);
  10545. }
  10546. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10547. {
  10548. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10549. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10550. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10551. }
  10552. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10553. {
  10554. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10555. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10556. }
  10557. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10558. {
  10559. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10560. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10561. }
  10562. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10563. {
  10564. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10565. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10566. }
  10567. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10568. {
  10569. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10570. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10571. }
  10572. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10573. {
  10574. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10575. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10576. }
  10577. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10578. {
  10579. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10580. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10581. }
  10582. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10583. {
  10584. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10585. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10586. }
  10587. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10588. {
  10589. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10590. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10591. }
  10592. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10593. {
  10594. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10595. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10596. }
  10597. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10598. {
  10599. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10600. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10601. }
  10602. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10603. {
  10604. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10605. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10606. }
  10607. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10608. {
  10609. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10610. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10611. }
  10612. }
  10613. fclose(fp);
  10614. }
  10615. return 0;
  10616. }
  10617. void StoreConfigurationTable(void)
  10618. {
  10619. FILE *outfile;
  10620. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10621. if(outfile == NULL)
  10622. {
  10623. DEBUG_INFO("Error opening file");
  10624. return ;
  10625. }
  10626. /*Core Profile*/
  10627. //AllowOfflineTxForUnknownId
  10628. /*
  10629. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10630. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10633. */
  10634. //DEBUG_INFO("data=%s\n",data);
  10635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10636. //AuthorizationCacheEnabled
  10637. /*
  10638. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10641. */
  10642. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10643. //AuthorizeRemoteTxRequests
  10644. /*
  10645. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10648. */
  10649. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10650. //BlinkRepeat
  10651. /*
  10652. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10655. */
  10656. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10657. //ClockAlignedDataInterval
  10658. /*
  10659. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10662. */
  10663. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10664. //ConnectionTimeOut
  10665. /*
  10666. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10669. */
  10670. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10671. //GetConfigurationMaxKeys
  10672. /*
  10673. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10676. */
  10677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10678. // HeartbeatInterval
  10679. /*
  10680. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10683. */
  10684. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10685. // LightIntensity
  10686. /*
  10687. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10690. */
  10691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10692. // LocalAuthorizeOffline
  10693. /*
  10694. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10697. */
  10698. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10699. // LocalPreAuthorize
  10700. /*
  10701. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10704. */
  10705. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10706. // MaxEnergyOnInvalidId
  10707. /*
  10708. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10711. */
  10712. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10713. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10714. // MeterValuesAlignedData
  10715. /*
  10716. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10719. */
  10720. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10721. // MeterValuesAlignedDataMaxLength
  10722. /*
  10723. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10726. */
  10727. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10728. // MeterValuesSampledData
  10729. /*
  10730. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10733. */
  10734. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10735. // MeterValuesSampledDataMaxLength
  10736. /*
  10737. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10740. */
  10741. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10742. // MeterValueSampleInterval
  10743. /*
  10744. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10747. */
  10748. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10749. // MinimumStatusDuration
  10750. /*
  10751. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10754. */
  10755. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10756. // NumberOfConnectors
  10757. /*
  10758. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10760. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10761. {
  10762. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10763. }
  10764. else
  10765. {
  10766. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10767. }
  10768. */
  10769. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10770. // ResetRetries
  10771. /*
  10772. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10775. */
  10776. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10777. // ConnectorPhaseRotation
  10778. /*
  10779. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10782. */
  10783. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10784. // ConnectorPhaseRotationMaxLength
  10785. /*
  10786. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10789. */
  10790. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10791. // StopTransactionOnEVSideDisconnect
  10792. /*
  10793. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10796. */
  10797. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10798. // StopTransactionOnInvalidId
  10799. /*
  10800. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10803. */
  10804. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10805. // StopTxnAlignedData
  10806. /*
  10807. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10810. */
  10811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10812. // StopTxnAlignedDataMaxLength
  10813. /*
  10814. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10817. */
  10818. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10819. // StopTxnSampledData
  10820. /*
  10821. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10824. */
  10825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10826. // StopTxnSampledDataMaxLength
  10827. /*
  10828. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10831. */
  10832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10833. // SupportedFeatureProfiles
  10834. /*
  10835. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10838. */
  10839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10840. // SupportedFeatureProfilesMaxLength
  10841. /*
  10842. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10845. */
  10846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10847. // TransactionMessageAttempts
  10848. /*
  10849. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10852. */
  10853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10854. // TransactionMessageRetryInterval
  10855. /*
  10856. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10859. */
  10860. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10861. // UnlockConnectorOnEVSideDisconnect
  10862. /*
  10863. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10866. */
  10867. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10868. // WebSocketPingInterval
  10869. /*
  10870. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10873. */
  10874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10875. // QueueOffLineStartTransactionMessage
  10876. /*
  10877. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  10878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10880. */
  10881. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10882. //* Local Auth List Management Profile*/
  10883. //LocalAuthListEnabled
  10884. /*
  10885. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10888. */
  10889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10890. //LocalAuthListMaxLength
  10891. /*
  10892. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10895. */
  10896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10897. //SendLocalListMaxLength
  10898. /*
  10899. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10902. */
  10903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10904. //ReserveConnectorZeroSupported
  10905. /*
  10906. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10909. */
  10910. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10911. //* Smart Charging Profile */
  10912. //ChargeProfileMaxStackLevel
  10913. /*
  10914. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10917. */
  10918. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10919. // ChargingScheduleAllowedChargingRateUnit
  10920. /*
  10921. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10924. */
  10925. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10926. // ChargingScheduleMaxPeriods
  10927. /*
  10928. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10931. */
  10932. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10933. // ConnectorSwitch3to1PhaseSupported
  10934. /*
  10935. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10938. */
  10939. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10940. // MaxChargingProfilesInstalled
  10941. /*
  10942. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10945. */
  10946. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10947. fclose(outfile);
  10948. }
  10949. void getKeyValue(char *keyReq)
  10950. {
  10951. int isEmpty = FALSE;
  10952. int isKnowKey = FALSE;
  10953. DEBUG_INFO("keyReq = %s\n", keyReq);
  10954. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10955. isEmpty = TRUE;
  10956. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10957. {
  10958. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10960. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10961. {
  10962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10963. }
  10964. else
  10965. {
  10966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10967. }
  10968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10969. isKnowKey = TRUE;
  10970. }
  10971. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10972. {
  10973. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10975. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10976. {
  10977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10978. }
  10979. else
  10980. {
  10981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10982. }
  10983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10984. isKnowKey = TRUE;
  10985. }
  10986. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10987. {
  10988. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10990. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10991. {
  10992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10993. }
  10994. else
  10995. {
  10996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10997. }
  10998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10999. isKnowKey = TRUE;
  11000. }
  11001. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11002. {
  11003. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11005. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11006. {
  11007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11008. }
  11009. else
  11010. {
  11011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11012. }
  11013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11014. isKnowKey = TRUE;
  11015. }
  11016. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11017. {
  11018. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11020. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11021. {
  11022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11023. }
  11024. else
  11025. {
  11026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11027. }
  11028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11029. isKnowKey = TRUE;
  11030. }
  11031. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11032. {
  11033. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11035. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11036. {
  11037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11038. }
  11039. else
  11040. {
  11041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11042. }
  11043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11044. isKnowKey = TRUE;
  11045. }
  11046. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11047. {
  11048. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11050. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11051. {
  11052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11053. }
  11054. else
  11055. {
  11056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11057. }
  11058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11059. isKnowKey = TRUE;
  11060. }
  11061. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11062. {
  11063. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11065. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11066. {
  11067. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11068. }
  11069. else
  11070. {
  11071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11072. }
  11073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11074. isKnowKey = TRUE;
  11075. }
  11076. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11077. {
  11078. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11080. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11081. {
  11082. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11083. }
  11084. else
  11085. {
  11086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11087. }
  11088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11089. isKnowKey = TRUE;
  11090. }
  11091. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11092. {
  11093. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11095. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11096. {
  11097. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11098. }
  11099. else
  11100. {
  11101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11102. }
  11103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11104. isKnowKey = TRUE;
  11105. }
  11106. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11107. {
  11108. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11110. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11111. {
  11112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11113. }
  11114. else
  11115. {
  11116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11117. }
  11118. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11119. isKnowKey = TRUE;
  11120. }
  11121. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11122. {
  11123. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11125. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11126. {
  11127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11128. }
  11129. else
  11130. {
  11131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11132. }
  11133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11134. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11135. isKnowKey = TRUE;
  11136. }
  11137. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11138. {
  11139. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11141. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11142. {
  11143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11144. }
  11145. else
  11146. {
  11147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11148. }
  11149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11150. isKnowKey = TRUE;
  11151. }
  11152. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11153. {
  11154. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11156. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11157. {
  11158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11159. }
  11160. else
  11161. {
  11162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11163. }
  11164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11165. isKnowKey = TRUE;
  11166. }
  11167. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11168. {
  11169. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11171. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11172. {
  11173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11174. }
  11175. else
  11176. {
  11177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11178. }
  11179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11180. isKnowKey = TRUE;
  11181. }
  11182. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11183. {
  11184. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11186. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11187. {
  11188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11189. }
  11190. else
  11191. {
  11192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11193. }
  11194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11195. isKnowKey = TRUE;
  11196. }
  11197. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11198. {
  11199. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11201. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11202. {
  11203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11204. }
  11205. else
  11206. {
  11207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11208. }
  11209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11210. isKnowKey = TRUE;
  11211. }
  11212. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11213. {
  11214. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11216. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11217. {
  11218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11219. }
  11220. else
  11221. {
  11222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11223. }
  11224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11225. isKnowKey = TRUE;
  11226. }
  11227. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11228. {
  11229. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11231. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11232. {
  11233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11234. }
  11235. else
  11236. {
  11237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11238. }
  11239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11240. isKnowKey = TRUE;
  11241. }
  11242. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11243. {
  11244. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11246. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11247. {
  11248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11249. }
  11250. else
  11251. {
  11252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11253. }
  11254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11255. isKnowKey = TRUE;
  11256. }
  11257. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11258. {
  11259. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11261. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11262. {
  11263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11264. }
  11265. else
  11266. {
  11267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11268. }
  11269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11270. isKnowKey = TRUE;
  11271. }
  11272. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11273. {
  11274. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11276. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11277. {
  11278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11279. }
  11280. else
  11281. {
  11282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11283. }
  11284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11285. isKnowKey = TRUE;
  11286. }
  11287. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11288. {
  11289. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11291. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11292. {
  11293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11294. }
  11295. else
  11296. {
  11297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11298. }
  11299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11300. isKnowKey = TRUE;
  11301. }
  11302. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11303. {
  11304. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11306. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11307. {
  11308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11309. }
  11310. else
  11311. {
  11312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11313. }
  11314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11315. isKnowKey = TRUE;
  11316. }
  11317. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11318. {
  11319. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11321. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11322. {
  11323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11324. }
  11325. else
  11326. {
  11327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11328. }
  11329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11330. isKnowKey = TRUE;
  11331. }
  11332. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11333. {
  11334. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11336. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11337. {
  11338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11339. }
  11340. else
  11341. {
  11342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11343. }
  11344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11345. isKnowKey = TRUE;
  11346. }
  11347. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11348. {
  11349. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11351. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11352. {
  11353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11354. }
  11355. else
  11356. {
  11357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11358. }
  11359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11360. isKnowKey = TRUE;
  11361. }
  11362. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11363. {
  11364. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11366. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11367. {
  11368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11369. }
  11370. else
  11371. {
  11372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11373. }
  11374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11375. isKnowKey = TRUE;
  11376. }
  11377. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11378. {
  11379. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11381. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11382. {
  11383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11384. }
  11385. else
  11386. {
  11387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11388. }
  11389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11390. isKnowKey = TRUE;
  11391. }
  11392. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11393. {
  11394. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11396. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11397. {
  11398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11399. }
  11400. else
  11401. {
  11402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11403. }
  11404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11405. isKnowKey = TRUE;
  11406. }
  11407. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11408. {
  11409. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11411. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11412. {
  11413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11414. }
  11415. else
  11416. {
  11417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11418. }
  11419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11420. isKnowKey = TRUE;
  11421. }
  11422. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11423. {
  11424. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11426. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11427. {
  11428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11429. }
  11430. else
  11431. {
  11432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11433. }
  11434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11435. isKnowKey = TRUE;
  11436. }
  11437. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11438. {
  11439. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11441. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11442. {
  11443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11444. }
  11445. else
  11446. {
  11447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11448. }
  11449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11450. isKnowKey = TRUE;
  11451. }
  11452. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11453. {
  11454. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11456. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11457. {
  11458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11459. }
  11460. else
  11461. {
  11462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11463. }
  11464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11465. isKnowKey = TRUE;
  11466. }
  11467. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11468. {
  11469. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11471. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11472. {
  11473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11474. }
  11475. else
  11476. {
  11477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11478. }
  11479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11480. isKnowKey = TRUE;
  11481. }
  11482. #if 1
  11483. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11484. {
  11485. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11487. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11488. {
  11489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11490. }
  11491. else
  11492. {
  11493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11494. }
  11495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11496. isKnowKey = TRUE;
  11497. }
  11498. #endif
  11499. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11500. {
  11501. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11503. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11504. {
  11505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11506. }
  11507. else
  11508. {
  11509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11510. }
  11511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11512. isKnowKey = TRUE;
  11513. }
  11514. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11515. {
  11516. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11518. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11519. {
  11520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11521. }
  11522. else
  11523. {
  11524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11525. }
  11526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11527. isKnowKey = TRUE;
  11528. }
  11529. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11530. {
  11531. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11533. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11534. {
  11535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11536. }
  11537. else
  11538. {
  11539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11540. }
  11541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11542. isKnowKey = TRUE;
  11543. }
  11544. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11545. {
  11546. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11548. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11549. {
  11550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11551. }
  11552. else
  11553. {
  11554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11555. }
  11556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11557. isKnowKey = TRUE;
  11558. }
  11559. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11560. {
  11561. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11563. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11564. {
  11565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11566. }
  11567. else
  11568. {
  11569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11570. }
  11571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11572. isKnowKey = TRUE;
  11573. }
  11574. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11575. {
  11576. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11578. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11579. {
  11580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11581. }
  11582. else
  11583. {
  11584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11585. }
  11586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11587. isKnowKey = TRUE;
  11588. }
  11589. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11590. {
  11591. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11593. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11594. {
  11595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11596. }
  11597. else
  11598. {
  11599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11600. }
  11601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11602. isKnowKey = TRUE;
  11603. }
  11604. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11605. {
  11606. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11608. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11609. {
  11610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11611. }
  11612. else
  11613. {
  11614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11615. }
  11616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11617. isKnowKey = TRUE;
  11618. }
  11619. //=========================================================
  11620. if(!isEmpty && !isKnowKey)
  11621. {
  11622. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11623. strcpy(unknownkey[UnknownKeynum], keyReq);
  11624. UnknownKeynum = UnknownKeynum + 1;
  11625. }
  11626. }
  11627. void processUnkownKey(void)
  11628. {
  11629. DEBUG_INFO("processUnkownKey...\n");
  11630. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11631. for(int index=0; index < UnknownKeynum; index++)
  11632. {
  11633. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11634. {
  11635. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11636. }
  11637. }
  11638. }
  11639. int setKeyValue(char *key, char *value)
  11640. {
  11641. int isSuccess = NotSupported;
  11642. int check_ascii=0;
  11643. char str[10]={0};
  11644. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11645. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11646. {
  11647. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11648. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11649. {
  11650. strcpy(str, (const char*)value);
  11651. for(int i = 0; str[i]; i++){
  11652. str[i] = tolower(str[i]);
  11653. }
  11654. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11655. isSuccess = ConfigurationStatus_Accepted;
  11656. }
  11657. else
  11658. {
  11659. isSuccess = ConfigurationStatus_Rejected;
  11660. }
  11661. }
  11662. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11663. {
  11664. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11665. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11666. {
  11667. strcpy(str, (const char*)value);
  11668. for(int i = 0; str[i]; i++){
  11669. str[i] = tolower(str[i]);
  11670. }
  11671. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11672. isSuccess = ConfigurationStatus_Accepted;
  11673. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11674. }
  11675. else
  11676. {
  11677. isSuccess = ConfigurationStatus_Rejected;
  11678. }
  11679. }
  11680. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11681. {
  11682. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11683. {
  11684. strcpy(str, (const char*)value);
  11685. for(int i = 0; str[i]; i++)
  11686. {
  11687. str[i] = tolower(str[i]);
  11688. }
  11689. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11690. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11691. isSuccess = ConfigurationStatus_Accepted;
  11692. }
  11693. else
  11694. {
  11695. isSuccess = ConfigurationStatus_Rejected;
  11696. }
  11697. }
  11698. if(strcmp(key, "BlinkRepeat") == 0)
  11699. {
  11700. //Charger.BlinkRepeat = Integer.parseInt(value);
  11701. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11702. {
  11703. check_ascii = value[0];
  11704. if( (check_ascii < 48) || (check_ascii > 57) )
  11705. {
  11706. isSuccess = ConfigurationStatus_Rejected;
  11707. }
  11708. else
  11709. {
  11710. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11711. isSuccess = ConfigurationStatus_Accepted;
  11712. }
  11713. }
  11714. else
  11715. {
  11716. isSuccess = ConfigurationStatus_Rejected;
  11717. }
  11718. }
  11719. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11720. {
  11721. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11722. {
  11723. check_ascii = value[0];
  11724. if( (check_ascii < 48) || (check_ascii > 57) )
  11725. {
  11726. isSuccess = ConfigurationStatus_Rejected;
  11727. }
  11728. else
  11729. {
  11730. if((atoi(value) == 0) || (atoi(value) >= 10))
  11731. {
  11732. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11733. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11734. isSuccess = ConfigurationStatus_Accepted;
  11735. }
  11736. else
  11737. isSuccess = ConfigurationStatus_Rejected;
  11738. }
  11739. }
  11740. else
  11741. {
  11742. isSuccess = ConfigurationStatus_Rejected;
  11743. }
  11744. }
  11745. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11746. {
  11747. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11748. {
  11749. check_ascii = value[0];
  11750. if( (check_ascii < 48) || (check_ascii > 57) )
  11751. {
  11752. isSuccess = ConfigurationStatus_Rejected;
  11753. }
  11754. else
  11755. {
  11756. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11757. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11758. isSuccess = ConfigurationStatus_Accepted;
  11759. }
  11760. }
  11761. else
  11762. {
  11763. isSuccess = ConfigurationStatus_Rejected;
  11764. }
  11765. }
  11766. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11767. {
  11768. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11769. {
  11770. check_ascii = value[0];
  11771. if( (check_ascii < 48) || (check_ascii > 57) )
  11772. {
  11773. isSuccess = ConfigurationStatus_Rejected;
  11774. }
  11775. else
  11776. {
  11777. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11778. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11779. isSuccess = ConfigurationStatus_Accepted;
  11780. }
  11781. }
  11782. else
  11783. {
  11784. isSuccess = ConfigurationStatus_Rejected;
  11785. }
  11786. }
  11787. if(strcmp(key, "HeartbeatInterval") == 0)
  11788. {
  11789. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11790. {
  11791. check_ascii = value[0];
  11792. if( (check_ascii < 48) || (check_ascii > 57) )
  11793. {
  11794. isSuccess = ConfigurationStatus_Rejected;
  11795. }
  11796. else
  11797. {
  11798. if((atoi(value) == 0) || (atoi(value) >= 10))
  11799. {
  11800. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11801. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11802. HeartBeatWaitTime = atoi(value);
  11803. isSuccess = ConfigurationStatus_Accepted;
  11804. }
  11805. else
  11806. {
  11807. isSuccess = ConfigurationStatus_Rejected;
  11808. }
  11809. }
  11810. }
  11811. else
  11812. {
  11813. isSuccess = ConfigurationStatus_Rejected;
  11814. }
  11815. }
  11816. if(strcmp(key, "LightIntensity") == 0)
  11817. {
  11818. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11819. {
  11820. check_ascii = value[0];
  11821. if( (check_ascii < 48) || (check_ascii > 57) )
  11822. {
  11823. isSuccess = ConfigurationStatus_Rejected;
  11824. }
  11825. else
  11826. {
  11827. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11828. isSuccess = ConfigurationStatus_Accepted;
  11829. }
  11830. }
  11831. else
  11832. {
  11833. isSuccess = ConfigurationStatus_Rejected;
  11834. }
  11835. }
  11836. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11837. {
  11838. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11839. {
  11840. strcpy(str, (const char*)value);
  11841. for(int i = 0; str[i]; i++)
  11842. {
  11843. str[i] = tolower(str[i]);
  11844. }
  11845. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11846. isSuccess = ConfigurationStatus_Accepted;
  11847. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11848. }
  11849. else
  11850. {
  11851. isSuccess = ConfigurationStatus_Rejected;
  11852. }
  11853. }
  11854. if(strcmp(key, "LocalPreAuthorize") == 0)
  11855. {
  11856. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11857. {
  11858. strcpy(str, (const char*)value);
  11859. for(int i = 0; str[i]; i++)
  11860. {
  11861. str[i] = tolower(str[i]);
  11862. }
  11863. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11864. isSuccess = ConfigurationStatus_Accepted;
  11865. }
  11866. else
  11867. {
  11868. isSuccess = ConfigurationStatus_Rejected;
  11869. }
  11870. }
  11871. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11872. {
  11873. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11874. {
  11875. check_ascii = value[0];
  11876. if( (check_ascii < 48) || (check_ascii > 57) )
  11877. {
  11878. isSuccess = ConfigurationStatus_Rejected;
  11879. }
  11880. else
  11881. {
  11882. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11883. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11884. isSuccess = ConfigurationStatus_Accepted;
  11885. }
  11886. }
  11887. else
  11888. {
  11889. isSuccess = ConfigurationStatus_Rejected;
  11890. }
  11891. }
  11892. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11893. {
  11894. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11895. {
  11896. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11897. isSuccess = ConfigurationStatus_Accepted;
  11898. }
  11899. else
  11900. {
  11901. isSuccess = ConfigurationStatus_Rejected;
  11902. }
  11903. }
  11904. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11905. {
  11906. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11907. {
  11908. check_ascii = value[0];
  11909. if( (check_ascii < 48) || (check_ascii > 57) )
  11910. {
  11911. isSuccess = ConfigurationStatus_Rejected;
  11912. }
  11913. else
  11914. {
  11915. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11916. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11917. isSuccess = ConfigurationStatus_Accepted;
  11918. }
  11919. }
  11920. else
  11921. {
  11922. isSuccess = ConfigurationStatus_Rejected;
  11923. }
  11924. }
  11925. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11926. {
  11927. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11928. {
  11929. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11930. isSuccess = ConfigurationStatus_Accepted;
  11931. }
  11932. else
  11933. {
  11934. isSuccess = ConfigurationStatus_Rejected;
  11935. }
  11936. }
  11937. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11938. {
  11939. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].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. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11949. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11950. isSuccess = ConfigurationStatus_Accepted;
  11951. }
  11952. }
  11953. else
  11954. {
  11955. isSuccess = ConfigurationStatus_Rejected;
  11956. }
  11957. }
  11958. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11959. {
  11960. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11961. {
  11962. check_ascii = value[0];
  11963. if( (check_ascii < 48) || (check_ascii > 57) )
  11964. {
  11965. isSuccess = ConfigurationStatus_Rejected;
  11966. }
  11967. else
  11968. {
  11969. if((atoi(value) == 0) || (atoi(value) >= 10))
  11970. {
  11971. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11972. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11973. isSuccess = ConfigurationStatus_Accepted;
  11974. }
  11975. else
  11976. {
  11977. isSuccess = ConfigurationStatus_Rejected;
  11978. }
  11979. }
  11980. }
  11981. else
  11982. {
  11983. isSuccess = ConfigurationStatus_Rejected;
  11984. }
  11985. }
  11986. if(strcmp(key, "MinimumStatusDuration") == 0)
  11987. {
  11988. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11989. {
  11990. check_ascii = value[0];
  11991. if( (check_ascii < 48) || (check_ascii > 57) )
  11992. {
  11993. isSuccess = ConfigurationStatus_Rejected;
  11994. }
  11995. else
  11996. {
  11997. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  11998. {
  11999. isSuccess = ConfigurationStatus_Rejected;
  12000. }
  12001. else
  12002. {
  12003. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12004. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12005. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12006. isSuccess = ConfigurationStatus_Accepted;
  12007. }
  12008. }
  12009. }
  12010. else
  12011. {
  12012. isSuccess = ConfigurationStatus_Rejected;
  12013. }
  12014. }
  12015. if(strcmp(key, "NumberOfConnectors") == 0)
  12016. {
  12017. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12018. {
  12019. check_ascii = value[0];
  12020. if( (check_ascii < 48) || (check_ascii > 57) )
  12021. {
  12022. isSuccess = ConfigurationStatus_Rejected;
  12023. }
  12024. else
  12025. {
  12026. //Charger.ResetRetries = Integer.parseInt(value);
  12027. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12028. isSuccess = ConfigurationStatus_Accepted;
  12029. }
  12030. }
  12031. else
  12032. {
  12033. isSuccess = ConfigurationStatus_Rejected;
  12034. }
  12035. }
  12036. if(strcmp(key, "ResetRetries") == 0)
  12037. {
  12038. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12039. {
  12040. check_ascii = value[0];
  12041. if( (check_ascii < 48) || (check_ascii > 57) )
  12042. {
  12043. isSuccess = ConfigurationStatus_Rejected;
  12044. }
  12045. else
  12046. {
  12047. //Charger.ResetRetries = Integer.parseInt(value);
  12048. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12049. isSuccess = ConfigurationStatus_Accepted;
  12050. }
  12051. }
  12052. else
  12053. {
  12054. isSuccess = ConfigurationStatus_Rejected;
  12055. }
  12056. }
  12057. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12058. {
  12059. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12060. {
  12061. strcpy(str, (const char*)value);
  12062. for(int i = 0; str[i]; i++)
  12063. {
  12064. str[i] = tolower(str[i]);
  12065. }
  12066. if(strcmp(str, "notapplicable")== 0)
  12067. {
  12068. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12069. isSuccess = ConfigurationStatus_Accepted;
  12070. }
  12071. else if(strcmp(str, "unknown")== 0)
  12072. {
  12073. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12074. isSuccess = ConfigurationStatus_Accepted;
  12075. }
  12076. else if(strcmp(str, "rst")== 0)
  12077. {
  12078. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12079. isSuccess = ConfigurationStatus_Accepted;
  12080. }
  12081. else if(strcmp(str, "rts")== 0)
  12082. {
  12083. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12084. isSuccess = ConfigurationStatus_Accepted;
  12085. }
  12086. else if(strcmp(str, "srt")== 0)
  12087. {
  12088. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12089. isSuccess = ConfigurationStatus_Accepted;
  12090. }
  12091. else if(strcmp(str, "str")== 0)
  12092. {
  12093. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12094. isSuccess = ConfigurationStatus_Accepted;
  12095. }
  12096. else if(strcmp(str, "trs")== 0)
  12097. {
  12098. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12099. isSuccess = ConfigurationStatus_Accepted;
  12100. }
  12101. else if(strcmp(str, "tsr")== 0)
  12102. {
  12103. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12104. isSuccess = ConfigurationStatus_Accepted;
  12105. }
  12106. else
  12107. {
  12108. isSuccess = ConfigurationStatus_Rejected;
  12109. }
  12110. }
  12111. else
  12112. {
  12113. isSuccess = ConfigurationStatus_Rejected;
  12114. }
  12115. }
  12116. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12117. {
  12118. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12119. {
  12120. check_ascii = value[0];
  12121. if( (check_ascii < 48) || (check_ascii > 57) )
  12122. {
  12123. isSuccess = ConfigurationStatus_Rejected;
  12124. }
  12125. else
  12126. {
  12127. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12128. isSuccess = ConfigurationStatus_Accepted;
  12129. }
  12130. }
  12131. else
  12132. {
  12133. isSuccess = ConfigurationStatus_Rejected;
  12134. }
  12135. }
  12136. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12137. {
  12138. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12139. {
  12140. strcpy(str, (const char*)value);
  12141. for(int i = 0; str[i]; i++)
  12142. {
  12143. str[i] = tolower(str[i]);
  12144. }
  12145. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12146. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12147. isSuccess = ConfigurationStatus_Accepted;
  12148. }
  12149. else
  12150. {
  12151. isSuccess = ConfigurationStatus_Rejected;
  12152. }
  12153. }
  12154. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12155. {
  12156. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12157. {
  12158. strcpy(str, (const char*)value);
  12159. for(int i = 0; str[i]; i++)
  12160. {
  12161. str[i] = tolower(str[i]);
  12162. }
  12163. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12164. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12165. isSuccess = ConfigurationStatus_Accepted;
  12166. }
  12167. else
  12168. {
  12169. isSuccess = ConfigurationStatus_Rejected;
  12170. }
  12171. }
  12172. if(strcmp(key, "StopTxnAlignedData") == 0)
  12173. {
  12174. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12175. {
  12176. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12177. isSuccess = ConfigurationStatus_Accepted;
  12178. }
  12179. else
  12180. {
  12181. isSuccess = ConfigurationStatus_Rejected;
  12182. }
  12183. }
  12184. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12185. {
  12186. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12187. {
  12188. check_ascii = value[0];
  12189. if( (check_ascii < 48) || (check_ascii > 57) )
  12190. {
  12191. isSuccess = ConfigurationStatus_Rejected;
  12192. }
  12193. else
  12194. {
  12195. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12196. isSuccess = ConfigurationStatus_Accepted;
  12197. }
  12198. }
  12199. else
  12200. {
  12201. isSuccess = ConfigurationStatus_Rejected;
  12202. }
  12203. }
  12204. if(strcmp(key, "StopTxnSampledData") == 0)
  12205. {
  12206. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12207. {
  12208. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12209. isSuccess = ConfigurationStatus_Accepted;
  12210. }
  12211. else
  12212. {
  12213. isSuccess = ConfigurationStatus_Rejected;
  12214. }
  12215. }
  12216. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12217. {
  12218. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12219. {
  12220. check_ascii = value[0];
  12221. if( (check_ascii < 48) || (check_ascii > 57) )
  12222. {
  12223. isSuccess = ConfigurationStatus_Rejected;
  12224. }
  12225. else
  12226. {
  12227. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12228. isSuccess = ConfigurationStatus_Accepted;
  12229. }
  12230. }
  12231. else
  12232. {
  12233. isSuccess = ConfigurationStatus_Rejected;
  12234. }
  12235. }
  12236. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12237. {
  12238. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12239. {
  12240. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12241. isSuccess = ConfigurationStatus_Accepted;
  12242. }
  12243. else
  12244. {
  12245. isSuccess = ConfigurationStatus_Rejected;
  12246. }
  12247. }
  12248. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12249. {
  12250. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12251. {
  12252. check_ascii = value[0];
  12253. if( (check_ascii < 48) || (check_ascii > 57) )
  12254. {
  12255. isSuccess = ConfigurationStatus_Rejected;
  12256. }
  12257. else
  12258. {
  12259. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12260. isSuccess = ConfigurationStatus_Accepted;
  12261. }
  12262. }
  12263. else
  12264. {
  12265. isSuccess = ConfigurationStatus_Rejected;
  12266. }
  12267. }
  12268. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12269. {
  12270. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12271. {
  12272. check_ascii = value[0];
  12273. if( (check_ascii < 48) || (check_ascii > 57) )
  12274. {
  12275. isSuccess = ConfigurationStatus_Rejected;
  12276. }
  12277. else
  12278. {
  12279. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12280. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12281. TransactionMessageAttemptsValue = atoi(value);
  12282. isSuccess = ConfigurationStatus_Accepted;
  12283. }
  12284. }
  12285. else
  12286. {
  12287. isSuccess = ConfigurationStatus_Rejected;
  12288. }
  12289. }
  12290. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12291. {
  12292. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12293. {
  12294. check_ascii = value[0];
  12295. if( (check_ascii < 48) || (check_ascii > 57) )
  12296. {
  12297. isSuccess = ConfigurationStatus_Rejected;
  12298. }
  12299. else
  12300. {
  12301. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12302. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12303. TransactionMessageRetryIntervalValue = atoi(value);
  12304. isSuccess = ConfigurationStatus_Accepted;
  12305. }
  12306. }
  12307. else
  12308. {
  12309. isSuccess = ConfigurationStatus_Rejected;
  12310. }
  12311. }
  12312. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12313. {
  12314. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12315. {
  12316. strcpy(str, (const char*)value);
  12317. for(int i = 0; str[i]; i++)
  12318. {
  12319. str[i] = tolower(str[i]);
  12320. }
  12321. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12322. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12323. isSuccess = ConfigurationStatus_Accepted;
  12324. }
  12325. else
  12326. {
  12327. isSuccess = ConfigurationStatus_Rejected;
  12328. }
  12329. }
  12330. if(strcmp(key, "WebSocketPingInterval") == 0)
  12331. {
  12332. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12333. {
  12334. check_ascii = value[0];
  12335. if( (check_ascii < 48) || (check_ascii > 57) )
  12336. {
  12337. isSuccess = ConfigurationStatus_Rejected;
  12338. }
  12339. else
  12340. {
  12341. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12342. isSuccess = ConfigurationStatus_Accepted;
  12343. }
  12344. }
  12345. else
  12346. {
  12347. isSuccess = ConfigurationStatus_Rejected;
  12348. }
  12349. }
  12350. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12351. {
  12352. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12353. {
  12354. strcpy(str, (const char*)value);
  12355. for(int i = 0; str[i]; i++)
  12356. {
  12357. str[i] = tolower(str[i]);
  12358. }
  12359. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12360. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12361. isSuccess = ConfigurationStatus_Accepted;
  12362. }
  12363. else
  12364. {
  12365. isSuccess = ConfigurationStatus_Rejected;
  12366. }
  12367. }
  12368. #if 0
  12369. //For OCPP Test Case
  12370. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12371. {
  12372. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12373. {
  12374. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12375. isSuccess = ConfigurationStatus_Accepted;
  12376. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12377. }
  12378. else
  12379. {
  12380. isSuccess = ConfigurationStatus_Rejected;
  12381. }
  12382. }
  12383. #endif
  12384. #if 1
  12385. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12386. {
  12387. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12388. {
  12389. strcpy(str, (const char*)value);
  12390. for(int i = 0; str[i]; i++)
  12391. {
  12392. str[i] = tolower(str[i]);
  12393. }
  12394. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12395. isSuccess = ConfigurationStatus_Accepted;
  12396. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12397. }
  12398. else
  12399. {
  12400. isSuccess = ConfigurationStatus_Rejected;
  12401. }
  12402. }
  12403. #endif
  12404. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12405. {
  12406. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12407. {
  12408. check_ascii = value[0];
  12409. if( (check_ascii < 48) || (check_ascii > 57) )
  12410. {
  12411. isSuccess = ConfigurationStatus_Rejected;
  12412. }
  12413. else
  12414. {
  12415. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12416. isSuccess = ConfigurationStatus_Accepted;
  12417. }
  12418. }
  12419. else
  12420. {
  12421. isSuccess = ConfigurationStatus_Rejected;
  12422. }
  12423. }
  12424. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12425. {
  12426. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12427. {
  12428. check_ascii = value[0];
  12429. if( (check_ascii < 48) || (check_ascii > 57) )
  12430. {
  12431. isSuccess = ConfigurationStatus_Rejected;
  12432. }
  12433. else
  12434. {
  12435. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12436. isSuccess = ConfigurationStatus_Accepted;
  12437. }
  12438. }
  12439. else
  12440. {
  12441. isSuccess = ConfigurationStatus_Rejected;
  12442. }
  12443. }
  12444. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12445. {
  12446. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12447. {
  12448. strcpy(str, (const char*)value);
  12449. for(int i = 0; str[i]; i++)
  12450. {
  12451. str[i] = tolower(str[i]);
  12452. }
  12453. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12454. isSuccess = ConfigurationStatus_Accepted;
  12455. }
  12456. else
  12457. {
  12458. isSuccess = ConfigurationStatus_Rejected;
  12459. }
  12460. }
  12461. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12462. {
  12463. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12464. {
  12465. check_ascii = value[0];
  12466. if( (check_ascii < 48) || (check_ascii > 57) )
  12467. {
  12468. isSuccess = ConfigurationStatus_Rejected;
  12469. }
  12470. else
  12471. {
  12472. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12473. isSuccess = ConfigurationStatus_Accepted;
  12474. }
  12475. }
  12476. else
  12477. {
  12478. isSuccess = ConfigurationStatus_Rejected;
  12479. }
  12480. }
  12481. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12482. {
  12483. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12484. {
  12485. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12486. isSuccess = ConfigurationStatus_Accepted;
  12487. }
  12488. else
  12489. {
  12490. isSuccess = ConfigurationStatus_Rejected;
  12491. }
  12492. }
  12493. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12494. {
  12495. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12496. {
  12497. check_ascii = value[0];
  12498. if( (check_ascii < 48) || (check_ascii > 57) )
  12499. {
  12500. isSuccess = ConfigurationStatus_Rejected;
  12501. }
  12502. else
  12503. {
  12504. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12505. isSuccess = ConfigurationStatus_Accepted;
  12506. }
  12507. }
  12508. else
  12509. {
  12510. isSuccess = ConfigurationStatus_Rejected;
  12511. }
  12512. }
  12513. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12514. {
  12515. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12516. {
  12517. strcpy(str, (const char*)value);
  12518. for(int i = 0; str[i]; i++)
  12519. {
  12520. str[i] = tolower(str[i]);
  12521. }
  12522. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12523. isSuccess = ConfigurationStatus_Accepted;
  12524. }
  12525. else
  12526. {
  12527. isSuccess = ConfigurationStatus_Rejected;
  12528. }
  12529. }
  12530. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12531. {
  12532. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12533. {
  12534. check_ascii = value[0];
  12535. if( (check_ascii < 48) || (check_ascii > 57) )
  12536. {
  12537. isSuccess = ConfigurationStatus_Rejected;
  12538. }
  12539. else
  12540. {
  12541. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12542. isSuccess = ConfigurationStatus_Accepted;
  12543. }
  12544. }
  12545. else
  12546. {
  12547. isSuccess = ConfigurationStatus_Rejected;
  12548. }
  12549. }
  12550. return isSuccess;
  12551. }
  12552. int TransactionMessageAttemptsGet(void)
  12553. {
  12554. return TransactionMessageAttemptsValue;
  12555. }
  12556. int FirstHeartBeatResponse(void)
  12557. {
  12558. return FirstHeartBeat;
  12559. }
  12560. int TransactionMessageRetryIntervalGet(void)
  12561. {
  12562. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12563. }
  12564. int ReadHttpStatus(int sock)
  12565. {
  12566. //char c;
  12567. char buff[1024]="",*ptr=buff+1;
  12568. int bytes_received, status;
  12569. DEBUG_INFO("Begin Response ..\n");
  12570. while((bytes_received = recv(sock, ptr, 1, 0))){
  12571. if(bytes_received==-1){
  12572. perror("ReadHttpStatus");
  12573. exit(1);
  12574. }
  12575. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12576. ptr++;
  12577. }
  12578. *ptr=0;
  12579. ptr=buff+1;
  12580. sscanf(ptr,"%*s %d ", &status);
  12581. DEBUG_INFO("%s\n",ptr);
  12582. DEBUG_INFO("status=%d\n",status);
  12583. DEBUG_INFO("End Response ..\n");
  12584. return (bytes_received>0)?status:0;
  12585. }
  12586. //the only filed that it parsed is 'Content-Length'
  12587. int ParseHeader(int sock)
  12588. {
  12589. //char c;
  12590. char buff[1024]="",*ptr=buff+4;
  12591. int bytes_received;
  12592. DEBUG_INFO("Begin HEADER ..\n");
  12593. while((bytes_received = recv(sock, ptr, 1, 0))){
  12594. if(bytes_received==-1){
  12595. perror("Parse Header");
  12596. exit(1);
  12597. }
  12598. if(
  12599. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12600. (ptr[-1]=='\r') && (*ptr=='\n' )
  12601. ) break;
  12602. ptr++;
  12603. }
  12604. *ptr=0;
  12605. ptr=buff+4;
  12606. //printf("%s",ptr);
  12607. if(bytes_received){
  12608. ptr=strstr(ptr,"Content-Length:");
  12609. if(ptr){
  12610. sscanf(ptr,"%*s %d",&bytes_received);
  12611. }else
  12612. bytes_received=-1; //unknown size
  12613. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12614. }
  12615. DEBUG_INFO("End HEADER ..\n");
  12616. return bytes_received ;
  12617. }
  12618. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12619. {
  12620. char rmFileCmd[100]={0};
  12621. char FilePath[100]={0};
  12622. char ftpbuf[200];
  12623. int systemresult;
  12624. //DEBUG_INFO("filename=%s\n",filename);
  12625. //DEBUG_INFO("url=%s\n",url);
  12626. sprintf(FilePath,"/mnt/%s",filename);
  12627. if((access(FilePath,F_OK))!=-1)
  12628. {
  12629. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12630. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12631. system(rmFileCmd);
  12632. }
  12633. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12634. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12635. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12636. systemresult = system(ftpbuf);
  12637. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12638. if(systemresult != 0)
  12639. {
  12640. DEBUG_INFO("http DownLoad error!\n");
  12641. return FALSE;
  12642. }
  12643. return TRUE;
  12644. }
  12645. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12646. {
  12647. char rmFileCmd[100]={0};
  12648. char FilePath[100]={0};
  12649. char ftpbuf[200];
  12650. int systemresult;
  12651. //char temp[100];
  12652. sprintf(FilePath,"/mnt/%s",filename);
  12653. if((access(FilePath,F_OK))!=-1)
  12654. {
  12655. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12656. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12657. system(rmFileCmd);
  12658. }
  12659. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12660. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12661. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12662. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12663. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12664. systemresult = system(ftpbuf);
  12665. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12666. if(systemresult != 0)
  12667. {
  12668. printf("wget error!\n");
  12669. return FALSE;
  12670. }
  12671. return TRUE;
  12672. }
  12673. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12674. {
  12675. char rmFileCmd[100]={0};
  12676. char FilePath[100]={0};
  12677. char ftpbuf[200];
  12678. int systemresult;
  12679. //DEBUG_INFO("filename=%s\n",filename);
  12680. //DEBUG_INFO("url=%s\n",url);
  12681. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12682. if((access(FilePath,F_OK))!=-1)
  12683. {
  12684. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12685. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12686. system(rmFileCmd);
  12687. }
  12688. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12689. if(fp == NULL)
  12690. {
  12691. DEBUG_INFO("log is NULL\n");
  12692. return FALSE;
  12693. }
  12694. else
  12695. {
  12696. fprintf(fp, "%s\n", url);
  12697. fprintf(fp, "%s\n", filename);
  12698. fclose(fp);
  12699. }
  12700. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12701. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12702. systemresult = system(ftpbuf);
  12703. DEBUG_INFO("systemresult = %d\n",systemresult);
  12704. if(systemresult != 0)
  12705. {
  12706. DEBUG_INFO("http upload error!\n");
  12707. return FALSE;
  12708. }
  12709. return TRUE;
  12710. }
  12711. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12712. {
  12713. struct hostent* server;
  12714. char *IPbuffer;
  12715. char ftpbuf[200];
  12716. int systemresult;
  12717. // To retrieve host information
  12718. server = gethostbyname(location);
  12719. // To convert an Internet network
  12720. // address into ASCII string
  12721. IPbuffer = inet_ntoa(*((struct in_addr*)
  12722. server->h_addr_list[0]));
  12723. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12724. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12725. /* format : ftpput -u username -p passwd IP target source*/
  12726. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12727. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12728. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12729. systemresult = system(ftpbuf);
  12730. DEBUG_INFO("systemresult=%d\n",systemresult);
  12731. if(systemresult != 0)
  12732. {
  12733. DEBUG_INFO("ftpput error!\n");
  12734. return FALSE;
  12735. }
  12736. return TRUE;
  12737. }
  12738. /**
  12739. * Place the contents of the specified file into a memory buffer
  12740. *
  12741. * @param[in] filename The path and name of the file to read
  12742. * @param[out] filebuffer A pointer to the contents in memory
  12743. * @return status 0 success, 1 on failure
  12744. */
  12745. int get_file_contents(const char* filename, char** outbuffer) {
  12746. FILE* file = NULL;
  12747. long filesize;
  12748. const int blocksize = 1;
  12749. size_t readsize;
  12750. char* filebuffer;
  12751. // Open the file
  12752. file = fopen(filename, "r");
  12753. if (NULL == file)
  12754. {
  12755. printf("'%s' not opened\n", filename);
  12756. exit(EXIT_FAILURE);
  12757. }
  12758. // Determine the file size
  12759. fseek(file, 0, SEEK_END);
  12760. filesize = ftell(file);
  12761. rewind (file);
  12762. // Allocate memory for the file contents
  12763. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12764. *outbuffer = filebuffer;
  12765. if (filebuffer == NULL)
  12766. {
  12767. fputs ("malloc out-of-memory", stderr);
  12768. exit(EXIT_FAILURE);
  12769. }
  12770. // Read in the file
  12771. readsize = fread(filebuffer, blocksize, filesize, file);
  12772. if (readsize != filesize)
  12773. {
  12774. fputs ("didn't read file completely",stderr);
  12775. exit(EXIT_FAILURE);
  12776. }
  12777. // Clean exit
  12778. fclose(file);
  12779. return EXIT_SUCCESS;
  12780. }
  12781. static int selectSqlCount = 0;
  12782. static int callback(void *data, int argc, char **argv, char **azColName){
  12783. int i;
  12784. //printf("%s: ", (const char*)data);
  12785. selectSqlCount = argc;
  12786. for(i = 0; i<argc; i++){
  12787. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12788. }
  12789. //printf("\n");
  12790. return 0;
  12791. }
  12792. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12793. //int i;
  12794. //printf("%s:\n", (const char*)data);
  12795. localversion = argv[5] ? atoi(argv[5]) : 0;
  12796. //printf("localversion=%d\n", localversion);
  12797. return 0;
  12798. }
  12799. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12800. //int i;
  12801. //printf("%s:\n", (const char*)data);
  12802. //idTag
  12803. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12804. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12805. //parentIdTag
  12806. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12807. //expir_date
  12808. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12809. //status
  12810. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12811. //version
  12812. idTagQuery.listVersionInt = atoi(argv[5]);
  12813. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12814. return 0;
  12815. }
  12816. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12817. {
  12818. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12819. // printf("localversion=%d\n", localversion);
  12820. return 0;
  12821. }
  12822. //=========================================
  12823. // Sqlite3 related function
  12824. //=========================================
  12825. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12826. {
  12827. for (int i = 0; i < n_columns; i++)
  12828. {
  12829. DEBUG_INFO("%s\t", col_values[i]);
  12830. }
  12831. DEBUG_INFO("\n");
  12832. return 0;
  12833. }
  12834. void OCPP_getListVerion()
  12835. {
  12836. int rc = 0;
  12837. // const char* data = "Callback function called";
  12838. char sql[100];
  12839. char zErrMsg[100];
  12840. memset(sql, 0, 100);
  12841. memset(zErrMsg, 0, 100);
  12842. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12843. /* Execute SQL statement */
  12844. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12845. if( rc != SQLITE_OK )
  12846. {
  12847. DEBUG_INFO("SQL error: %s", zErrMsg);
  12848. }
  12849. }
  12850. void OCPP_getIdTag(char idTag[])
  12851. {
  12852. int rc = 0;
  12853. // const char* data = "Callback function called";
  12854. char sql[100];
  12855. char zErrMsg[100];
  12856. memset(sql, 0, 100);
  12857. memset(zErrMsg, 0, 100);
  12858. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  12859. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12860. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12861. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12862. /* Execute SQL statement */
  12863. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12864. if( rc != SQLITE_OK )
  12865. {
  12866. DEBUG_INFO("SQL error: %s", zErrMsg);
  12867. }
  12868. //return ver;
  12869. }
  12870. void OCPP_get_TableAuthlocalAllData(void)
  12871. {
  12872. int rc = 0;
  12873. char sql[100];
  12874. char zErrMsg[100];
  12875. memset(sql, 0, 100);
  12876. memset(zErrMsg, 0, 100);
  12877. sprintf(sql,"select * from ocpp_auth_local ");
  12878. /* Execute SQL statement */
  12879. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12880. if( rc != SQLITE_OK )
  12881. {
  12882. DEBUG_INFO("SQL error: %s", zErrMsg);
  12883. }
  12884. //return ver;
  12885. }
  12886. int OCPP_cleanLocalList()
  12887. {
  12888. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12889. char *errMsg = 0;
  12890. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12891. if (SQLITE_OK != rc)
  12892. {
  12893. DEBUG_INFO("%s\n",errMsg);
  12894. return FALSE;
  12895. }
  12896. return TRUE;
  12897. }
  12898. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12899. {
  12900. int isSuccess = FALSE;
  12901. int ret = 0;
  12902. //const char* data = "Callback function called";
  12903. char sql[300];
  12904. char zErrMsg[200];
  12905. memset(sql, 0, 300);
  12906. memset(zErrMsg, 0, 200);
  12907. 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);
  12908. //* Execute SQL statement */
  12909. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12910. if( ret != SQLITE_OK )
  12911. {
  12912. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12913. return isSuccess;
  12914. }
  12915. memset(sql, 0, 300);
  12916. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  12917. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  12918. if( ret != SQLITE_OK )
  12919. {
  12920. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12921. return isSuccess;
  12922. }
  12923. isSuccess = TRUE;
  12924. return isSuccess;
  12925. }
  12926. void OCPP_deleteIdTag(char idTag[])
  12927. {
  12928. //int ver = 0;
  12929. //int isSuccess = FALSE;
  12930. int rc = 0;
  12931. char sql[100];
  12932. char zErrMsg[100];
  12933. memset(sql, 0, 100);
  12934. memset(zErrMsg, 0, 100);
  12935. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12936. //* Execute SQL statement */
  12937. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12938. if( rc != SQLITE_OK )
  12939. {
  12940. DEBUG_INFO("SQL error: %s", zErrMsg);
  12941. }
  12942. }
  12943. int GetOcppServerURL()
  12944. {
  12945. int result = FALSE;
  12946. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  12947. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  12948. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  12949. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12950. {
  12951. #if 1
  12952. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12953. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12954. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12955. #endif
  12956. result = TRUE;
  12957. goto End;
  12958. }
  12959. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12960. {
  12961. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12962. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12963. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12964. result = TRUE;
  12965. goto End;
  12966. }
  12967. else
  12968. {
  12969. strcpy(OcppHost,"");
  12970. }
  12971. End:
  12972. return result;
  12973. }
  12974. int GetOcppPath()
  12975. {
  12976. int result = FALSE;
  12977. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12978. {
  12979. if(OcppTempPath == NULL)
  12980. {
  12981. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12982. }
  12983. else
  12984. {
  12985. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12986. }
  12987. result = TRUE;
  12988. goto End;
  12989. }
  12990. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12991. {
  12992. if(OcppTempPath == NULL)
  12993. {
  12994. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12995. }
  12996. else
  12997. {
  12998. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12999. }
  13000. result = TRUE;
  13001. goto End;
  13002. }
  13003. else
  13004. {
  13005. strcpy(OcppPath,"");
  13006. }
  13007. End:
  13008. return result;
  13009. }
  13010. int GetOcppPort()
  13011. {
  13012. return OcppPort;
  13013. }
  13014. int GetOcppConnStatus(void)
  13015. {
  13016. return ShmOCPP16Data->OcppConnStatus;
  13017. }
  13018. void SetOcppConnStatus(uint8_t status)
  13019. {
  13020. ShmOCPP16Data->OcppConnStatus = status;
  13021. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13022. }
  13023. int GetHeartBeatWithNOResponse(void)
  13024. {
  13025. return HeartBeatWithNOResponse;
  13026. }
  13027. void SetHeartBeatWithNOResponse(void)
  13028. {
  13029. HeartBeatWithNOResponse = 0;
  13030. }
  13031. void GetStartTransactionIdTag(int gun_index)
  13032. {
  13033. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13034. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13035. }
  13036. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13037. {
  13038. char ch;
  13039. FILE *fptr1;
  13040. int temptransactionId;
  13041. char str[100]={0};
  13042. temptransactionId = 0;
  13043. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  13044. {
  13045. DEBUG_INFO("IdTag is empty.\n");
  13046. return temptransactionId;
  13047. }
  13048. /*------ Read the file ----------------*/
  13049. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13050. if (!fptr1)
  13051. {
  13052. DEBUG_INFO("QueueTransactionId file open error.\n");
  13053. //printf(" File not found or unable to open the input file!!\n");
  13054. return temptransactionId;
  13055. }
  13056. ch=fgetc(fptr1);
  13057. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13058. rewind(fptr1);
  13059. if(ch!=EOF)
  13060. {
  13061. // printf("%c",ch);
  13062. while (fgets(str, 100, fptr1) != NULL)
  13063. {
  13064. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13065. if(str[0]=='\0')
  13066. {
  13067. break;
  13068. }
  13069. char *revbuf[8] = {0}; //存放分割後的子字串
  13070. int num = 0;//分割後子字串的個數
  13071. DEBUG_INFO("str: %s\n", str);
  13072. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13073. DEBUG_INFO("revbuf[0]: %s\n", revbuf[0]);
  13074. DEBUG_INFO("revbuf[1]: %s\n", revbuf[1]);
  13075. DEBUG_INFO("revbuf[2]: %s\n", revbuf[2]);
  13076. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13077. {
  13078. if(isStopTransaction)
  13079. {
  13080. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13081. {
  13082. temptransactionId = atoi(revbuf[2]);
  13083. break;
  13084. }
  13085. }
  13086. else
  13087. {
  13088. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13089. {
  13090. temptransactionId = atoi(revbuf[2]);
  13091. break;
  13092. }
  13093. }
  13094. }
  13095. }
  13096. }
  13097. else
  13098. DEBUG_INFO("EOF\n");
  13099. fclose(fptr1);
  13100. /*------- End of reading ---------------*/
  13101. return temptransactionId;
  13102. }
  13103. void SetTransactionIdZero(int transactionId)
  13104. {
  13105. char ch;
  13106. FILE *fptr1, *fptr2;
  13107. int temptransactionId = 0;
  13108. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13109. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13110. if (!fptr1)
  13111. {
  13112. //printf(" File not found or unable to open the input file!!\n");
  13113. return ;
  13114. }
  13115. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13116. if (!fptr2)
  13117. {
  13118. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13119. fclose(fptr1);
  13120. return ;
  13121. }
  13122. ch=fgetc(fptr1);
  13123. rewind(fptr1);
  13124. if(ch!=EOF)
  13125. {
  13126. // copy all contents to the temporary file except the specific line
  13127. while (fgets(str, 100, fptr1) != NULL)
  13128. {
  13129. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13130. if(str[0]=='\0')
  13131. {
  13132. break;
  13133. }
  13134. char *revbuf[8] = {0};
  13135. int num = 0;
  13136. strcpy(strtemp, str);
  13137. splitstring(str,",",revbuf,&num);
  13138. if(revbuf[2][0] != '\0')
  13139. {
  13140. temptransactionId = atoi(revbuf[2]);
  13141. if(transactionId != temptransactionId)
  13142. {
  13143. fprintf(fptr2, "%s\n", strtemp);
  13144. }
  13145. }
  13146. }
  13147. }
  13148. fclose(fptr1);
  13149. fclose(fptr2);
  13150. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13151. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13152. /*------ Read the file ----------------*/
  13153. }
  13154. int InternetDisconnect(void)
  13155. {
  13156. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13157. }
  13158. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13159. void storeTempStopTransaction(int gun_index)
  13160. {
  13161. char guid[37]={0};
  13162. int tempIndex = 0;
  13163. char TempStopTransaction[256];
  13164. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13165. DEBUG_INFO("storeTempStopTransaction...\n");
  13166. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13167. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13168. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13169. if(gunType[gun_index] == 'J')
  13170. {
  13171. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13172. {
  13173. tempIndex = ((gun_index==2) ? 1: 0);
  13174. }
  13175. else
  13176. {
  13177. tempIndex = gun_index;
  13178. }
  13179. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13180. {
  13181. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13182. {
  13183. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13184. }
  13185. }// END OF CHAdeMO_QUANTITY
  13186. }
  13187. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13188. {
  13189. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13190. {
  13191. tempIndex = ((gun_index==2) ? 1: 0);
  13192. }
  13193. else
  13194. {
  13195. tempIndex = gun_index;
  13196. }
  13197. for (int index = 0; index < CCS_QUANTITY; index++)
  13198. {
  13199. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13200. {
  13201. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13202. }
  13203. }// END OF CCS_QUANTITY
  13204. }
  13205. else if(gunType[gun_index] == 'G')
  13206. {
  13207. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13208. {
  13209. tempIndex = ((gun_index==2) ? 1: 0);
  13210. }
  13211. else
  13212. {
  13213. tempIndex = gun_index;
  13214. }
  13215. for (int index = 0; index < GB_QUANTITY; index++)
  13216. {
  13217. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13218. {
  13219. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13220. }
  13221. }// END OF GB_QUANTITY
  13222. }
  13223. else
  13224. {
  13225. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13226. {
  13227. tempIndex = 2;
  13228. }
  13229. else
  13230. {
  13231. tempIndex = gun_index;
  13232. }
  13233. for (int index = 0; index < AC_QUANTITY; index++)
  13234. {
  13235. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13236. {
  13237. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13238. }
  13239. }// END OF AC_QUANTITY
  13240. }
  13241. //Stop Transaction Time
  13242. struct timeval tmnow;
  13243. struct tm *tm;
  13244. char buf[28];//, usec_buf[6];
  13245. gettimeofday(&tmnow, NULL);
  13246. time_t t;
  13247. t = time(NULL);
  13248. /*UTC time and date*/
  13249. tm = gmtime(&t);
  13250. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13251. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13252. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13253. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13254. random_uuid(guid);
  13255. /***********************************transactionData******************************************************/
  13256. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13258. //=================================
  13259. //1. Transaction_Begin
  13260. //=================================
  13261. //============================== Energy.Active.Import.Interval ===========================================
  13262. //idx_sample=0;
  13263. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  13264. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13265. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13266. 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*/]);
  13267. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13268. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13269. {
  13270. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13271. }
  13272. else
  13273. {
  13274. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13275. }
  13276. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13277. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13278. //=================================
  13279. //2. Transaction_End
  13280. //=================================
  13281. //2.1====================================== Current.Import L1 ==============================================
  13282. //idx_sample=1;
  13283. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13284. if(gunType[gun_index] == 'J')
  13285. {
  13286. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13287. {
  13288. tempIndex = ((gun_index==2) ? 1: 0);
  13289. }
  13290. else
  13291. {
  13292. tempIndex = gun_index;
  13293. }
  13294. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13295. {
  13296. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13297. {
  13298. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13299. }
  13300. }// End of for CHAdeMO_QUANTITY
  13301. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13302. }
  13303. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13304. {
  13305. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13306. {
  13307. tempIndex = ((gun_index==2) ? 1: 0);
  13308. }
  13309. else
  13310. {
  13311. tempIndex = gun_index;
  13312. }
  13313. for (int index = 0; index < CCS_QUANTITY; index++)
  13314. {
  13315. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13316. {
  13317. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13318. }
  13319. }// End of for CCS_QUANTITY
  13320. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13321. }
  13322. else if(gunType[gun_index] == 'G')
  13323. {
  13324. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13325. {
  13326. tempIndex = ((gun_index==2) ? 1: 0);
  13327. }
  13328. else
  13329. {
  13330. tempIndex = gun_index;
  13331. }
  13332. for (int index = 0; index < GB_QUANTITY; index++)
  13333. {
  13334. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13335. {
  13336. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13337. }
  13338. }// End of for GB_QUANTITY
  13339. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13340. }
  13341. else
  13342. {
  13343. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13344. {
  13345. tempIndex = 2;
  13346. }
  13347. else
  13348. {
  13349. tempIndex = gun_index;
  13350. }
  13351. for (int index = 0; index < AC_QUANTITY; index++)
  13352. {
  13353. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13354. {
  13355. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13356. }
  13357. }// End of for AC_QUANTITY
  13358. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13359. }
  13360. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13361. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13363. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13364. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13365. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13366. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13367. //idx_sample=2;
  13368. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13369. if(gunType[gun_index] == 'J')
  13370. {
  13371. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13372. {
  13373. tempIndex = ((gun_index==2) ? 1: 0);
  13374. }
  13375. else
  13376. {
  13377. tempIndex = gun_index;
  13378. }
  13379. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13380. {
  13381. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13382. {
  13383. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13384. }
  13385. }// END OF CHAdeMO_QUANTITY
  13386. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13387. }
  13388. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13389. {
  13390. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13391. {
  13392. tempIndex = ((gun_index==2) ? 1: 0);
  13393. }
  13394. else
  13395. {
  13396. tempIndex = gun_index;
  13397. }
  13398. for (int index = 0; index < CCS_QUANTITY; index++)
  13399. {
  13400. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13401. {
  13402. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13403. }
  13404. }// END OF CCS_QUANTITY
  13405. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13406. }
  13407. else if(gunType[gun_index] == 'G')
  13408. {
  13409. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13410. {
  13411. tempIndex = ((gun_index==2) ? 1: 0);
  13412. }
  13413. else
  13414. {
  13415. tempIndex = gun_index;
  13416. }
  13417. for (int index = 0; index < GB_QUANTITY; index++)
  13418. {
  13419. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13420. {
  13421. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13422. }
  13423. }// END OF GB_QUANTITY
  13424. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13425. }
  13426. else
  13427. {
  13428. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13429. {
  13430. tempIndex = 2;
  13431. }
  13432. else
  13433. {
  13434. tempIndex = gun_index;
  13435. }
  13436. for (int index = 0; index < AC_QUANTITY; index++)
  13437. {
  13438. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13439. {
  13440. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13441. }
  13442. }// END OF AC_QUANTITY
  13443. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13444. }
  13445. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13446. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13447. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13448. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13449. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13450. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13451. //2.3====================================== Power.Active.Import =========================================
  13452. //idx_sample=3;
  13453. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13454. if(gunType[gun_index] == 'J')
  13455. {
  13456. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13457. {
  13458. tempIndex = ((gun_index==2) ? 1: 0);
  13459. }
  13460. else
  13461. {
  13462. tempIndex = gun_index;
  13463. }
  13464. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13465. {
  13466. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13467. {
  13468. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13469. }
  13470. } // End for CHAdeMO_QUANTITY
  13471. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13472. }
  13473. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13474. {
  13475. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13476. {
  13477. tempIndex = ((gun_index==2) ? 1: 0);
  13478. }
  13479. else
  13480. {
  13481. tempIndex = gun_index;
  13482. }
  13483. for (int index = 0; index < CCS_QUANTITY; index++)
  13484. {
  13485. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13486. {
  13487. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13488. }
  13489. } // END for CCS_QUANTITY
  13490. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13491. }
  13492. else if(gunType[gun_index] == 'G')
  13493. {
  13494. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13495. {
  13496. tempIndex = ((gun_index==2) ? 1: 0);
  13497. }
  13498. else
  13499. {
  13500. tempIndex = gun_index;
  13501. }
  13502. for (int index = 0; index < GB_QUANTITY; index++)
  13503. {
  13504. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13505. {
  13506. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13507. }
  13508. }// END for GB_QUANTITY
  13509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13510. }
  13511. else
  13512. {
  13513. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13514. {
  13515. tempIndex = 2;
  13516. }
  13517. else
  13518. {
  13519. tempIndex = gun_index;
  13520. }
  13521. for (int index = 0; index < AC_QUANTITY; index++)
  13522. {
  13523. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13524. {
  13525. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13526. }
  13527. } // END for AC_QUANTITY
  13528. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13529. }
  13530. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13531. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13532. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13533. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13534. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13535. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13536. //2.4====================================== Voltage L1 ====================================================
  13537. //idx_sample=4;
  13538. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13539. if(gunType[gun_index] == 'J')
  13540. {
  13541. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13542. {
  13543. tempIndex = ((gun_index==2) ? 1: 0);
  13544. }
  13545. else
  13546. {
  13547. tempIndex = gun_index;
  13548. }
  13549. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13550. {
  13551. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13552. {
  13553. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13554. }
  13555. } // END OF FOR CHAdeMO_QUANTITY
  13556. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13557. }
  13558. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13559. {
  13560. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13561. {
  13562. tempIndex = ((gun_index==2) ? 1: 0);
  13563. }
  13564. else
  13565. {
  13566. tempIndex = gun_index;
  13567. }
  13568. for (int index = 0; index < CCS_QUANTITY; index++)
  13569. {
  13570. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13571. {
  13572. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13573. }
  13574. } // END OF FOR CCS_QUANTITY
  13575. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13576. }
  13577. else if(gunType[gun_index] == 'G')
  13578. {
  13579. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13580. {
  13581. tempIndex = ((gun_index==2) ? 1: 0);
  13582. }
  13583. else
  13584. {
  13585. tempIndex = gun_index;
  13586. }
  13587. for (int index = 0; index < GB_QUANTITY; index++)
  13588. {
  13589. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13590. {
  13591. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13592. }
  13593. } // END OF FOR GB_QUANTITY
  13594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13595. }
  13596. else
  13597. {
  13598. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13599. {
  13600. tempIndex = 2;
  13601. }
  13602. else
  13603. {
  13604. tempIndex = gun_index;
  13605. }
  13606. for (int index = 0; index < AC_QUANTITY; index++)
  13607. {
  13608. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13609. {
  13610. 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
  13611. }
  13612. } // END OF FOR AC_QUANTITY
  13613. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13614. }
  13615. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13617. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13618. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13619. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13620. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13621. //2.5============================================== SoC =========================================================
  13622. //idx_sample=5;
  13623. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13624. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13625. {
  13626. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13627. {
  13628. tempIndex = ((gun_index==2) ? 1: 0);
  13629. }
  13630. else
  13631. {
  13632. tempIndex = gun_index;
  13633. }
  13634. if(gunType[gun_index] == 'J')
  13635. {
  13636. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13637. {
  13638. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13639. {
  13640. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13641. }
  13642. }
  13643. }
  13644. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13645. {
  13646. for (int index = 0; index < CCS_QUANTITY; index++)
  13647. {
  13648. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13649. {
  13650. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13651. }
  13652. }
  13653. }
  13654. else if(gunType[gun_index] == 'G')
  13655. {
  13656. for (int index = 0; index < GB_QUANTITY; index++)
  13657. {
  13658. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13659. {
  13660. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13661. }
  13662. }
  13663. }
  13664. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13665. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13666. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13667. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13668. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  13669. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13670. } // END FOR DC CASE
  13671. //2.6====================================== Current.Import L2 ==============================================
  13672. // idx_sample=6;
  13673. // AC 3 phase L2 current
  13674. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13675. {
  13676. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13677. {
  13678. tempIndex = 2;
  13679. }
  13680. else
  13681. {
  13682. tempIndex = gun_index;
  13683. }
  13684. for (int index = 0; index < AC_QUANTITY; index++)
  13685. {
  13686. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13687. {
  13688. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  13689. }
  13690. }// End of for AC_QUANTITY
  13691. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  13692. }
  13693. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13694. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  13695. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  13696. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  13697. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13698. //2.7====================================== Current.Import L3 ==============================================
  13699. // idx_sample=7;
  13700. // AC 3 phase L3 current
  13701. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13702. {
  13703. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13704. {
  13705. tempIndex = 2;
  13706. }
  13707. else
  13708. {
  13709. tempIndex = gun_index;
  13710. }
  13711. for (int index = 0; index < AC_QUANTITY; index++)
  13712. {
  13713. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13714. {
  13715. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  13716. }
  13717. }// End of for AC_QUANTITY
  13718. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  13719. }
  13720. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13721. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  13722. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  13723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  13724. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13725. //2.9====================================== Voltage L2 ====================================================
  13726. //idx_sample=8;
  13727. // AC 3 phase L2 volatge
  13728. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13729. {
  13730. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13731. {
  13732. tempIndex = 2;
  13733. }
  13734. else
  13735. {
  13736. tempIndex = gun_index;
  13737. }
  13738. for (int index = 0; index < AC_QUANTITY; index++)
  13739. {
  13740. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13741. {
  13742. 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
  13743. }
  13744. } // END OF FOR AC_QUANTITY
  13745. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  13746. }
  13747. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13748. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  13749. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  13750. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  13751. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13752. //2.10====================================== Voltage L3 ====================================================
  13753. //idx_sample=9;
  13754. // AC 3 phase L3 volatge
  13755. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13756. {
  13757. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13758. {
  13759. tempIndex = 2;
  13760. }
  13761. else
  13762. {
  13763. tempIndex = gun_index;
  13764. }
  13765. for (int index = 0; index < AC_QUANTITY; index++)
  13766. {
  13767. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13768. {
  13769. 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
  13770. }
  13771. } // END OF FOR AC_QUANTITY
  13772. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  13773. }
  13774. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13775. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  13776. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  13777. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  13778. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13779. //======================================== Message create ==============================================
  13780. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13781. {
  13782. 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\"}]}]}]"
  13783. ,gun_index+1
  13784. ,MESSAGE_TYPE_CALL
  13785. ,guid
  13786. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13787. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13788. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13789. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13790. ,"PowerLoss"
  13791. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13792. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13793. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13794. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13795. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13796. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13797. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13798. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13799. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13800. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13801. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13802. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13803. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13804. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13805. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13806. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13807. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13808. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13809. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13810. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13811. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13812. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13813. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13814. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13815. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13816. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13817. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13818. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13819. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13820. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13821. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13822. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13823. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13824. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13825. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13826. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13827. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  13828. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  13829. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  13830. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  13831. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  13832. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  13833. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  13834. );
  13835. }
  13836. else
  13837. {
  13838. if(((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W')))
  13839. {
  13840. 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\"}]}]}]"
  13841. ,gun_index+1
  13842. ,MESSAGE_TYPE_CALL
  13843. ,guid
  13844. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13845. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13846. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13847. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13848. ,"PowerLoss"
  13849. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13850. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13851. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13852. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13853. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13854. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13855. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13856. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13857. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13858. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13859. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13860. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13861. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13862. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13863. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13864. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13865. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13866. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13867. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13868. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13869. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13870. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13871. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13885. );
  13886. }
  13887. else
  13888. {
  13889. 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\"}]}]}]"
  13890. ,gun_index+1
  13891. ,MESSAGE_TYPE_CALL
  13892. ,guid
  13893. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13894. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13895. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13896. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13897. ,"PowerLoss"
  13898. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13899. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13900. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13901. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13902. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13903. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13904. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13905. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13906. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13907. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13908. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13909. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13910. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13911. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13912. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13913. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13914. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13915. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13916. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13917. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13918. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13919. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13920. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13921. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13922. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13923. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13924. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13925. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13926. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13927. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13928. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13929. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13930. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13931. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13932. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13933. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13934. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  13935. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  13936. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  13937. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  13938. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  13939. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  13940. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  13941. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  13942. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  13943. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  13944. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  13945. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  13946. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  13947. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  13948. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  13949. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  13950. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  13951. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  13952. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  13953. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  13954. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  13955. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  13956. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  13957. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  13958. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  13959. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  13960. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  13961. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  13962. );
  13963. }
  13964. }
  13965. // Check File "TempStopTransaction" Exist
  13966. if((access(TempStopTransaction,F_OK))!=-1)
  13967. {
  13968. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  13969. fclose(fopen(TempStopTransaction, "w"));
  13970. }
  13971. else
  13972. {
  13973. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  13974. FILE *log = fopen(TempStopTransaction, "w+");
  13975. if(log == NULL)
  13976. {
  13977. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  13978. return ;
  13979. }
  13980. else
  13981. {
  13982. fclose(log);
  13983. }
  13984. }
  13985. //Add TempStopTransaction | Update TempStopTransaction
  13986. // open file for writing
  13987. FILE *outfile;
  13988. outfile = fopen (TempStopTransaction, "a");
  13989. //DEBUG_INFO("data = %s\n", queuedata);
  13990. fputs(queuedata, outfile);
  13991. fputs("\n", outfile);
  13992. fclose (outfile);
  13993. }
  13994. void checkTempStopTransaction(int gun_index)
  13995. {
  13996. FILE *fptr1;
  13997. char ch;
  13998. char str[QUEUE_MESSAGE_LENGTH]={0};
  13999. char guid[37]={0};
  14000. char tempdata[65]={0};
  14001. char connectorStr[2]={0};
  14002. char TempStopTransaction[256];
  14003. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14004. fptr1 = fopen(TempStopTransaction, "r");
  14005. //TempStopTransaction格式: 槍號,StopTransaction封包
  14006. if (!fptr1)
  14007. {
  14008. //printf(" File not found or unable to open the input file!!\n");
  14009. return ;
  14010. }
  14011. ch=fgetc(fptr1);
  14012. //printf(" Now the content of the file %s is : \n",fname);
  14013. rewind(fptr1);
  14014. if(ch!=EOF)
  14015. {
  14016. // copy all contents to the temporary file except the specific line
  14017. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14018. {
  14019. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14020. if(str[0]=='\0')
  14021. {
  14022. break;
  14023. }
  14024. //TempStopTransaction格式: 槍號,StopTransaction封包
  14025. strncpy(connectorStr, str, 1);
  14026. if(atoi(connectorStr) != (gun_index+1))
  14027. {
  14028. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  14029. fclose(fptr1);
  14030. return ;
  14031. }
  14032. //random_uuid(guid);
  14033. strncpy(guid, str+6, 36); //copy guid
  14034. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14035. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14036. {
  14037. DEBUG_INFO("StopTransaction mapitem pass\n");
  14038. }
  14039. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14040. memset(str,0,ARRAY_SIZE(str));
  14041. }
  14042. }
  14043. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14044. fclose(fptr1);
  14045. remove(TempStopTransaction); // remove the original file
  14046. }
  14047. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14048. {
  14049. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14050. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14051. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14052. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14053. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14054. }
  14055. int GetWebSocketPingInterval(void)
  14056. {
  14057. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14058. }
  14059. int GetServerSign(void)
  14060. {
  14061. return server_sign;
  14062. }
  14063. void SetServerSign(int value)
  14064. {
  14065. server_sign = value;
  14066. }
  14067. int GetBootNotificationInterval(void)
  14068. {
  14069. return BootNotificationInterval;
  14070. }
  14071. int GetInternetConn(void)
  14072. {
  14073. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14074. }
  14075. void InitialSystemValue(void)
  14076. {
  14077. int connectorIndex = 0;
  14078. //int valueASCII = 0;
  14079. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14080. gunTotalNumber=0;
  14081. SystemInitial = 0;
  14082. localversion=0;
  14083. BootNotificationInterval = 0;
  14084. authorizeRetryTimes = 0;
  14085. GunStatusInterval = 10;
  14086. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14087. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14088. //Hear Beat
  14089. HeartBeatWithNOResponse = 0;
  14090. HeartBeatCountPerHour = 0;
  14091. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14092. FirstHeartBeat = 0;
  14093. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14094. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14095. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14096. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14097. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14098. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14099. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14100. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14101. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14102. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14103. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14104. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14105. memset(gunType, 0, ARRAY_SIZE(gunType));
  14106. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14107. {
  14108. //check connector / socket type (index: 8, 9, 10)
  14109. for(int index=7; index <10 ; index++)
  14110. {
  14111. if(index != 8)
  14112. {
  14113. // DC Connector
  14114. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  14115. {
  14116. SystemInitial = SystemInitial + 1;
  14117. gunTotalNumber = gunTotalNumber + 1;
  14118. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14119. connectorIndex = connectorIndex + 1;
  14120. }
  14121. }
  14122. else
  14123. {
  14124. // AC Connector
  14125. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14126. {
  14127. SystemInitial = SystemInitial + 1;
  14128. gunTotalNumber = gunTotalNumber + 1;
  14129. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14130. connectorIndex = connectorIndex + 1;
  14131. }
  14132. }
  14133. }
  14134. //DEBUG_INFO("DC ...\n");
  14135. }
  14136. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14137. {
  14138. //check connector / socket type (index: 8, 9, 10)
  14139. for(int index=7; index <10 ; index++)
  14140. {
  14141. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14142. {
  14143. SystemInitial = SystemInitial + 1;
  14144. gunTotalNumber = gunTotalNumber + 1;
  14145. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14146. connectorIndex = connectorIndex + 1;
  14147. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14148. }
  14149. }
  14150. }
  14151. //Status && ConnectorPlugIn Setting
  14152. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14153. {
  14154. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14155. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14156. }
  14157. for (int index = 0; index < CCS_QUANTITY; index++)
  14158. {
  14159. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14160. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14161. }
  14162. for (int index = 0; index < GB_QUANTITY; index++)
  14163. {
  14164. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14165. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14166. }
  14167. for (int index = 0; index < AC_QUANTITY; index++)
  14168. {
  14169. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14170. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14171. }
  14172. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14173. {
  14174. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14175. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14176. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14177. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14178. }
  14179. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14180. clientTime.Heartbeat=time((time_t*)NULL);
  14181. sleep(1);
  14182. }
  14183. void LWS_Send(char * str)
  14184. {
  14185. //=====================================================
  14186. // Check InternetConn 0: disconnected, 1: connected
  14187. //====================================================
  14188. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14189. {
  14190. DEBUG_INFO("offline now !!!\n");
  14191. return;
  14192. }
  14193. pthread_mutex_lock(&lock_send);
  14194. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14195. sprintf((char *)SendBuffer, "%s", str);
  14196. SendBufLen = strlen(str);
  14197. pthread_mutex_unlock(&lock_send);
  14198. lws_callback_on_writable(wsi_client);
  14199. //lws_service(context, 0);
  14200. //sleep(1);
  14201. }