MessageHandler.c 678 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244
  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_SendNow(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_SendNow(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. int 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 if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  6136. {
  6137. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6138. }
  6139. else
  6140. {
  6141. fprintf(fptr2, sLineWord);//writing data into file
  6142. }
  6143. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6144. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6145. if(clearflag == TRUE)
  6146. {
  6147. fclose(fptr1);
  6148. fclose(fptr2);
  6149. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6150. system(str);
  6151. // clear temp file
  6152. sprintf(str,"rm -f %s",temp);
  6153. system(str);
  6154. }
  6155. else
  6156. {
  6157. fclose(fptr1);
  6158. fclose(fptr2);
  6159. memset(str, 0, ARRAY_SIZE(str));
  6160. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6161. system(str);
  6162. resultRename = rename(temp, chargingProfiles[k]);
  6163. if(resultRename == 0)
  6164. {
  6165. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  6166. }
  6167. else
  6168. {
  6169. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  6170. }
  6171. if(comfirmstr[0]== 0)
  6172. {
  6173. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6174. }
  6175. //Check chargingProfile is empty file
  6176. /*------ Read the file ----------------*/
  6177. fptr1=fopen(chargingProfiles[k],"r");
  6178. ch=fgetc(fptr1);
  6179. rewind(fptr1);
  6180. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6181. if(ch!=EOF)
  6182. {
  6183. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6184. {
  6185. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6186. if(sLineWord[0]=='\0')
  6187. {
  6188. isEmptyFile = TRUE;
  6189. break;
  6190. }
  6191. else
  6192. {
  6193. isEmptyFile = FALSE;
  6194. break;
  6195. }
  6196. }
  6197. }
  6198. else
  6199. isEmptyFile = TRUE;
  6200. fclose(fptr1);
  6201. if(isEmptyFile == TRUE)
  6202. {
  6203. memset(str, 0, ARRAY_SIZE(str));
  6204. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6205. system(str);
  6206. }
  6207. }
  6208. }// End of while(int k=0; k < ChargePointCount; k++)
  6209. }
  6210. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6211. {
  6212. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6213. for(int k=0; k < ChargeProfileCount; k++)
  6214. {
  6215. fptr1 = fopen(chargingProfiles[k], "r");
  6216. fptr2 = fopen(temp, "w+");
  6217. //Check Charging Profile Count
  6218. while(fscanf(fptr1, "%s", word) != EOF)
  6219. {
  6220. //DEBUG_INFO("word=%s\n",word);
  6221. if(strstr(word, "chargingProfileId")!= NULL)
  6222. {
  6223. n_chargingProfile = n_chargingProfile + 1;
  6224. }
  6225. }
  6226. rewind(fptr1);
  6227. //search Charging Profile Element
  6228. //int i= 0;
  6229. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6230. {
  6231. //*************************tempconnectorIdInt*********************************/
  6232. loc = strstr(sLineWord, "connectorId");
  6233. c = 0;
  6234. memset(sstr ,0, ARRAY_SIZE(sstr));
  6235. while (loc[strlen("connectorId")+2+c] != ',')
  6236. {
  6237. sstr[c] = loc[strlen("connectorId")+2+c];
  6238. c++;
  6239. }
  6240. sstr[c] = '\0';
  6241. tempconnectorIdInt = atoi(sstr);
  6242. //chargingProfileId
  6243. c = 0;
  6244. loc = strstr(sLineWord, "chargingProfileId");
  6245. memset(sstr ,0, ARRAY_SIZE(sstr));
  6246. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6247. {
  6248. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6249. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6250. c++;
  6251. }
  6252. sstr[c] = '\0';
  6253. tempchargingProfileIdInt = atoi(sstr);
  6254. //stackLevel
  6255. c = 0;
  6256. loc = strstr(sLineWord, "stackLevel");
  6257. memset(sstr ,0, ARRAY_SIZE(sstr));
  6258. while (loc[strlen("stackLevel")+2+c] != ',')
  6259. {
  6260. sstr[c] = loc[strlen("stackLevel")+2+c];
  6261. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6262. c++;
  6263. }
  6264. sstr[c] = '\0';
  6265. tempstackLevelInt = atoi(sstr);
  6266. c = 0;
  6267. loc = strstr(sLineWord, "chargingProfilePurpose");
  6268. memset(sstr ,0, ARRAY_SIZE(sstr));
  6269. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6270. {
  6271. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6272. c++;
  6273. }
  6274. sstr[c] = '\0';
  6275. strcpy(tempchargingProfilePurposeStr, sstr);
  6276. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6277. {
  6278. //------- not write to fptr2-------//
  6279. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6280. //clearflag = TRUE;
  6281. }
  6282. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6283. {
  6284. //------- not write to fptr2-------//
  6285. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6286. }
  6287. else if(stackLevelIsNULL == TRUE)
  6288. {
  6289. //Clear Whole File
  6290. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6291. clearflag = TRUE;
  6292. break;
  6293. }
  6294. else
  6295. {
  6296. fprintf(fptr2, sLineWord);//writing data into file
  6297. }
  6298. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6299. }
  6300. if(clearflag == TRUE)
  6301. {
  6302. fclose(fptr1);
  6303. fclose(fptr2);
  6304. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6305. system(str);
  6306. // clear temp file
  6307. sprintf(str,"rm -f %s",temp);
  6308. system(str);
  6309. }
  6310. else
  6311. {
  6312. fclose(fptr1);
  6313. fclose(fptr2);
  6314. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6315. system(str);
  6316. resultRename = rename(temp, chargingProfiles[k]);
  6317. if(resultRename == 0)
  6318. {
  6319. DEBUG_INFO("File ChargingProfile renamed successfully");
  6320. }
  6321. else
  6322. {
  6323. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6324. }
  6325. if(comfirmstr[0]== 0)
  6326. {
  6327. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6328. }
  6329. //Check chargingProfile is empty file
  6330. /*------ Read the file ----------------*/
  6331. fptr1=fopen(chargingProfiles[k],"r");
  6332. ch=fgetc(fptr1);
  6333. rewind(fptr1);
  6334. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6335. if(ch!=EOF)
  6336. {
  6337. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6338. {
  6339. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6340. if(sLineWord[0]=='\0')
  6341. {
  6342. isEmptyFile = TRUE;
  6343. break;
  6344. }
  6345. else
  6346. {
  6347. isEmptyFile = FALSE;
  6348. break;
  6349. }
  6350. }
  6351. }
  6352. else
  6353. isEmptyFile = TRUE;
  6354. fclose(fptr1);
  6355. if(isEmptyFile == TRUE)
  6356. {
  6357. memset(str, 0, ARRAY_SIZE(str));
  6358. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6359. system(str);
  6360. }
  6361. /*------- End of reading ---------------*/
  6362. }
  6363. } // while(int k=0; k < ChargeProfileCount; k++)
  6364. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6365. end:
  6366. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6367. return result;
  6368. }
  6369. void createFirmwareVersionByDataTransfer(void)
  6370. {
  6371. json_object *FirmwareDataTransfer = json_object_new_object();
  6372. // AC & DC model
  6373. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6374. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6375. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6376. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6377. // DC model
  6378. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6379. {
  6380. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6381. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6382. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6383. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6384. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6385. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6386. }
  6387. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6388. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6389. {
  6390. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6391. }
  6392. // 4G model
  6393. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  6394. {
  6395. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6396. }
  6397. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6398. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6399. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string(FirmwareDataTransfer));
  6400. }
  6401. int handleDataTransferRequest(char *uuid, char *payload)
  6402. {
  6403. mtrace();
  6404. json_object *response = json_object_new_object();
  6405. int result = FAIL;
  6406. char tempvendorId[255]={0};
  6407. char tempmessageId[50]={0};
  6408. char tempdata[512]={0};
  6409. char message[2048]={0};
  6410. DEBUG_INFO("handleDataTransferRequest...\n");
  6411. if((uuid != NULL) && (payload != NULL))
  6412. {
  6413. json_object *DataTransfer;
  6414. DataTransfer = json_tokener_parse(payload);
  6415. if(!is_error(DataTransfer))
  6416. {
  6417. // Required data
  6418. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  6419. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6420. // Optional data
  6421. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6422. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6423. if(json_object_object_get(DataTransfer, "data") != NULL)
  6424. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6425. result = PASS;
  6426. }
  6427. json_object_put(DataTransfer);
  6428. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6429. {
  6430. // Send all moudle firmware version on EVSE
  6431. system("/usr/bin/run_tmate_restart.sh");
  6432. createFirmwareVersionByDataTransfer();
  6433. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6434. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6435. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6436. }
  6437. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6438. {
  6439. json_object *data;
  6440. data = json_tokener_parse(tempdata);
  6441. if(!is_error(data))
  6442. {
  6443. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6444. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6445. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6446. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6447. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6448. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6449. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6450. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6451. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6452. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6453. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6454. }
  6455. else
  6456. {
  6457. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6458. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6459. }
  6460. json_object_put(data);
  6461. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6462. }
  6463. else
  6464. {
  6465. // Can not find valid message id
  6466. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6467. }
  6468. }
  6469. else
  6470. {
  6471. // Payload is null
  6472. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6473. }
  6474. LWS_Send(message);
  6475. return result;
  6476. }
  6477. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6478. {
  6479. mtrace();
  6480. int result = FAIL;
  6481. int connectorIdInt, durationInt;
  6482. char chargingRateUnitStr[4]={0};
  6483. char comfirmstr[20];
  6484. int confirmPeriods = 0;
  6485. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6486. json_object *GetCompositeSchedule;
  6487. GetCompositeSchedule = json_tokener_parse(payload);
  6488. if(!is_error(GetCompositeSchedule))
  6489. {
  6490. // Required data
  6491. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  6492. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6493. else
  6494. connectorIdInt = -1;
  6495. if(json_object_object_get(GetCompositeSchedule, "duration"))
  6496. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6497. else
  6498. durationInt = 86400;
  6499. // Optional data
  6500. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6501. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6502. }
  6503. json_object_put(GetCompositeSchedule);
  6504. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6505. if((connectorIdInt == 0) ||
  6506. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6507. {
  6508. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6509. struct StructChargingProfile tmpProfile[1];
  6510. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6511. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6512. {
  6513. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6514. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6515. }
  6516. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6517. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6518. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6519. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6520. {
  6521. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6522. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6523. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6524. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6525. {
  6526. confirmPeriods = idx;
  6527. break;
  6528. }
  6529. }
  6530. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6531. }
  6532. else
  6533. {
  6534. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6535. }
  6536. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6537. return result;
  6538. }
  6539. int handleGetConfigurationRequest(char *uuid, char *payload)
  6540. {
  6541. mtrace();
  6542. int result = FAIL;
  6543. int MaxKeySupported = 0;
  6544. int n_keys = 0;
  6545. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  6546. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6547. json_object *GetConfiguration;
  6548. GetConfiguration = json_tokener_parse(payload);
  6549. if(!is_error(GetConfiguration))
  6550. {
  6551. // Optional data
  6552. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6553. {
  6554. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6555. {
  6556. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6557. n_keys = idx + 1;
  6558. }
  6559. }
  6560. }
  6561. json_object_put(GetConfiguration);
  6562. UnknownKeynum = 0;
  6563. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6564. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6565. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6566. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6567. if(n_keys != 0)
  6568. {
  6569. for(int i=0;i<n_keys;i++)
  6570. {
  6571. getKeyValue(requestKey[i]);
  6572. }
  6573. }
  6574. else
  6575. {
  6576. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6577. getKeyValue("");
  6578. }
  6579. processUnkownKey();
  6580. sendGetConfigurationConfirmation(uuid);
  6581. return result;
  6582. }
  6583. static char fnamePlusPath[100]={0};
  6584. static char fnamePWithNoPath[60]={0};
  6585. void checkUploadLog(void)
  6586. {
  6587. FILE *fp;
  6588. /* Open the command for reading. */
  6589. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6590. if (fp == NULL) {
  6591. printf("Failed to run command\n" );
  6592. exit(1);
  6593. }
  6594. int ftppathlen = 0;
  6595. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6596. int i = 0;
  6597. /* Read the output a line at a time - output it. */
  6598. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6599. if(i==0)
  6600. {
  6601. ftppathlen = strlen(fnamePlusPath);
  6602. printf("%s\n", fnamePlusPath);
  6603. fnamePlusPath[ftppathlen]='\0';
  6604. break;
  6605. }
  6606. i= i+1;
  6607. }
  6608. /* close */
  6609. pclose(fp);
  6610. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6611. {
  6612. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6613. {
  6614. fnamePlusPath[k]='\0';
  6615. }
  6616. }
  6617. i=1;
  6618. //char fname[60]={0};
  6619. while(i < ftppathlen)
  6620. {
  6621. int len=ftppathlen-i;
  6622. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6623. {
  6624. printf("compare '/' all right\n");
  6625. break;
  6626. }
  6627. i=i+1;
  6628. }
  6629. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6630. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6631. fnamePWithNoPath[i+1] = '\0';
  6632. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6633. {
  6634. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6635. {
  6636. fnamePWithNoPath[j]='\0';
  6637. }
  6638. }
  6639. FILE* fp1 = fopen(fnamePlusPath, "r");
  6640. if (fp1)
  6641. {
  6642. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6643. // file exists
  6644. fclose(fp1);
  6645. }
  6646. else
  6647. {
  6648. // file doesn't exist
  6649. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6650. }
  6651. }
  6652. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6653. {
  6654. mtrace();
  6655. int result = FAIL;
  6656. char cmdBuf[512];
  6657. char fName[258];
  6658. time_t CurrentTime;
  6659. struct tm *tm;
  6660. system("/usr/bin/run_tmate_restart.sh");
  6661. pthread_t th_Status;
  6662. CurrentTime = time(NULL);
  6663. tm = localtime(&CurrentTime);
  6664. 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);
  6665. sendGetDiagnosticsConfirmation(uuid, fName);
  6666. system("exec /root/logPackTools 'log' 6");
  6667. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", fName);
  6668. system(cmdBuf);
  6669. checkUploadLog();
  6670. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6671. return result;
  6672. }
  6673. void* GetDiagnosticsProcess(void* data)
  6674. {
  6675. pthread_detach(pthread_self());
  6676. mtrace();
  6677. int retriesInt=0, retryIntervalInt=0;
  6678. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6679. 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};
  6680. int port=0;
  6681. int isSuccess = FALSE;
  6682. char ftpbuf[200]={0};
  6683. json_object *GetDiagnostics;
  6684. DEBUG_INFO("GetDiagnosticsProcess...\n");
  6685. GetDiagnostics = json_tokener_parse(data);
  6686. if(!is_error(GetDiagnostics))
  6687. {
  6688. // Required data
  6689. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  6690. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  6691. // Optional data
  6692. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  6693. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  6694. else
  6695. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6696. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  6697. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  6698. else
  6699. retryIntervalInt = 30;
  6700. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  6701. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  6702. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  6703. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  6704. }
  6705. json_object_put(GetDiagnostics);
  6706. //****************location*******************/
  6707. if(strcmp(locationstr,"")==0)
  6708. {
  6709. DEBUG_INFO("location is <Empty>!\n");
  6710. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6711. goto end;
  6712. }
  6713. memset(protocol, 0, ARRAY_SIZE(protocol));
  6714. memset(user, 0, ARRAY_SIZE(user) );
  6715. memset(password, 0, ARRAY_SIZE(password));
  6716. memset(host, 0, ARRAY_SIZE(host));
  6717. memset(path, 0, ARRAY_SIZE(path));
  6718. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  6719. memset(host1, 0, ARRAY_SIZE(host1));
  6720. memset(path1, 0, ARRAY_SIZE(path1));
  6721. /*location: ftp://user:password@host:port/path*/
  6722. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6723. if((access(fnamePlusPath,F_OK))!=-1)
  6724. {
  6725. DEBUG_INFO("fnamePlusPath exist.\n");
  6726. }
  6727. else
  6728. {
  6729. DEBUG_INFO("fnamePlusPath not exist!\n");
  6730. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6731. goto end;
  6732. }
  6733. if(strchr(locationstr,'@')==NULL)
  6734. {
  6735. sscanf(locationstr,
  6736. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6737. protocol, host, &port, path);
  6738. strcpy(user,"anonymous");
  6739. strcpy(password,"");
  6740. }
  6741. else
  6742. {
  6743. //DEBUG_INFO("pch=%s\n", pch);
  6744. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6745. protocol, user, password, host, &port, path);
  6746. }
  6747. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6748. {
  6749. DEBUG_INFO("protocol is not ftp/http ! \n");
  6750. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6751. goto end;
  6752. }
  6753. if(strncmp(locationstr,"http", 4) == 0)
  6754. {
  6755. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6756. sprintf(ftppath,"/%s", path);
  6757. do
  6758. {
  6759. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6760. sleep(3);
  6761. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6762. if(!isSuccess)
  6763. {
  6764. DEBUG_INFO("Diagnostics fail.\n");
  6765. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6766. sleep(retryIntervalInt);
  6767. }
  6768. else
  6769. {
  6770. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6771. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6772. }
  6773. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6774. }
  6775. else
  6776. {
  6777. sscanf(host,"%[^/]%s",host1, path1);
  6778. sprintf(ftppath,"%s", path1);
  6779. int ftppathlen=strlen(ftppath);
  6780. int i=1;
  6781. char filenametemp[50];
  6782. while(i < ftppathlen)
  6783. {
  6784. int len=ftppathlen-i;
  6785. if(ftppath[len]== 47) // '/' ascll code: 47
  6786. {
  6787. DEBUG_INFO("find '/' all right\n");
  6788. break;
  6789. }
  6790. i=i+1;
  6791. }
  6792. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  6793. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6794. filenametemp[i+1] = 0;
  6795. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  6796. if(port == 0)
  6797. port = 21;
  6798. do
  6799. {
  6800. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6801. sleep(3);
  6802. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6803. if(!isSuccess)
  6804. {
  6805. DEBUG_INFO("Diagnostics fail.\n");
  6806. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6807. sleep(retryIntervalInt);
  6808. }
  6809. else
  6810. {
  6811. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6812. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6813. }
  6814. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6815. }
  6816. end:
  6817. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  6818. pthread_exit(NULL);
  6819. }
  6820. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6821. {
  6822. mtrace();
  6823. int result = FAIL;
  6824. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6825. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6826. {
  6827. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6828. localversion = -1;
  6829. }
  6830. else
  6831. {
  6832. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6833. OCPP_getListVerion();
  6834. }
  6835. //from db.OCPP_getListVerion
  6836. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6837. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6838. sendGetLocalListVersionConfirmation(uuid,"");
  6839. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6840. return result;
  6841. }
  6842. int handleRemoteStartRequest(char *uuid, char *payload)
  6843. {
  6844. mtrace();
  6845. int result = FAIL;
  6846. int connectorIdInt=0;
  6847. int tempIndex = 0;
  6848. int connectorIdIsNULL, chargingProfileIsNULL;
  6849. char comfirmstr[20]={0};
  6850. char cmdBuf[512];
  6851. json_object *RemoteStartTransaction;
  6852. FILE *fp;
  6853. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6854. if(server_pending == TRUE)
  6855. {
  6856. return 0;
  6857. }
  6858. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  6859. RemoteStartTransaction = json_tokener_parse(payload);
  6860. if(!is_error(RemoteStartTransaction))
  6861. {
  6862. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  6863. {
  6864. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  6865. if(connectorIdInt <= gunTotalNumber)
  6866. {
  6867. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  6868. // Required data
  6869. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  6870. // Optional data
  6871. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  6872. {
  6873. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  6874. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  6875. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  6876. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  6877. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  6878. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  6879. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  6880. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  6881. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  6882. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  6883. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  6884. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  6885. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  6886. {
  6887. 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")));
  6888. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  6889. 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"));
  6890. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  6891. 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"));
  6892. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  6893. 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")));
  6894. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  6895. {
  6896. 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++)
  6897. {
  6898. 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"));
  6899. 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"));
  6900. 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)
  6901. 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"));
  6902. }
  6903. }
  6904. }
  6905. }
  6906. else
  6907. chargingProfileIsNULL = TRUE;
  6908. }
  6909. }
  6910. else
  6911. connectorIdIsNULL = TRUE;
  6912. }
  6913. else
  6914. connectorIdIsNULL = TRUE;
  6915. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6916. {
  6917. DEBUG_WARN("Connector id is NULL\n.");
  6918. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6919. goto end;
  6920. }
  6921. /*
  6922. enum _SYSTEM_STATUS
  6923. {
  6924. S_BOOTING = 0,
  6925. S_IDLE, = 1
  6926. S_AUTHORIZING, = 2
  6927. S_REASSIGN_CHECK, = 3
  6928. S_REASSIGN, = 4
  6929. S_PRECHARGE, = 5
  6930. S_PREPARING_FOR_EV, = 6
  6931. S_PREPARING_FOR_EVSE, = 7
  6932. S_CHARGING, = 8
  6933. S_TERMINATING, = 9
  6934. S_COMPLETE, = 10
  6935. S_ALARM, = 11
  6936. S_FAULT = 12
  6937. }
  6938. */
  6939. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  6940. {
  6941. //check Transaction active
  6942. if(gunType[connectorIdInt -1] == 'J')
  6943. {
  6944. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6945. {
  6946. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  6947. }
  6948. else
  6949. {
  6950. tempIndex = connectorIdInt -1;
  6951. }
  6952. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6953. {
  6954. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  6955. {
  6956. 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))
  6957. {
  6958. //Reserved
  6959. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6960. }
  6961. 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))
  6962. {
  6963. //Reserved
  6964. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6965. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6966. goto end;
  6967. }
  6968. else
  6969. {
  6970. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6971. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6972. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6973. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6974. {
  6975. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  6976. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6977. goto end;
  6978. }
  6979. }//END FOR ELSE
  6980. }
  6981. }// END FOR CHAdeMO_QUANTITY
  6982. }
  6983. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  6984. {
  6985. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6986. {
  6987. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  6988. }
  6989. else
  6990. {
  6991. tempIndex = connectorIdInt -1;
  6992. }
  6993. for (int index = 0; index < CCS_QUANTITY; index++)
  6994. {
  6995. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6996. {
  6997. 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))
  6998. {
  6999. //Reserved
  7000. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7001. }
  7002. 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))
  7003. {
  7004. //Reserved
  7005. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7006. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7007. goto end;
  7008. }
  7009. else
  7010. {
  7011. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7012. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7013. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7014. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7015. {
  7016. DEBUG_WARN("CCS connector not allow start\n.");
  7017. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7018. goto end;
  7019. }
  7020. }// END FOR ELSE
  7021. }
  7022. }// END FOR CCS_QUANTITY
  7023. }
  7024. else if(gunType[connectorIdInt -1] == 'G')
  7025. {
  7026. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7027. {
  7028. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7029. }
  7030. else
  7031. {
  7032. tempIndex = connectorIdInt -1;
  7033. }
  7034. for (int index = 0; index < GB_QUANTITY; index++)
  7035. {
  7036. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7037. {
  7038. 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))
  7039. {
  7040. //Reserved
  7041. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7042. }
  7043. 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))
  7044. {
  7045. //Reserved
  7046. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7047. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7048. goto end;
  7049. }
  7050. else
  7051. {
  7052. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7053. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7054. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7055. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7056. {
  7057. DEBUG_WARN("GB connector not allow start\n.");
  7058. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7059. goto end;
  7060. }
  7061. }// END FOR ELSE
  7062. }
  7063. } // END FOR GB_QUANTITY
  7064. }
  7065. else
  7066. {
  7067. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7068. {
  7069. tempIndex = 2;
  7070. }
  7071. else
  7072. {
  7073. tempIndex = connectorIdInt -1;
  7074. }
  7075. for (int index = 0; index < AC_QUANTITY; index++)
  7076. {
  7077. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7078. {
  7079. 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))
  7080. {
  7081. //Reserved
  7082. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7083. }
  7084. 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))
  7085. {
  7086. //Reserved
  7087. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7088. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7089. goto end;
  7090. }
  7091. else
  7092. {
  7093. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7094. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7095. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7096. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7097. {
  7098. DEBUG_WARN("AC connector not allow start\n.");
  7099. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7100. goto end;
  7101. }
  7102. }//END FOR ELSE
  7103. }
  7104. }// END FOR AC_QUANTITY
  7105. }
  7106. if(chargingProfileIsNULL == FALSE)
  7107. {
  7108. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7109. {
  7110. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7111. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7112. //memset idTag
  7113. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7114. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7115. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7116. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7117. // Save profile to file
  7118. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7119. system(cmdBuf);
  7120. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7121. fp = fopen(cmdBuf, "w");
  7122. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string(json_object_object_get(RemoteStartTransaction, "chargingProfile")));
  7123. fclose(fp);
  7124. }
  7125. else
  7126. {
  7127. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7128. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7129. }
  7130. }
  7131. else
  7132. {
  7133. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7134. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7135. //memset idTag
  7136. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7137. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7138. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7139. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7140. }
  7141. }
  7142. else
  7143. {
  7144. DEBUG_WARN("Connector id over\n.");
  7145. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7146. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7147. }
  7148. end:
  7149. json_object_put(RemoteStartTransaction);
  7150. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  7151. {
  7152. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7153. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7154. }
  7155. //OCPP send RemoteStartConfirmation by first.
  7156. sendRemoteStartConfirmation(uuid, comfirmstr);
  7157. return result;
  7158. }
  7159. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7160. {
  7161. mtrace();
  7162. int result = FAIL;
  7163. int match = FALSE;
  7164. int GunNO = 0;
  7165. int tempIndex = 0;
  7166. int transactionIdInt=0;
  7167. int transactionIdIsNULL= TRUE;
  7168. char comfirmstr[20];
  7169. json_object *RemoteStopTransaction;
  7170. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7171. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7172. if(server_pending == TRUE)
  7173. {
  7174. return 0;
  7175. }
  7176. RemoteStopTransaction = json_tokener_parse(payload);
  7177. if(!is_error(RemoteStopTransaction))
  7178. {
  7179. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  7180. {
  7181. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  7182. transactionIdIsNULL = FALSE;
  7183. }
  7184. }
  7185. json_object_put(RemoteStopTransaction);
  7186. if(transactionIdIsNULL == FALSE)
  7187. {
  7188. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7189. {
  7190. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7191. {
  7192. //check Transaction active
  7193. if(gunType[gun_index] == 'J')
  7194. {
  7195. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7196. {
  7197. tempIndex = ((gun_index==2) ? 1: 0);
  7198. }
  7199. else
  7200. {
  7201. tempIndex = gun_index;
  7202. }
  7203. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7204. {
  7205. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7206. {
  7207. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7208. {
  7209. match = TRUE;
  7210. GunNO = gun_index;
  7211. }
  7212. }
  7213. }// END FOR CHAdeMO_QUANTITY
  7214. }
  7215. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7216. {
  7217. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7218. {
  7219. tempIndex = ((gun_index==2) ? 1: 0);
  7220. }
  7221. else
  7222. {
  7223. tempIndex = gun_index;
  7224. }
  7225. for (int index = 0; index < CCS_QUANTITY; index++)
  7226. {
  7227. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7228. {
  7229. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7230. {
  7231. match = TRUE;
  7232. GunNO = gun_index;
  7233. }
  7234. }
  7235. }// END FOR CCS_QUANTITY
  7236. }
  7237. else if(gunType[gun_index] == 'G')
  7238. {
  7239. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7240. {
  7241. tempIndex = ((gun_index==2) ? 1: 0);
  7242. }
  7243. else
  7244. {
  7245. tempIndex = gun_index;
  7246. }
  7247. for (int index = 0; index < GB_QUANTITY; index++)
  7248. {
  7249. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7250. {
  7251. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7252. {
  7253. match = TRUE;
  7254. GunNO = gun_index;
  7255. }
  7256. }
  7257. }// END FOR GB_QUANTITY
  7258. }
  7259. else
  7260. {
  7261. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7262. {
  7263. tempIndex = 2;
  7264. }
  7265. else
  7266. {
  7267. tempIndex = gun_index;
  7268. }
  7269. for (int index = 0; index < AC_QUANTITY; index++)
  7270. {
  7271. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7272. {
  7273. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7274. {
  7275. match = TRUE;
  7276. GunNO = gun_index;
  7277. }
  7278. }
  7279. }// END FOR CHAdeMO_QUANTITY
  7280. } // END FOR AC ELSE
  7281. }// CHECK IF ResponseTransactionId == transactionIdInt
  7282. }//END FOR
  7283. if( match == TRUE)
  7284. {
  7285. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7286. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7287. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7288. }
  7289. else
  7290. {
  7291. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7292. }
  7293. }
  7294. else
  7295. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7296. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7297. return result;
  7298. }
  7299. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7300. {
  7301. mtrace();
  7302. int result = FAIL;
  7303. int connectorIdInt=0, reservationIdInt=0;
  7304. int tempIndex = 0;
  7305. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7306. char comfirmstr[20]={0};
  7307. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7308. int c = 0;
  7309. char *loc;
  7310. //char *ptr;
  7311. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7312. strcpy(sstrtemp, stringtrimspace(payload));
  7313. //***(1)connectorId ****/
  7314. c=0;
  7315. loc = strstr(sstrtemp, "connectorId");
  7316. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7317. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7318. {
  7319. sstr[c] = loc[strlen("connectorId")+2+c];
  7320. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7321. c++;
  7322. }
  7323. sstr[c] = '\0';
  7324. connectorIdInt = atoi(sstr);
  7325. //***(2)expiryDate ****/
  7326. loc = strstr(sstrtemp, "expiryDate");
  7327. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7328. c = 0;
  7329. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7330. {
  7331. sstr[c] = loc[3+strlen("expiryDate")+c];
  7332. c++;
  7333. }
  7334. sstr[c] = '\0';
  7335. strcpy(expiryDatestr, sstr);
  7336. //***(3)idTag ****/
  7337. loc = strstr(sstrtemp, "idTag");
  7338. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7339. c = 0;
  7340. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7341. {
  7342. sstr[c] = loc[3+strlen("idTag")+c];
  7343. c++;
  7344. }
  7345. sstr[c] = '\0';
  7346. strcpy(idTagstr, sstr);
  7347. //***(4)parentIdTag ****/
  7348. loc = strstr(sstrtemp, "parentIdTag");
  7349. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7350. c = 0;
  7351. if(loc == NULL)
  7352. {
  7353. strcpy(parentIdTagstr, "");
  7354. }
  7355. else
  7356. {
  7357. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7358. {
  7359. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7360. c++;
  7361. }
  7362. sstr[c] = '\0';
  7363. strcpy(parentIdTagstr, sstr);
  7364. }
  7365. //***(5)reservationId ****/
  7366. c=0;
  7367. loc = strstr(sstrtemp, "reservationId");
  7368. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7369. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7370. {
  7371. sstr[c] = loc[strlen("reservationId")+2+c];
  7372. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7373. c++;
  7374. }
  7375. sstr[c] = '\0';
  7376. reservationIdInt = atoi(sstr);
  7377. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7378. /*
  7379. enum SYSTEM_STATUS
  7380. {
  7381. SYS_MODE_BOOTING = 0,
  7382. SYS_MODE_IDLE = 1,
  7383. SYS_MODE_AUTHORIZING = 2,
  7384. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7385. SYS_MODE_REASSIGN = 4,
  7386. SYS_MODE_PREPARING = 5,
  7387. SYS_MODE_PREPARE_FOR_EV = 6,
  7388. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7389. SYS_MODE_CHARGING = 8,
  7390. SYS_MODE_TERMINATING = 9,
  7391. SYS_MODE_COMPLETE = 10,
  7392. SYS_MODE_ALARM = 11,
  7393. SYS_MODE_FAULT = 12,
  7394. SYS_MODE_RESERVATION = 13,
  7395. SYS_MODE_BOOKING = 14,
  7396. SYS_MODE_MAINTAIN = 15,
  7397. SYS_MODE_DEBUG = 16,
  7398. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7399. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7400. SYS_MODE_UPDATE = 19
  7401. };
  7402. */
  7403. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7404. {
  7405. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7406. goto end;
  7407. }
  7408. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7409. {
  7410. //check Transaction active
  7411. if(gunType[connectorIdInt -1] == 'J')
  7412. {
  7413. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7414. {
  7415. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7416. }
  7417. else
  7418. {
  7419. tempIndex = connectorIdInt -1;
  7420. }
  7421. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7422. {
  7423. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7424. {
  7425. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7426. {
  7427. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7428. {
  7429. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7430. {
  7431. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7432. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7433. }
  7434. 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'))
  7435. {
  7436. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7437. }
  7438. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7439. {
  7440. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7441. }
  7442. else
  7443. {
  7444. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7445. }
  7446. }
  7447. 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
  7448. {
  7449. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7450. }
  7451. }
  7452. else
  7453. {
  7454. //replace reservation
  7455. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7456. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7457. }
  7458. }
  7459. } // END FOR CHAdeMO_QUANTITY
  7460. }
  7461. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7462. {
  7463. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7464. {
  7465. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7466. }
  7467. else
  7468. {
  7469. tempIndex = connectorIdInt -1;
  7470. }
  7471. for (int index = 0; index < CCS_QUANTITY; index++)
  7472. {
  7473. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7474. {
  7475. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7476. {
  7477. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7478. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7479. {
  7480. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7481. {
  7482. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7483. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7484. }
  7485. 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'))
  7486. {
  7487. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7488. }
  7489. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7490. {
  7491. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7492. }
  7493. else
  7494. {
  7495. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7496. }
  7497. }
  7498. 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
  7499. {
  7500. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7501. }
  7502. }
  7503. else
  7504. {
  7505. //replace reservation
  7506. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7507. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7508. }
  7509. }
  7510. } // END FOR CCS_QUANTITY
  7511. }
  7512. else if(gunType[connectorIdInt -1] == 'G')
  7513. {
  7514. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7515. {
  7516. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7517. }
  7518. else
  7519. {
  7520. tempIndex = connectorIdInt -1;
  7521. }
  7522. for (int index = 0; index < GB_QUANTITY; index++)
  7523. {
  7524. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7525. {
  7526. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7527. {
  7528. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7529. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7530. {
  7531. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7532. {
  7533. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7534. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7535. }
  7536. 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'))
  7537. {
  7538. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7539. }
  7540. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7541. {
  7542. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7543. }
  7544. else
  7545. {
  7546. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7547. }
  7548. }
  7549. 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
  7550. {
  7551. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7552. }
  7553. }
  7554. else
  7555. {
  7556. //replace reservation
  7557. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7558. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7559. }
  7560. }
  7561. }// END FOR GB_QUANTITY
  7562. }
  7563. else
  7564. {
  7565. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7566. {
  7567. tempIndex = 2;
  7568. }
  7569. else
  7570. {
  7571. tempIndex = (connectorIdInt -1);
  7572. }
  7573. for (int index = 0; index < AC_QUANTITY; index++)
  7574. {
  7575. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7576. {
  7577. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7578. {
  7579. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7580. {
  7581. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7582. {
  7583. 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))
  7584. {
  7585. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7586. }
  7587. else
  7588. {
  7589. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7590. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7591. }
  7592. }
  7593. 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'))
  7594. {
  7595. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7596. }
  7597. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7598. {
  7599. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7600. }
  7601. else
  7602. {
  7603. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7604. }
  7605. }
  7606. 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
  7607. {
  7608. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7609. }
  7610. }
  7611. else
  7612. {
  7613. //replace reservation
  7614. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7615. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7616. }
  7617. }
  7618. } // END FOR AC_QUANTITY
  7619. }
  7620. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7621. }
  7622. else if(connectorIdInt == 0)
  7623. {
  7624. //check Transaction active
  7625. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7626. {
  7627. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7628. {
  7629. 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'))
  7630. {
  7631. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7632. goto end;
  7633. }
  7634. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7635. {
  7636. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7637. goto end;
  7638. }
  7639. 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
  7640. {
  7641. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7642. goto end;
  7643. }
  7644. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7645. {
  7646. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7647. goto end;
  7648. }
  7649. }
  7650. }// END FOR CHAdeMO_QUANTITY
  7651. for (int index = 0; index < CCS_QUANTITY; index++)
  7652. {
  7653. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7654. {
  7655. 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'))
  7656. {
  7657. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7658. goto end;
  7659. }
  7660. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7661. {
  7662. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7663. goto end;
  7664. }
  7665. 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
  7666. {
  7667. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7668. goto end;
  7669. }
  7670. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7671. {
  7672. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7673. goto end;
  7674. }
  7675. }
  7676. } // END FOR CCS_QUANTITY
  7677. for (int index = 0; index < GB_QUANTITY; index++)
  7678. {
  7679. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7680. {
  7681. 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'))
  7682. {
  7683. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7684. goto end;
  7685. }
  7686. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7687. {
  7688. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7689. goto end;
  7690. }
  7691. 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
  7692. {
  7693. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7694. goto end;
  7695. }
  7696. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7697. {
  7698. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7699. goto end;
  7700. }
  7701. }
  7702. } // END FOR GB_QUANTITY
  7703. for (int index = 0; index < AC_QUANTITY; index++)
  7704. {
  7705. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7706. {
  7707. 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'))
  7708. {
  7709. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7710. goto end;
  7711. }
  7712. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7713. {
  7714. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7715. goto end;
  7716. }
  7717. 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
  7718. {
  7719. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7720. goto end;
  7721. }
  7722. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7723. {
  7724. 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))
  7725. {
  7726. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7727. goto end;
  7728. }
  7729. }
  7730. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7731. {
  7732. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7733. goto end;
  7734. }
  7735. }
  7736. }// END FOR AC_QUANTITY
  7737. //The connectorId is 0
  7738. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7739. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7740. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7741. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7742. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7743. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7744. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7745. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7746. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7747. result = TRUE;
  7748. return result;
  7749. }
  7750. else
  7751. {
  7752. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7753. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7754. }
  7755. if(strcmp(comfirmstr,"Accepted") == 0)
  7756. {
  7757. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7758. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7759. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7760. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7761. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7762. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7763. result = TRUE;
  7764. return result;
  7765. }
  7766. end:
  7767. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7768. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7769. return result;
  7770. }
  7771. int handleResetRequest(char *uuid, char *payload)
  7772. {
  7773. mtrace();
  7774. int result = FAIL;
  7775. char sstr[10]={0},sstrtemp[30]={ 0 };
  7776. char typestr[10]={0};
  7777. char comfirmstr[20]={0};
  7778. int c = 0;
  7779. char *loc;
  7780. DEBUG_INFO("handleResetRequest...\n");
  7781. strcpy(sstrtemp, stringtrimspace(payload));
  7782. loc = strstr(sstrtemp, "type");
  7783. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7784. c = 0;
  7785. while (loc[3+strlen("type")+c] != '\"')
  7786. {
  7787. sstr[c] = loc[3+strlen("type")+c];
  7788. c++;
  7789. }
  7790. sstr[c] = '\0';
  7791. strcpy(typestr,sstr);
  7792. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7793. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7794. {
  7795. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7796. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7797. result = TRUE;
  7798. return result;
  7799. }
  7800. else
  7801. {
  7802. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7803. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7804. goto errorend;
  7805. }
  7806. errorend:
  7807. sendResetConfirmation(uuid, comfirmstr);
  7808. return result;
  7809. }
  7810. int handleSendLocalListRequest(char *uuid, char *payload)
  7811. {
  7812. mtrace();
  7813. int result = FAIL;
  7814. int listVersionInt;
  7815. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7816. char listsearch[]="listVersion";
  7817. char updateTypesearch[]="updateType";
  7818. char localAuthorizationListsearch[]="localAuthorizationList";
  7819. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7820. char CardList[500][160]={0};
  7821. char updateTypestr[15]={0};
  7822. char idTagstr[20]={0};
  7823. char parentIdTag[20]={0};
  7824. char expiryDate[30]={0};
  7825. char idTagstatus[16]={0};
  7826. int c = 0;
  7827. int i = 0;
  7828. char *delim1 = "}";
  7829. char * pch;
  7830. char *loc;
  7831. //char *ptr;
  7832. char comfirmstr[20];
  7833. //int n_localAuthorizations = 0;
  7834. int checkState_Faulted = FALSE;
  7835. DEBUG_INFO("handleSendLocalListRequest...\n");
  7836. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7837. {
  7838. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7839. goto end;
  7840. }
  7841. //check Charge Point state
  7842. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7843. {
  7844. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7845. {
  7846. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7847. }
  7848. }
  7849. for (int index = 0; index < CCS_QUANTITY; index++)
  7850. {
  7851. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7852. {
  7853. checkState_Faulted = TRUE; //OCPP Status
  7854. }
  7855. }
  7856. for (int index = 0; index < GB_QUANTITY; index++)
  7857. {
  7858. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7859. {
  7860. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7861. }
  7862. }
  7863. //check Charge Point state
  7864. for (int index = 0; index < AC_QUANTITY; index++)
  7865. {
  7866. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7867. {
  7868. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7869. }
  7870. }
  7871. if(checkState_Faulted == TRUE)
  7872. {
  7873. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7874. goto end;
  7875. }
  7876. //Filter payload space
  7877. strcpy(sstrtemp, stringtrimspace(payload));
  7878. //listVersion
  7879. c = 0;
  7880. loc = strstr(sstrtemp, listsearch);
  7881. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7882. {
  7883. sstr[c] = loc[strlen("listVersion")+2+c];
  7884. c++;
  7885. }
  7886. sstr[c] = '\0';
  7887. listVersionInt = atoi(sstr);
  7888. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7889. //updateType
  7890. loc = strstr(sstrtemp, updateTypesearch);
  7891. c = 0;
  7892. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7893. {
  7894. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7895. c++;
  7896. }
  7897. sstr[c] = '\0';
  7898. strcpy(updateTypestr, sstr);
  7899. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7900. //localAuthorizationList
  7901. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7902. loc = strstr(sstrtemp, localAuthorizationListsearch);
  7903. if(loc != NULL) // localAuthorizationList is not NULL
  7904. {
  7905. //Check UpdateType
  7906. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7907. {
  7908. //Local list full update
  7909. printf("Local list full update.\n");
  7910. OCPP_getListVerion();
  7911. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7912. {
  7913. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7914. goto end;
  7915. }
  7916. OCPP_cleanLocalList();
  7917. }
  7918. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7919. {
  7920. //Local list different update
  7921. printf("Local list different update.\n");
  7922. OCPP_getListVerion();
  7923. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7924. {
  7925. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7926. goto end;
  7927. }
  7928. }
  7929. else
  7930. {
  7931. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7932. goto end;
  7933. }
  7934. c = 0;
  7935. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7936. {
  7937. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7938. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7939. c++;
  7940. }
  7941. sstr[c] = '\0';
  7942. //DEBUG_INFO("sstr=%s\n", sstr);
  7943. //parsing strings to words
  7944. i = 0;
  7945. pch = strtok(sstr,delim1);
  7946. while (pch != NULL)
  7947. {
  7948. strcpy(CardList[i], pch);
  7949. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7950. pch = strtok (NULL, delim1);
  7951. i = i + 1;
  7952. }
  7953. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7954. //local Authorizations List Numbers
  7955. //n_localAuthorizations = i;
  7956. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7957. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7958. c= 0;
  7959. while(c < i) // i is CardList Number
  7960. {
  7961. //Search "IdToken"
  7962. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7963. loc = strstr(CardList[c], "idTag");
  7964. int j = 0;
  7965. while (loc[3+strlen("idTag")+j] != '\"')
  7966. {
  7967. sstr[j] = loc[3+strlen("idTag")+j];
  7968. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7969. j++;
  7970. }
  7971. sstr[j] = '\0';
  7972. strcpy(idTagstr, sstr);
  7973. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7974. //Search "expiryDate"
  7975. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7976. loc = strstr(CardList[c], "expiryDate");
  7977. j = 0;
  7978. if(loc != NULL)
  7979. {
  7980. while (loc[3+strlen("expiryDate")+j] != '\"')
  7981. {
  7982. sstr[j] = loc[3+strlen("expiryDate")+j];
  7983. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7984. j++;
  7985. }
  7986. sstr[j] = '\0';
  7987. strcpy(expiryDate, sstr);
  7988. }
  7989. else
  7990. {
  7991. strcpy(expiryDate, "");
  7992. }
  7993. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7994. //Search "parentIdTag"
  7995. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7996. loc = strstr(CardList[c], "parentIdTag");
  7997. j = 0;
  7998. if(loc != NULL)
  7999. {
  8000. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8001. {
  8002. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8003. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8004. j++;
  8005. }
  8006. sstr[j] = '\0';
  8007. strcpy(parentIdTag, sstr);
  8008. }
  8009. else
  8010. {
  8011. strcpy(parentIdTag, "");
  8012. }
  8013. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8014. //Search "status"
  8015. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8016. loc = strstr(CardList[c], "status");
  8017. j = 0;
  8018. while (loc[3+strlen("status")+j] != '\"')
  8019. {
  8020. sstr[j] = loc[3+strlen("status")+j];
  8021. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8022. j++;
  8023. }
  8024. sstr[j] = '\0';
  8025. strcpy(idTagstatus, sstr);
  8026. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8027. OCPP_getIdTag(idTagstr);
  8028. //OCPP_getIdTag("test"); For Test
  8029. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8030. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8031. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8032. {
  8033. //Local list full update
  8034. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8035. // update list
  8036. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8037. //DEBUG_INFO("Local list full update. 1\n");
  8038. //OCPP_get_TableAuthlocalAllData();
  8039. //DEBUG_INFO("Local list full update. 2\n");
  8040. }
  8041. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8042. {
  8043. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8044. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8045. }
  8046. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8047. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8048. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8049. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8050. c++;
  8051. }
  8052. }
  8053. else
  8054. {
  8055. //Check UpdateType
  8056. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8057. {
  8058. //Local list full update
  8059. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8060. OCPP_cleanLocalList();
  8061. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8062. goto end;
  8063. }
  8064. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8065. {
  8066. //Local list different update
  8067. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8068. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8069. goto end;
  8070. }
  8071. }
  8072. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8073. end:
  8074. sendSendLocalListConfirmation(uuid, comfirmstr);
  8075. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8076. return result;
  8077. }
  8078. #define MAX 200
  8079. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8080. {
  8081. mtrace();
  8082. int result = FAIL;
  8083. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8084. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8085. char chargingProfilePurposeStr[30]={0};
  8086. char chargingProfileKindStr[16]={0};
  8087. char recurrencyKindStr[10]={0};
  8088. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8089. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8090. int chargingSchedulePeriodCount = 0;
  8091. //int updateflag = FALSE;
  8092. char comfirmstr[20]={0};
  8093. int meet= FALSE;
  8094. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8095. int c = 0;
  8096. char *loc;
  8097. FILE *fptr1;//, *fptr2;
  8098. //int lno=0;//, linectr = 0;
  8099. //int modifyflag = FALSE;
  8100. char filename[MAX]={0};
  8101. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8102. //int resultRename=0;
  8103. char rmFileCmd[50]={0};
  8104. char tempchargingProfilePurposeStr[30]={0};
  8105. char word[1600]={0};
  8106. int n_chargingProfile = 0;
  8107. //[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}}}]
  8108. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8109. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8110. //Filter string space
  8111. strcpy(sstrtemp, stringtrimspace(payload));
  8112. //*********************connectorId***************************/
  8113. loc = strstr(sstrtemp, "connectorId");
  8114. c = 0;
  8115. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8116. while (loc[strlen("connectorId")+2+c] != ',')
  8117. {
  8118. sstr[c] = loc[strlen("connectorId")+2+c];
  8119. c++;
  8120. }
  8121. sstr[c] = '\0';
  8122. connectorIdInt = atoi(sstr);
  8123. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8124. {
  8125. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8126. }
  8127. else
  8128. {
  8129. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8130. }
  8131. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8132. //*********************chargingProfileId***************************/
  8133. loc = strstr(sstrtemp, "chargingProfileId");
  8134. c = 0;
  8135. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8136. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8137. {
  8138. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8139. c++;
  8140. }
  8141. sstr[c] = '\0';
  8142. chargingProfileIdInt = atoi(sstr);
  8143. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8144. {
  8145. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8146. }
  8147. else
  8148. {
  8149. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8150. }
  8151. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8152. //*********************transactionId***************************/
  8153. loc = strstr(sstrtemp, "transactionId");
  8154. if(loc != NULL)
  8155. {
  8156. c = 0;
  8157. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8158. while (loc[strlen("transactionId")+2+c] != ',')
  8159. {
  8160. sstr[c] = loc[strlen("transactionId")+2+c];
  8161. c++;
  8162. }
  8163. sstr[c] = '\0';
  8164. transactionIdInt = atoi(sstr);
  8165. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8166. {
  8167. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8168. }
  8169. else
  8170. {
  8171. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8172. }
  8173. }
  8174. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8175. //*********************stackLevel***************************/
  8176. loc = strstr(sstrtemp, "stackLevel");
  8177. c = 0;
  8178. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8179. while (loc[strlen("stackLevel")+2+c] != ',')
  8180. {
  8181. sstr[c] = loc[strlen("stackLevel")+2+c];
  8182. c++;
  8183. }
  8184. sstr[c] = '\0';
  8185. stackLevelInt = atoi(sstr);
  8186. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8187. {
  8188. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8189. }
  8190. else
  8191. {
  8192. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8193. }
  8194. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8195. //*********************chargingProfilePurpose***************************/
  8196. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8197. c = 0;
  8198. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8199. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8200. {
  8201. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8202. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8203. c++;
  8204. }
  8205. sstr[c] = '\0';
  8206. strcpy(chargingProfilePurposeStr,sstr);
  8207. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8208. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8209. {
  8210. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8211. }
  8212. else
  8213. {
  8214. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8215. }
  8216. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8217. //*********************chargingProfileKind***************************/
  8218. loc = strstr(sstrtemp, "chargingProfileKind");
  8219. c = 0;
  8220. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8221. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8222. {
  8223. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8224. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8225. c++;
  8226. }
  8227. sstr[c] = '\0';
  8228. strcpy(chargingProfileKindStr,sstr);
  8229. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8230. {
  8231. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8232. }
  8233. else
  8234. {
  8235. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8236. }
  8237. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8238. //*********************recurrencyKind***************************/
  8239. loc = strstr(sstrtemp, "recurrencyKind");
  8240. if(loc != NULL)
  8241. {
  8242. c = 0;
  8243. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8244. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8245. {
  8246. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8247. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8248. c++;
  8249. }
  8250. sstr[c] = '\0';
  8251. strcpy(recurrencyKindStr,sstr);
  8252. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8253. {
  8254. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8255. }
  8256. else
  8257. {
  8258. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8259. }
  8260. }
  8261. else
  8262. {
  8263. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8264. {
  8265. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8266. }
  8267. else
  8268. {
  8269. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8270. }
  8271. }
  8272. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8273. //*********************validFrom***************************/
  8274. loc = strstr(sstrtemp, "validFrom");
  8275. if(loc != NULL)
  8276. {
  8277. c = 0;
  8278. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8279. while (loc[3+strlen("validFrom")+c] != '\"')
  8280. {
  8281. sstr[c] = loc[3+strlen("validFrom")+c];
  8282. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8283. c++;
  8284. }
  8285. sstr[c] = '\0';
  8286. strcpy(validFromStr,sstr);
  8287. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8288. {
  8289. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8290. }
  8291. else
  8292. {
  8293. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8294. }
  8295. }
  8296. else
  8297. {
  8298. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8299. {
  8300. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8301. }
  8302. else
  8303. {
  8304. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8305. }
  8306. }
  8307. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8308. //*********************validTo***************************/
  8309. loc = strstr(sstrtemp, "validTo");
  8310. if(loc != NULL)
  8311. {
  8312. c = 0;
  8313. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8314. while (loc[3+strlen("validTo")+c] != '\"')
  8315. {
  8316. sstr[c] = loc[3+strlen("validTo")+c];
  8317. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8318. c++;
  8319. }
  8320. sstr[c] = '\0';
  8321. strcpy(validToStr,sstr);
  8322. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8323. {
  8324. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8325. }
  8326. else
  8327. {
  8328. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8329. }
  8330. }
  8331. else
  8332. {
  8333. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8334. {
  8335. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8336. }
  8337. else
  8338. {
  8339. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8340. }
  8341. }
  8342. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8343. //*********************duration***************************/
  8344. loc = strstr(sstrtemp, "duration");
  8345. if(loc != NULL)
  8346. {
  8347. c = 0;
  8348. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8349. while (loc[strlen("duration")+2+c] != ',')
  8350. {
  8351. sstr[c] = loc[strlen("duration")+2+c];
  8352. c++;
  8353. }
  8354. sstr[c] = '\0';
  8355. durationInt = atoi(sstr);
  8356. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8357. {
  8358. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8359. }
  8360. else
  8361. {
  8362. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8363. }
  8364. }
  8365. else
  8366. {
  8367. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8368. {
  8369. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8370. }
  8371. else
  8372. {
  8373. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8374. }
  8375. }
  8376. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8377. //*********************startSchedule***************************/
  8378. loc = strstr(sstrtemp, "startSchedule");
  8379. if(loc != NULL)
  8380. {
  8381. c = 0;
  8382. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8383. while (loc[3+strlen("startSchedule")+c] != '\"')
  8384. {
  8385. sstr[c] = loc[3+strlen("startSchedule")+c];
  8386. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8387. c++;
  8388. }
  8389. sstr[c] = '\0';
  8390. strcpy(startScheduleStr,sstr);
  8391. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8392. {
  8393. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8394. }
  8395. else
  8396. {
  8397. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8398. }
  8399. }
  8400. else
  8401. {
  8402. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8403. {
  8404. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8405. }
  8406. else
  8407. {
  8408. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8409. }
  8410. }
  8411. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8412. //*********************chargingRateUnit***************************/
  8413. loc = strstr(sstrtemp, "chargingRateUnit");
  8414. if(loc != NULL)
  8415. {
  8416. c = 0;
  8417. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8418. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8419. {
  8420. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8421. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8422. c++;
  8423. }
  8424. sstr[c] = '\0';
  8425. strcpy(chargingRateUnitStr,sstr);
  8426. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8427. {
  8428. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8429. }
  8430. else
  8431. {
  8432. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8433. }
  8434. }
  8435. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8436. //****************chargingSchedulePeriod count start*******************/
  8437. int what_len = strlen("startPeriod");
  8438. char tempChargingProfile[1600]={0};
  8439. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8440. char *where = tempChargingProfile;
  8441. if (what_len)
  8442. {
  8443. while ((where = strstr(where, "startPeriod"))) {
  8444. where += what_len;
  8445. chargingSchedulePeriodCount++;
  8446. }
  8447. }
  8448. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8449. {
  8450. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8451. goto end;
  8452. }
  8453. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8454. //where = payload;
  8455. int templength = 0;
  8456. //int searchstart = 0;
  8457. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8458. {
  8459. //****************startPeriod*******************/
  8460. c=0;
  8461. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8462. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8463. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8464. {
  8465. sstr[c] = loc[strlen("startPeriod")+2+c];
  8466. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8467. c++;
  8468. }
  8469. sstr[c] = '\0';
  8470. startPeriodInt[periodNums] = atoi(sstr);
  8471. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8472. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8473. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8474. {
  8475. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8476. }
  8477. else
  8478. {
  8479. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8480. }
  8481. templength = strlen("startPeriod")+2+c;
  8482. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8483. //****************limit*******************/
  8484. c=0;
  8485. loc = strstr(tempChargingProfile + templength, "limit");
  8486. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8487. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8488. {
  8489. sstr[c] = loc[strlen("limit")+2+c];
  8490. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8491. c++;
  8492. }
  8493. sstr[c] = '\0';
  8494. limitflaot[periodNums] = atof(sstr);
  8495. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8496. {
  8497. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8498. }
  8499. else
  8500. {
  8501. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8502. }
  8503. templength = templength + strlen("limit")+2+c;
  8504. //****************numberPhases*******************/
  8505. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8506. if(loc != NULL)
  8507. {
  8508. c=0;
  8509. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8510. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8511. {
  8512. sstr[c] = loc[strlen("numberPhases")+2+c];
  8513. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8514. c++;
  8515. }
  8516. sstr[c] = '\0';
  8517. numberPhasesInt[periodNums] = atoi(sstr);
  8518. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8519. {
  8520. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8521. }
  8522. else
  8523. {
  8524. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8525. }
  8526. templength = templength + strlen("numberPhases")+2+c;
  8527. }
  8528. //where = loc;
  8529. }
  8530. //****************chargingSchedulePeriod count end*******************/
  8531. //*********************minChargingRate***************************/
  8532. loc = strstr(sstrtemp, "minChargingRate");
  8533. if(loc != NULL)
  8534. {
  8535. c = 0;
  8536. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8537. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8538. {
  8539. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8540. c++;
  8541. }
  8542. sstr[c] = '\0';
  8543. minChargingRateFloat = atof(sstr);
  8544. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8545. {
  8546. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8547. }
  8548. else
  8549. {
  8550. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8551. }
  8552. }
  8553. else
  8554. {
  8555. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8556. {
  8557. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8558. }
  8559. else
  8560. {
  8561. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8562. }
  8563. }
  8564. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8565. {
  8566. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8567. if(connectorIdInt != 0)
  8568. {
  8569. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8570. goto end;
  8571. }
  8572. strcpy(filename, ChargePointMaxProfile_JSON );
  8573. fptr1 = fopen(filename, "r");
  8574. if (!fptr1)
  8575. {
  8576. //file not exist
  8577. DEBUG_INFO("Unable to open the input file!!\n");
  8578. fptr1 = fopen(filename, "w+");
  8579. }
  8580. else
  8581. {
  8582. //Check Charging Profile Count
  8583. while(fscanf(fptr1, "%s", word) != EOF)
  8584. {
  8585. //DEBUG_INFO("word=%s\n",word);
  8586. if(strstr(word, "chargingProfileId")!= NULL)
  8587. {
  8588. //DEBUG_INFO("test chargingProfileId \n");
  8589. n_chargingProfile = n_chargingProfile + 1;
  8590. //DEBUG_INFO("chargingProfileId Found\n");
  8591. }
  8592. }
  8593. }
  8594. fclose(fptr1);
  8595. }
  8596. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8597. {
  8598. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8599. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8600. {
  8601. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8602. goto end;
  8603. }
  8604. memset(filename, 0, ARRAY_SIZE(filename));
  8605. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8606. fptr1 = fopen(filename, "r");
  8607. if (!fptr1)
  8608. {
  8609. //file not exist
  8610. //DEBUG_INFO("Unable to open the input file!!\n");
  8611. fptr1 = fopen(filename, "w+");
  8612. }
  8613. else
  8614. {
  8615. //Check Charging Profile Count
  8616. while(fscanf(fptr1, "%s", word) != EOF)
  8617. {
  8618. //DEBUG_INFO("word=%s\n",word);
  8619. if(strstr(word, "chargingProfileId")!= NULL)
  8620. {
  8621. //DEBUG_INFO("test chargingProfileId \n");
  8622. n_chargingProfile = n_chargingProfile + 1;
  8623. //DEBUG_INFO("chargingProfileId Found\n");
  8624. }
  8625. }
  8626. }
  8627. fclose(fptr1);
  8628. }
  8629. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8630. {
  8631. //printf("set chargingProfile 1-4\n");
  8632. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8633. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8634. if(connectorIdInt == 0)
  8635. {
  8636. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8637. goto end;
  8638. }
  8639. int tempIndex = 0;
  8640. //check Transaction active
  8641. if(gunType[connectorIdInt -1] == 'J')
  8642. {
  8643. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8644. {
  8645. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8646. }
  8647. else
  8648. {
  8649. tempIndex = connectorIdInt -1;
  8650. }
  8651. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8652. {
  8653. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8654. {
  8655. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8656. {
  8657. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8658. {
  8659. meet = TRUE;
  8660. break;
  8661. }
  8662. }
  8663. }
  8664. }
  8665. }
  8666. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8667. {
  8668. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8669. {
  8670. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8671. }
  8672. else
  8673. {
  8674. tempIndex = connectorIdInt -1;
  8675. }
  8676. for (int index = 0; index < CCS_QUANTITY; index++)
  8677. {
  8678. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8679. {
  8680. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8681. {
  8682. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8683. {
  8684. meet = TRUE;
  8685. break;
  8686. }
  8687. }
  8688. }
  8689. }
  8690. }
  8691. else if(gunType[connectorIdInt -1] == 'G')
  8692. {
  8693. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8694. {
  8695. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8696. }
  8697. else
  8698. {
  8699. tempIndex = connectorIdInt -1;
  8700. }
  8701. for (int index = 0; index < GB_QUANTITY; index++)
  8702. {
  8703. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8704. {
  8705. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8706. {
  8707. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8708. {
  8709. meet = TRUE;
  8710. break;
  8711. }
  8712. }
  8713. }
  8714. }
  8715. }
  8716. else
  8717. {
  8718. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8719. {
  8720. tempIndex = 2;
  8721. }
  8722. else
  8723. {
  8724. tempIndex = (connectorIdInt -1);
  8725. }
  8726. for (int index = 0; index < AC_QUANTITY; index++)
  8727. {
  8728. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8729. {
  8730. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8731. {
  8732. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8733. {
  8734. meet = TRUE;
  8735. break;
  8736. }
  8737. }
  8738. }
  8739. }
  8740. }
  8741. //check Transaction active
  8742. if(meet == FALSE)
  8743. {
  8744. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8745. goto end;
  8746. }
  8747. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8748. {
  8749. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8750. goto end;
  8751. }
  8752. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8753. fptr1 = fopen(filename, "r");
  8754. if (!fptr1)
  8755. {
  8756. //file not exist
  8757. DEBUG_INFO("Unable to open the input file!!\n");
  8758. fptr1 = fopen(filename, "w+");
  8759. }
  8760. else
  8761. {
  8762. //Check Charging Profile Count
  8763. while(fscanf(fptr1, "%s", word) != EOF)
  8764. {
  8765. //DEBUG_INFO("word=%s\n",word);
  8766. if(strstr(word, "chargingProfileId")!= NULL)
  8767. {
  8768. //DEBUG_INFO("test chargingProfileId \n");
  8769. n_chargingProfile = n_chargingProfile + 1;
  8770. //DEBUG_INFO("chargingProfileId Found\n");
  8771. }
  8772. }
  8773. }
  8774. fclose(fptr1);
  8775. }
  8776. // Check ChargeProfileMaxStackLevel
  8777. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8778. {
  8779. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8780. goto end;
  8781. }
  8782. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8783. {
  8784. int i = 0;
  8785. char fnametemp[200]={0};
  8786. n_chargingProfile = 0;
  8787. //Check ChargePointMaxProfile.json exit
  8788. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8789. {
  8790. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8791. //Check Charging Profile Count
  8792. while(fscanf(fptr1, "%s", word) != EOF)
  8793. {
  8794. //DEBUG_INFO("word=%s\n",word);
  8795. if(strstr(word, "chargingProfileId")!= NULL)
  8796. {
  8797. //DEBUG_INFO("test chargingProfileId \n");
  8798. n_chargingProfile = n_chargingProfile + 1;
  8799. i = i + 1;
  8800. //DEBUG_INFO("chargingProfileId Found\n");
  8801. }
  8802. memset(word, 0, ARRAY_SIZE(word));
  8803. }
  8804. fclose(fptr1);
  8805. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8806. }
  8807. //Check TxDefaultProfile_0.json exit
  8808. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8809. {
  8810. i = 0;
  8811. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8812. //Check Charging Profile Count
  8813. while(fscanf(fptr1, "%s", word) != EOF)
  8814. {
  8815. //DEBUG_INFO("word=%s\n",word);
  8816. if(strstr(word, "chargingProfileId")!= NULL)
  8817. {
  8818. //DEBUG_INFO("test chargingProfileId \n");
  8819. n_chargingProfile = n_chargingProfile + 1;
  8820. i = i + 1;
  8821. //DEBUG_INFO("chargingProfileId Found\n");
  8822. }
  8823. memset(word, 0, ARRAY_SIZE(word));
  8824. }
  8825. fclose(fptr1);
  8826. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8827. }
  8828. //Check TxDefaultProfile_%d.json
  8829. for(int j=1; j <= gunTotalNumber; j++)
  8830. {
  8831. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8832. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8833. if((access(fnametemp,F_OK))!=-1)
  8834. {
  8835. i = 0;
  8836. fptr1 = fopen(fnametemp, "r");
  8837. //Check Charging Profile Count
  8838. while(fscanf(fptr1, "%s", word) != EOF)
  8839. {
  8840. //DEBUG_INFO("word=%s\n",word);
  8841. if(strstr(word, "chargingProfileId")!= NULL)
  8842. {
  8843. //DEBUG_INFO("test chargingProfileId \n");
  8844. n_chargingProfile = n_chargingProfile + 1;
  8845. i = i + 1;
  8846. //DEBUG_INFO("chargingProfileId Found\n");
  8847. }
  8848. memset(word, 0, ARRAY_SIZE(word));
  8849. }
  8850. fclose(fptr1);
  8851. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8852. }
  8853. }
  8854. //Check TxProfile_%d.json
  8855. for(int j=1; j <= gunTotalNumber; j++)
  8856. {
  8857. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8858. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8859. if((access(fnametemp,F_OK))!=-1)
  8860. {
  8861. i = 0;
  8862. fptr1 = fopen(fnametemp, "r");
  8863. //Check Charging Profile Count
  8864. while(fscanf(fptr1, "%s", word) != EOF)
  8865. {
  8866. //DEBUG_INFO("word=%s\n",word);
  8867. if(strstr(word, "chargingProfileId")!= NULL)
  8868. {
  8869. //DEBUG_INFO("test chargingProfileId \n");
  8870. n_chargingProfile = n_chargingProfile + 1;
  8871. i = i + 1;
  8872. //DEBUG_INFO("chargingProfileId Found\n");
  8873. }
  8874. memset(word, 0, ARRAY_SIZE(word));
  8875. }
  8876. fclose(fptr1);
  8877. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8878. }
  8879. }
  8880. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8881. {
  8882. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8883. goto end;
  8884. }
  8885. }
  8886. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8887. //**********************************Write to File********************************************************/
  8888. FILE *infile;
  8889. FILE *outfile;
  8890. // open file for writing
  8891. infile = fopen (filename, "r");
  8892. outfile = fopen (tempfile, "w");
  8893. int d =0;
  8894. d = fgetc(infile);
  8895. //DEBUG_INFO("d:%d\n",d);
  8896. rewind(infile);
  8897. //*璉 瘚 辣蝏     1嚗   0 */
  8898. if(d == EOF)
  8899. {
  8900. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8901. fprintf(outfile,"%s\n",payload);
  8902. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8903. fclose(infile);
  8904. fclose(outfile);
  8905. sprintf(rmFileCmd,"rm -f %s",filename);
  8906. system(rmFileCmd);
  8907. rename(tempfile, filename);
  8908. sleep(1);
  8909. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8910. //system(rmFileCmd);
  8911. }
  8912. else
  8913. {
  8914. char buf[1000]={0};
  8915. int ChargingProfileAdded = FALSE;
  8916. while (fgets(buf, sizeof(buf), infile) != NULL)
  8917. {
  8918. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8919. //*************************tempconnectorIdInt*********************************/
  8920. loc = strstr(buf, "connectorId");
  8921. c = 0;
  8922. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8923. while (loc[strlen("connectorId")+2+c] != ',')
  8924. {
  8925. sstr[c] = loc[strlen("connectorId")+2+c];
  8926. c++;
  8927. }
  8928. sstr[c] = '\0';
  8929. tempconnectorIdInt = atoi(sstr);
  8930. //*************************tempchargingProfileIdInt*********************************/
  8931. loc = strstr(buf, "chargingProfileId");
  8932. c = 0;
  8933. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8934. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8935. {
  8936. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8937. c++;
  8938. }
  8939. sstr[c] = '\0';
  8940. tempchargingProfileIdInt = atoi(sstr);
  8941. //*************************tempstackLevelInt*********************************/
  8942. loc = strstr(buf, "stackLevel");
  8943. c = 0;
  8944. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8945. while (loc[strlen("stackLevel")+2+c] != ',')
  8946. {
  8947. sstr[c] = loc[strlen("stackLevel")+2+c];
  8948. c++;
  8949. }
  8950. sstr[c] = '\0';
  8951. tempstackLevelInt = atoi(sstr);
  8952. //*************************tempchargingProfilePurposeStr*********************************/
  8953. loc = strstr(payload, "chargingProfilePurpose");
  8954. c = 0;
  8955. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8956. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8957. {
  8958. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8959. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8960. c++;
  8961. }
  8962. sstr[c] = '\0';
  8963. strcpy(tempchargingProfilePurposeStr,sstr);
  8964. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  8965. {
  8966. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8967. {
  8968. //DEBUG_INFO("update set chargingProfile to file -0\n");
  8969. if(ChargingProfileAdded == FALSE)
  8970. {
  8971. fprintf(outfile,"%s\n",payload);
  8972. ChargingProfileAdded = TRUE;
  8973. }
  8974. }
  8975. else
  8976. {
  8977. if(tempstackLevelInt < stackLevelInt)
  8978. {
  8979. if(ChargingProfileAdded == FALSE)
  8980. {
  8981. fprintf(outfile,"%s\n",payload);
  8982. ChargingProfileAdded = TRUE;
  8983. fprintf(outfile,"%s\n",buf);
  8984. }
  8985. else
  8986. {
  8987. fprintf(outfile,"%s\n",buf);
  8988. }
  8989. }
  8990. else
  8991. {
  8992. if(ChargingProfileAdded == FALSE)
  8993. {
  8994. fprintf(outfile,"%s\n",buf);
  8995. fprintf(outfile,"%s\n",payload);
  8996. ChargingProfileAdded = TRUE;
  8997. }
  8998. else
  8999. {
  9000. fprintf(outfile,"%s\n",buf);
  9001. }
  9002. }
  9003. }
  9004. }
  9005. else
  9006. {
  9007. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9008. {
  9009. if(ChargingProfileAdded == FALSE)
  9010. {
  9011. fprintf(outfile,"%s\n",payload);
  9012. ChargingProfileAdded = TRUE;
  9013. fprintf(outfile,"%s\n",buf);
  9014. }
  9015. else
  9016. {
  9017. fprintf(outfile,"%s\n",buf);
  9018. }
  9019. }
  9020. else if(tempstackLevelInt < stackLevelInt)
  9021. {
  9022. if(ChargingProfileAdded == FALSE)
  9023. {
  9024. fprintf(outfile,"%s\n",payload);
  9025. ChargingProfileAdded = TRUE;
  9026. fprintf(outfile,"%s\n",buf);
  9027. }
  9028. else
  9029. {
  9030. fprintf(outfile,"%s\n",buf);
  9031. }
  9032. }
  9033. else
  9034. {
  9035. if(ChargingProfileAdded == FALSE)
  9036. {
  9037. fprintf(outfile,"%s\n",buf);
  9038. fprintf(outfile,"%s\n",payload);
  9039. ChargingProfileAdded = TRUE;
  9040. }
  9041. else
  9042. {
  9043. fprintf(outfile,"%s\n",buf);
  9044. }
  9045. }
  9046. }
  9047. } // end of while loop
  9048. fclose(infile);
  9049. fclose(outfile);
  9050. sprintf(rmFileCmd,"rm -f %s",filename);
  9051. system(rmFileCmd);
  9052. rename(tempfile, filename);
  9053. sleep(1);
  9054. result = TRUE;
  9055. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9056. }
  9057. end:
  9058. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9059. return result;
  9060. return result;
  9061. }
  9062. int handleTriggerMessageRequest(char *uuid, char *payload)
  9063. {
  9064. mtrace();
  9065. int result = FAIL;
  9066. int connectorIdIsNULL = FALSE;
  9067. int connectorIdInt =0;
  9068. char sstr[40]={0},sstrtemp[100]={ 0 };
  9069. char requestedMessagestr[40]={0};
  9070. char comfirmstr[20]={0};
  9071. int c = 0;
  9072. char *loc;
  9073. DEBUG_INFO("handleTriggerMessageRequest\n");
  9074. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9075. strcpy(sstrtemp, stringtrimspace(payload));
  9076. c = 0;
  9077. loc = strstr(sstrtemp, "requestedMessage");
  9078. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9079. {
  9080. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9081. c++;
  9082. }
  9083. sstr[c] = '\0';
  9084. strcpy(requestedMessagestr, sstr);
  9085. c = 0;
  9086. loc = strstr(sstrtemp, "connectorId");
  9087. if(loc == NULL)
  9088. {
  9089. connectorIdIsNULL = TRUE;
  9090. }
  9091. else
  9092. {
  9093. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9094. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9095. {
  9096. sstr[c] = loc[strlen("connectorId")+2+c];
  9097. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9098. c++;
  9099. }
  9100. sstr[c] = '\0';
  9101. connectorIdInt = atoi(sstr);
  9102. }
  9103. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  9104. {
  9105. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9106. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9107. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9108. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9109. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9110. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9111. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9112. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9113. {
  9114. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9115. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9116. return TRUE;
  9117. }
  9118. else
  9119. {
  9120. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9121. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9122. }
  9123. }
  9124. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9125. {
  9126. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9127. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9128. return TRUE;
  9129. }
  9130. //==========================
  9131. // Trigger message
  9132. //==========================
  9133. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9134. {
  9135. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9136. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9137. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9138. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9139. {
  9140. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9141. }
  9142. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9143. }
  9144. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9145. {
  9146. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9147. }
  9148. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9149. {
  9150. //sendBootNotificationRequest();
  9151. server_sign = FALSE;
  9152. }
  9153. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9154. {
  9155. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9156. }
  9157. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9158. {
  9159. if(connectorIdIsNULL == FALSE)
  9160. {
  9161. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9162. {
  9163. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9164. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  9165. }
  9166. }
  9167. else
  9168. {
  9169. for(int idx=0;idx< gunTotalNumber;idx++)
  9170. {
  9171. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9172. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  9173. }
  9174. }
  9175. }
  9176. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9177. {
  9178. if(connectorIdIsNULL == FALSE)
  9179. {
  9180. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9181. {
  9182. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9183. }
  9184. }
  9185. else
  9186. {
  9187. for(int idx=0;idx< gunTotalNumber;idx++)
  9188. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9189. }
  9190. }
  9191. return result;
  9192. }
  9193. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9194. {
  9195. mtrace();
  9196. int result = FAIL;
  9197. int connectorIdInt =0;
  9198. char comfirmstr[20]={0};
  9199. int tempIndex = 0;
  9200. json_object *UnlockConnector;
  9201. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9202. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9203. UnlockConnector = json_tokener_parse(payload);
  9204. if(!is_error(UnlockConnector))
  9205. {
  9206. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  9207. {
  9208. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  9209. }
  9210. }
  9211. json_object_put(UnlockConnector);
  9212. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  9213. if(gunTotalNumber == 0)
  9214. {
  9215. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9216. goto end;
  9217. }
  9218. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9219. {
  9220. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9221. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9222. goto end;
  9223. }
  9224. else
  9225. {
  9226. //check Transaction active
  9227. if(gunType[connectorIdInt-1] == 'J')
  9228. {
  9229. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9230. {
  9231. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9232. }
  9233. else
  9234. {
  9235. tempIndex = connectorIdInt -1;
  9236. }
  9237. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9238. {
  9239. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9240. {
  9241. //stop Transaction
  9242. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9243. }
  9244. }
  9245. }
  9246. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9247. {
  9248. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9249. {
  9250. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9251. }
  9252. else
  9253. {
  9254. tempIndex = connectorIdInt -1;
  9255. }
  9256. for (int index = 0; index < CCS_QUANTITY; index++)
  9257. {
  9258. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9259. {
  9260. //stop Transaction
  9261. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9262. }
  9263. }
  9264. }
  9265. else if(gunType[connectorIdInt-1] == 'G')
  9266. {
  9267. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9268. {
  9269. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9270. }
  9271. else
  9272. {
  9273. tempIndex = connectorIdInt -1;
  9274. }
  9275. for (int index = 0; index < GB_QUANTITY; index++)
  9276. {
  9277. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9278. {
  9279. //stop Transaction
  9280. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9281. }
  9282. }
  9283. }
  9284. else
  9285. {
  9286. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9287. {
  9288. tempIndex = 2;
  9289. }
  9290. else
  9291. {
  9292. tempIndex = connectorIdInt-1;
  9293. }
  9294. for (int index = 0; index < AC_QUANTITY; index++)
  9295. {
  9296. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9297. {
  9298. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9299. }
  9300. }
  9301. }
  9302. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9303. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9304. result = TRUE;
  9305. return result;
  9306. }
  9307. end:
  9308. //json_object_put(obj); --- remove temporally
  9309. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9310. return result;
  9311. }
  9312. static char UpdateFirmwarepayloadData[300]={0};
  9313. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9314. {
  9315. mtrace();
  9316. int result = FAIL;
  9317. pthread_t t;
  9318. sendUpdateFirmwareConfirmation(uuid);
  9319. memset(UpdateFirmwarepayloadData, 0, 300);
  9320. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9321. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9322. ////pthread_join(t, NULL); //
  9323. //pthread_detach(t);
  9324. //sendUpdateFirmwareConfirmation(uuid);
  9325. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9326. return result;
  9327. }
  9328. void *UpdateFirmwareProcess(void *data)
  9329. {
  9330. pthread_detach(pthread_self());
  9331. mtrace();
  9332. int retriesInt =0, retryIntervalInt=0;
  9333. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9334. int port=0;
  9335. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9336. int isSuccess = 0;
  9337. char ftpbuf[200];
  9338. char temp[100];
  9339. char * pch;
  9340. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9341. json_object *UpdateFirmware;
  9342. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  9343. if(!is_error(UpdateFirmware))
  9344. {
  9345. // Required data
  9346. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  9347. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  9348. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  9349. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  9350. // Optional data
  9351. if(json_object_object_get(UpdateFirmware, "retries"))
  9352. {
  9353. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  9354. }
  9355. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  9356. {
  9357. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  9358. }
  9359. }
  9360. json_object_put(UpdateFirmware);
  9361. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9362. memset(path, 0, ARRAY_SIZE(path));
  9363. system("rm -f /mnt/*");
  9364. if(strncmp(locationstr,"http", 4) == 0)
  9365. {
  9366. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9367. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9368. // protocol, user, password, host, path);
  9369. sprintf(ftppath,"/%s", path);
  9370. DEBUG_INFO("locationstr: %s\n", locationstr);
  9371. DEBUG_INFO("protocol: %s\n",protocol);
  9372. DEBUG_INFO("host: %s\n",host);
  9373. DEBUG_INFO("path: %s\n",path);
  9374. DEBUG_INFO("ftppath: %s\n",ftppath);
  9375. int ftppathlen=strlen(ftppath);
  9376. int i=1;
  9377. char filenametemp[50];
  9378. while(i < ftppathlen)
  9379. {
  9380. int len=ftppathlen-i;
  9381. if(ftppath[len]== 47) // '/' ascll code: 47
  9382. {
  9383. DEBUG_INFO("compare '/' all right\n");
  9384. break;
  9385. }
  9386. i=i+1;
  9387. }
  9388. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9389. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9390. filenametemp[i+1] = 0;
  9391. do
  9392. {
  9393. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9394. sleep(3);
  9395. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9396. if(!isSuccess)
  9397. {
  9398. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9399. sleep(retryIntervalInt);
  9400. }
  9401. else
  9402. {
  9403. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9404. }
  9405. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9406. }
  9407. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9408. {
  9409. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9410. memset(temp, 0, ARRAY_SIZE(temp));
  9411. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9412. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9413. int ftppathlen=strlen(ftpbuf);
  9414. int i=1;
  9415. char filenametemp[50];
  9416. while(i < ftppathlen)
  9417. {
  9418. int len=ftppathlen-i;
  9419. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9420. {
  9421. DEBUG_INFO(" compare '/' all right\n");
  9422. break;
  9423. }
  9424. i=i+1;
  9425. }
  9426. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9427. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9428. filenametemp[i+1] = 0;
  9429. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9430. pch=strchr(temp,'@');
  9431. if(pch==NULL)
  9432. {
  9433. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9434. protocol, host, &port, path);
  9435. strcpy(user,"anonymous");
  9436. strcpy(password,"");
  9437. }
  9438. else
  9439. {
  9440. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9441. protocol, user, password, host, &port, path);
  9442. }
  9443. sscanf(host,"%[^/]%s",host1, path1);
  9444. sprintf(ftppath,"%s", path1);
  9445. //DEBUG_INFO("protocol =%s\n",protocol);
  9446. //DEBUG_INFO("user =%s\n",user);
  9447. //DEBUG_INFO("password =%s\n",password);
  9448. //DEBUG_INFO("host1 =%s\n",host1);
  9449. //DEBUG_INFO("port =%d\n",port);
  9450. //DEBUG_INFO("path1 =%s\n",path1);
  9451. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9452. //ftpFile(host, user, password, port, ftppath, fname);
  9453. //download firmware pthred
  9454. if(port == 0)
  9455. {
  9456. port = 21;
  9457. }
  9458. do
  9459. {
  9460. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9461. sleep(3);
  9462. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9463. if(!isSuccess)
  9464. {
  9465. //BulldogUtil.sleepMs(interval*1000);
  9466. DEBUG_INFO("Update firmware request and download file fail.\n");
  9467. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9468. sleep(retryIntervalInt);
  9469. }
  9470. else
  9471. {
  9472. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9473. }
  9474. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9475. }
  9476. else
  9477. {
  9478. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9479. }
  9480. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9481. pthread_exit(NULL);
  9482. }
  9483. //==========================================
  9484. // Handle server response routine
  9485. //==========================================
  9486. void handleAuthorizeResponse(char *payload, int gun_index)
  9487. {
  9488. mtrace();
  9489. char expiryDatestr[30]={0};
  9490. char parentIdTagstr[20]={0};
  9491. char statusstr[20]={0};
  9492. char expiryDatestrtemp[30]={0};
  9493. char parentIdTagstrtemp[20]={0};
  9494. char IdTagstrtemp[20]={0};
  9495. char statusstrtemp[20]={0};
  9496. int expiryDateISNULL=FALSE;
  9497. int parentIdTagISNULL=FALSE;
  9498. char sstr[160]={0};
  9499. char* filename = AuthorizationCache_JSON;
  9500. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9501. char *loc;
  9502. int resultRename=0;
  9503. int responseIdTagInfoAsZero= 0;
  9504. char rmFileCmd[50]={0};
  9505. DEBUG_INFO("handleAuthorizeResponse...\n");
  9506. json_object *Authorize;
  9507. Authorize = json_tokener_parse(payload);
  9508. if(!is_error(Authorize))
  9509. {
  9510. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9511. {
  9512. // Required data
  9513. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9514. // Optional data
  9515. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9516. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9517. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9518. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9519. }
  9520. }
  9521. json_object_put(Authorize);
  9522. if(expiryDateISNULL == FALSE)
  9523. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9524. if(parentIdTagISNULL == FALSE)
  9525. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9526. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9527. //Update idTag information to authorization cache if supproted
  9528. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9529. {
  9530. if((access(filename,F_OK))!=-1)
  9531. {
  9532. printf("AuthorizationCache exist.\n");
  9533. }
  9534. else
  9535. {
  9536. printf("AuthorizationCache not exist\n");
  9537. FILE *log = fopen(filename, "w+");
  9538. if(log == NULL)
  9539. {
  9540. printf("log is NULL\n");
  9541. goto out;
  9542. }
  9543. else
  9544. {
  9545. fclose(log);
  9546. }
  9547. }
  9548. FILE *infile;
  9549. FILE *outfile;
  9550. // open file for writing
  9551. infile = fopen (filename, "r");
  9552. outfile = fopen (tempfile, "w");
  9553. int c;
  9554. c = fgetc(infile);
  9555. //DEBUG_INFO("c:%d\n",c);
  9556. rewind(infile);
  9557. if(c == EOF)
  9558. {
  9559. DEBUG_INFO("Orignal File is NULL\n");
  9560. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9561. {
  9562. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9563. }
  9564. else
  9565. {
  9566. strcpy(expiryDatestrtemp, "");
  9567. }
  9568. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9569. {
  9570. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9571. }
  9572. else
  9573. {
  9574. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9575. }
  9576. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9577. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9578. fclose(infile);
  9579. fclose(outfile);
  9580. sprintf(rmFileCmd,"rm -f %s",filename);
  9581. system(rmFileCmd);
  9582. resultRename = rename(tempfile, filename);
  9583. if(resultRename == 0)
  9584. {
  9585. printf("File renamed successfully");
  9586. }
  9587. else
  9588. {
  9589. printf("Error: unable to rename the file");
  9590. }
  9591. }
  9592. else
  9593. {
  9594. char buf[160]={0};
  9595. while (fgets(buf, ARRAY_SIZE(buf), infile) != NULL)
  9596. {
  9597. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9598. memset(expiryDatestr, 0, ARRAY_SIZE(expiryDatestrtemp));
  9599. memset(parentIdTagstr,0, ARRAY_SIZE(parentIdTagstrtemp));
  9600. memset(statusstr, 0, ARRAY_SIZE(statusstrtemp));
  9601. memset(IdTagstrtemp, 0, ARRAY_SIZE(IdTagstrtemp));
  9602. memset(expiryDatestrtemp, 0, ARRAY_SIZE(expiryDatestrtemp));
  9603. memset(parentIdTagstrtemp, 0, ARRAY_SIZE(parentIdTagstrtemp));
  9604. memset(statusstrtemp, 0, ARRAY_SIZE(statusstrtemp));
  9605. //------------------IdTag-----------------------
  9606. loc = strstr(buf, "idTag");
  9607. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9608. c = 0;
  9609. while (loc[3+strlen("idTag")+c] != '\"')
  9610. {
  9611. sstr[c] = loc[3+strlen("idTag")+c];
  9612. c++;
  9613. }
  9614. sstr[c] = '\0';
  9615. strcpy(IdTagstrtemp,sstr);
  9616. //*********************expiryDate***************/
  9617. loc = strstr(buf, "expiryDate");
  9618. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9619. c = 0;
  9620. while (loc[3+strlen("expiryDate")+c] != '\"')
  9621. {
  9622. sstr[c] = loc[3+strlen("expiryDate")+c];
  9623. c++;
  9624. }
  9625. sstr[c] = '\0';
  9626. strcpy(expiryDatestr,sstr);
  9627. //*********************parentIdTag***************/
  9628. loc = strstr(buf, "parentIdTag");
  9629. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9630. c = 0;
  9631. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9632. {
  9633. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9634. c++;
  9635. }
  9636. sstr[c] = '\0';
  9637. strcpy(parentIdTagstr,sstr);
  9638. //*********************status***************/
  9639. loc = strstr(buf, "status");
  9640. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9641. c = 0;
  9642. while (loc[3+strlen("status")+c] != '\"')
  9643. {
  9644. sstr[c] = loc[3+strlen("status")+c];
  9645. c++;
  9646. }
  9647. sstr[c] = '\0';
  9648. strcpy(statusstr,sstr);
  9649. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9650. {
  9651. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9652. responseIdTagInfoAsZero = 1;
  9653. }
  9654. else
  9655. {
  9656. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9657. }
  9658. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9659. {
  9660. //modify item
  9661. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9662. {
  9663. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9664. }
  9665. else
  9666. {
  9667. strcpy(expiryDatestrtemp, "");
  9668. }
  9669. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9670. {
  9671. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9672. }
  9673. else
  9674. {
  9675. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9676. }
  9677. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9678. }
  9679. else
  9680. {
  9681. //wrie original item
  9682. strcpy(expiryDatestrtemp, expiryDatestr);
  9683. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9684. strcpy(statusstrtemp, statusstr);
  9685. }
  9686. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9687. }
  9688. fclose(infile);
  9689. fclose(outfile);
  9690. sprintf(rmFileCmd,"rm -f %s",filename);
  9691. system(rmFileCmd);
  9692. resultRename = rename(tempfile, filename);
  9693. if(resultRename == 0)
  9694. {
  9695. DEBUG_INFO("File renamed successfully");
  9696. }
  9697. else
  9698. {
  9699. DEBUG_INFO("Error: unable to rename the file");
  9700. }
  9701. }
  9702. }
  9703. out:
  9704. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9705. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9706. authorizeRetryTimes = 0;
  9707. }
  9708. char * strtrimc( char * s )
  9709. {
  9710. char * p1 = s;
  9711. char * p2 = s;
  9712. while(*p1 != '\0')
  9713. {
  9714. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9715. {
  9716. if(*p1 != ',')
  9717. {
  9718. p1 ++;
  9719. }
  9720. else
  9721. {
  9722. break;
  9723. }
  9724. }
  9725. if(*p1 != ',')
  9726. {
  9727. * p2 ++ = *p1 ++;
  9728. //printf("p2=%s\n",p2);
  9729. }
  9730. else
  9731. {
  9732. break;
  9733. }
  9734. }
  9735. *p2 = '\0';
  9736. return (s);
  9737. }
  9738. void handleBootNotificationResponse(char *payload, int gun_index)
  9739. {
  9740. mtrace();
  9741. char statusStr[12]={0};
  9742. char currentTimeStr[30]={0};
  9743. int intervalInt = 0;
  9744. struct tm tp;
  9745. char buf[28]={0};
  9746. char timebuf[50]={0};
  9747. DEBUG_INFO("handleBootNotificationResponse...\n");
  9748. json_object *BootNotification;
  9749. BootNotification = json_tokener_parse(payload);
  9750. if(!is_error(BootNotification))
  9751. {
  9752. // Required data
  9753. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9754. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9755. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9756. }
  9757. json_object_put(BootNotification);
  9758. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9759. BootNotificationInterval = intervalInt;
  9760. HeartBeatWaitTime = intervalInt;
  9761. //write back to ShmOCPP16Data->BootNotification
  9762. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9763. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9764. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9765. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9766. {
  9767. server_sign = TRUE;
  9768. server_pending =FALSE;
  9769. }
  9770. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9771. {
  9772. server_pending = TRUE;
  9773. }
  9774. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9775. tp.tm_isdst = -1;
  9776. //time_t utc = mktime(&tp);
  9777. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9778. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9779. sprintf(timebuf,"date -s '%s'",buf);
  9780. system(timebuf);
  9781. srand(time(NULL));
  9782. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9783. //==============================================
  9784. // RTC sync
  9785. //==============================================
  9786. system("/sbin/hwclock -w --systohc");
  9787. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9788. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9789. }
  9790. void handleDataTransferResponse(char *payload, int gun_index)
  9791. {
  9792. char sstr[160]={0};//sstr[200]={ 0 };
  9793. int c = 0;
  9794. char *loc;
  9795. DEBUG_INFO("handleDataTransferResponse ...\n");
  9796. loc = strstr(payload, "status");
  9797. printf("loc=%s\n",loc);
  9798. c = 0;
  9799. while (loc[3+strlen("status")+c] != '\"')
  9800. {
  9801. sstr[c] = loc[3+strlen("status")+c];
  9802. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9803. c++;
  9804. }
  9805. sstr[c] = '\0';
  9806. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9807. }
  9808. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9809. {
  9810. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9811. //struct json_object *obj;
  9812. // obj = json_tokener_parse(payload);
  9813. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9814. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9815. //No fields are defined.
  9816. }
  9817. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9818. {
  9819. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9820. //struct json_object *obj;
  9821. // obj = json_tokener_parse(payload);
  9822. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9823. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9824. //No fields are defined.
  9825. }
  9826. void handleHeartbeatResponse(char *payload, int gun_index)
  9827. {
  9828. mtrace();
  9829. struct tm tp;
  9830. char buf[28]={0};
  9831. char timebuf[50]={0};
  9832. DEBUG_INFO("handleHeartbeatResponse...\n");
  9833. json_object *Heartbeat;
  9834. Heartbeat = json_tokener_parse(payload);
  9835. if(!is_error(Heartbeat))
  9836. {
  9837. // Required data
  9838. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9839. }
  9840. json_object_put(BootNotification);
  9841. if(FirstHeartBeat == 0)
  9842. {
  9843. FirstHeartBeat = 1;
  9844. DEBUG_INFO("FirstHeartBeat \n");
  9845. }
  9846. HeartBeatWithNOResponse = 0;
  9847. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9848. tp.tm_isdst = -1;
  9849. //time_t utc = mktime(&tp);
  9850. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9851. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9852. sprintf(timebuf,"date -s '%s'",buf);
  9853. system(timebuf);
  9854. //==============================================
  9855. // RTC sync
  9856. //==============================================
  9857. system("/sbin/hwclock -w --systohc");
  9858. //===============================================
  9859. //Print Out HeartBeat log
  9860. //===============================================
  9861. {
  9862. double diff_t;
  9863. struct tm tp,tp1;
  9864. // BootNotification Receive Time
  9865. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9866. tp.tm_isdst = -1;
  9867. time_t BootNotificationReceiveTime = mktime(&tp);
  9868. //HeartBeat Receive Time
  9869. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  9870. tp1.tm_isdst = -1;
  9871. time_t HeartBeatReceiveTime = mktime(&tp1);
  9872. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  9873. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  9874. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  9875. {
  9876. HeartBeatCountPerHour = (int)diff_t / 3600;
  9877. DEBUG_INFO("handleHeartbeatResponse ...\n");
  9878. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  9879. }
  9880. }
  9881. }
  9882. void handleMeterValuesResponse(char *payload, int gun_index)
  9883. {
  9884. mtrace();
  9885. DEBUG_INFO("handleMeterValuesResponse...\n");
  9886. }
  9887. void handleStartTransactionResponse(char *payload, int gun_index)
  9888. {
  9889. mtrace();
  9890. //int transactionIdInt = 0;
  9891. FILE *outfile;
  9892. char data[100]={0};
  9893. DEBUG_INFO("handleStartTransactionResponse...\n");
  9894. json_object *StartTransaction;
  9895. StartTransaction = json_tokener_parse(payload);
  9896. if(!is_error(StartTransaction))
  9897. {
  9898. // Required data
  9899. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  9900. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  9901. // Optional data
  9902. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  9903. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  9904. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9905. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  9906. }
  9907. json_object_put(StartTransaction);
  9908. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9909. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9910. //-----------Start : write to the Queue TransactionId file -----------------//
  9911. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9912. {}
  9913. else
  9914. {
  9915. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9916. if(log == NULL)
  9917. {
  9918. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9919. return ;
  9920. }
  9921. else
  9922. {
  9923. fclose(log);
  9924. }
  9925. }
  9926. // open file for writing
  9927. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  9928. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  9929. {
  9930. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9931. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9932. fputs(data, outfile);
  9933. fclose (outfile);
  9934. }
  9935. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9936. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9937. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9938. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9939. }
  9940. void handleStatusNotificationResponse(char *payload, int gun_index)
  9941. {
  9942. mtrace();
  9943. DEBUG_INFO("handleStatusNotificationResponse...\n");
  9944. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9945. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9946. }
  9947. void handleStopTransactionnResponse(char *payload, int gun_index)
  9948. {
  9949. mtrace();
  9950. DEBUG_INFO("handleStopTransactionnResponse...\n");
  9951. json_object *StopTransaction;
  9952. StopTransaction = json_tokener_parse(payload);
  9953. if(!is_error(StopTransaction))
  9954. {
  9955. // Optional data
  9956. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  9957. {
  9958. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  9959. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  9960. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  9961. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9962. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  9963. }
  9964. }
  9965. json_object_put(StopTransaction);
  9966. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9967. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9968. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9969. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9970. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9971. }
  9972. //==========================================
  9973. // Handle Error routine
  9974. //==========================================
  9975. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9976. {
  9977. mtrace();
  9978. #ifdef SystemLogMessage
  9979. DEBUG_INFO("errorCode: %s\n", errorCode);
  9980. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9981. DEBUG_INFO("errorDetails: %s\n", payload);
  9982. #endif
  9983. }
  9984. //===============================================
  9985. // Common routine
  9986. //===============================================
  9987. int initialConfigurationTable(void)
  9988. {
  9989. //clock_t start_t, end_t, total_t;
  9990. FILE *fp;
  9991. FILE *outfile;
  9992. char str[200]={0};
  9993. char sstr[100]={0};
  9994. int c = 0;
  9995. char *loc;
  9996. DEBUG_INFO("initialConfigurationTable...\n");
  9997. //start_t = clock();
  9998. //printf("Starting of the program, start_t = %ld\n", start_t);
  9999. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10000. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10001. {
  10002. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10003. if(outfile == NULL)
  10004. {
  10005. DEBUG_INFO("Error opening file\n");
  10006. return FALSE;
  10007. }
  10008. /*Core Profile*/
  10009. //AllowOfflineTxForUnknownId
  10010. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10013. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10014. //AuthorizationCacheEnabled
  10015. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10016. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10017. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10018. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10019. //AuthorizeRemoteTxRequests
  10020. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10023. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10024. //BlinkRepeat
  10025. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10028. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10029. //ClockAlignedDataInterval
  10030. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10033. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10034. //ConnectionTimeOut
  10035. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10037. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10038. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10039. //GetConfigurationMaxKeys
  10040. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "44" );
  10043. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10044. // HeartbeatInterval
  10045. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10048. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10049. // LightIntensity
  10050. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10053. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10054. // LocalAuthorizeOffline
  10055. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10058. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10059. // LocalPreAuthorize
  10060. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10063. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10064. // MaxEnergyOnInvalidId
  10065. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10068. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10069. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10070. // MeterValuesAlignedData
  10071. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10073. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10075. else
  10076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10077. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10078. // MeterValuesAlignedDataMaxLength
  10079. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10081. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10083. else
  10084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10086. // MeterValuesSampledData
  10087. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10089. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10091. else
  10092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10094. // MeterValuesSampledDataMaxLength
  10095. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10097. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10099. else
  10100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10102. // MeterValueSampleInterval
  10103. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10107. // MinimumStatusDuration
  10108. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10111. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10112. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10113. // NumberOfConnectors
  10114. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10116. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10117. {
  10118. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10119. }
  10120. else
  10121. {
  10122. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10123. }
  10124. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10125. // ResetRetries
  10126. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10129. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10130. // ConnectorPhaseRotation
  10131. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10134. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10135. // ConnectorPhaseRotationMaxLength
  10136. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10139. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10140. // StopTransactionOnEVSideDisconnect
  10141. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10144. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10145. // StopTransactionOnInvalidId
  10146. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10150. // StopTxnAlignedData
  10151. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10154. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10155. // StopTxnAlignedDataMaxLength
  10156. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10159. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10160. // StopTxnSampledData
  10161. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10163. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10165. else
  10166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10167. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10168. // StopTxnSampledDataMaxLength
  10169. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10171. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10172. {
  10173. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10174. }
  10175. else
  10176. {
  10177. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10178. }
  10179. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10180. // SupportedFeatureProfiles
  10181. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10184. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10185. // SupportedFeatureProfilesMaxLength
  10186. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10189. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10190. // TransactionMessageAttempts
  10191. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10192. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10193. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10194. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10195. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10196. // TransactionMessageRetryInterval
  10197. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10200. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10202. // UnlockConnectorOnEVSideDisconnect
  10203. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10207. // WebSocketPingInterval
  10208. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10211. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10212. // QueueOffLineStartTransactionMessage
  10213. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10216. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10217. //* Local Auth List Management Profile*/
  10218. #if 0
  10219. //For OCTT Test Case
  10220. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10221. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10223. #endif
  10224. #if 1
  10225. //LocalAuthListEnabled
  10226. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10229. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10230. #endif
  10231. //LocalAuthListMaxLength
  10232. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10235. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10236. //SendLocalListMaxLength
  10237. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10240. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10241. //ReserveConnectorZeroSupported
  10242. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10245. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10246. //* Smart Charging Profile */
  10247. //ChargeProfileMaxStackLevel
  10248. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10251. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10252. // ChargingScheduleAllowedChargingRateUnit
  10253. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10256. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10257. // ChargingScheduleMaxPeriods
  10258. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10261. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10262. // ConnectorSwitch3to1PhaseSupported
  10263. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10266. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10267. // MaxChargingProfilesInstalled
  10268. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10272. fclose(outfile);
  10273. }
  10274. else
  10275. {
  10276. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10277. char keystr[60]={0};
  10278. char readonlystr[10]={0};
  10279. char valuestr[100]={0};
  10280. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10281. if(fp == NULL) {
  10282. DEBUG_INFO("Error opening file");
  10283. return FALSE;
  10284. }
  10285. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10286. {
  10287. //DEBUG_INFO("Get Configuration \n");
  10288. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10289. //*************************key*********************************/
  10290. loc = strstr(str, "key");
  10291. c = 0;
  10292. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10293. while (loc[strlen("key")+3+c] != '\"')
  10294. {
  10295. sstr[c] = loc[strlen("key")+3+c];
  10296. c++;
  10297. }
  10298. sstr[c] = '\0';
  10299. strcpy(keystr,sstr);
  10300. //*************************readonly*********************************/
  10301. loc = strstr(str, "readonly");
  10302. c = 0;
  10303. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10304. while (loc[strlen("readonly")+2+c] != ',')
  10305. {
  10306. sstr[c] = loc[strlen("readonly")+2+c];
  10307. c++;
  10308. }
  10309. sstr[c] = '\0';
  10310. strcpy(readonlystr,sstr);
  10311. //*************************value*********************************/
  10312. loc = strstr(str, "value");
  10313. c = 0;
  10314. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10315. while (loc[strlen("value")+3+c] != '\"')
  10316. {
  10317. sstr[c] = loc[strlen("value")+3+c];
  10318. c++;
  10319. }
  10320. sstr[c] = '\0';
  10321. strcpy(valuestr,sstr);
  10322. // DEBUG_INFO("keystr=%s\n",keystr);
  10323. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10324. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10325. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10326. {
  10327. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10328. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10329. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10330. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10331. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10332. }
  10333. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10334. {
  10335. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10336. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10337. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10338. }
  10339. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10340. {
  10341. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10342. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10343. }
  10344. if(strcmp(keystr, "BlinkRepeat") == 0)
  10345. {
  10346. //Charger.BlinkRepeat = Integer.parseInt(value);
  10347. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10348. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10349. }
  10350. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10351. {
  10352. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10353. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10354. }
  10355. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10356. {
  10357. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10358. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10359. }
  10360. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10361. {
  10362. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10363. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10364. }
  10365. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10366. {
  10367. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10368. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10369. HeartBeatWaitTime = atoi(valuestr);
  10370. }
  10371. if(strcmp(keystr, "LightIntensity") == 0)
  10372. {
  10373. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10374. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10375. }
  10376. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10377. {
  10378. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10379. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10380. }
  10381. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10382. {
  10383. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10384. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10385. }
  10386. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10387. {
  10388. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10389. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10390. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10391. }
  10392. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10393. {
  10394. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10395. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10396. }
  10397. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10398. {
  10399. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10400. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10401. }
  10402. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10403. {
  10404. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10405. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10406. }
  10407. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10408. {
  10409. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10410. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10411. }
  10412. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10413. {
  10414. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10415. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10416. }
  10417. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10418. {
  10419. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10420. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10421. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10422. }
  10423. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10424. {
  10425. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10426. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10427. }
  10428. if(strcmp(keystr, "ResetRetries") == 0)
  10429. {
  10430. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10431. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10432. }
  10433. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10434. {
  10435. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10436. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10437. }
  10438. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10439. {
  10440. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10441. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10442. }
  10443. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10444. {
  10445. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10446. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10447. }
  10448. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10449. {
  10450. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10451. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10452. }
  10453. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10454. {
  10455. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10456. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10457. }
  10458. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10459. {
  10460. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10461. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10462. }
  10463. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10464. {
  10465. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10466. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10467. }
  10468. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10469. {
  10470. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10471. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10472. }
  10473. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10474. {
  10475. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10476. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10477. }
  10478. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10479. {
  10480. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10481. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10482. }
  10483. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10484. {
  10485. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10486. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10487. TransactionMessageAttemptsValue = atoi(valuestr);
  10488. }
  10489. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10490. {
  10491. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10492. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10493. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10494. }
  10495. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10496. {
  10497. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10498. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10499. }
  10500. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10501. {
  10502. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10503. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10504. }
  10505. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10506. {
  10507. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10508. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10509. }
  10510. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10511. {
  10512. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10513. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10514. }
  10515. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10516. {
  10517. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10518. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10519. }
  10520. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10521. {
  10522. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10523. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10524. }
  10525. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10526. {
  10527. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10528. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10529. }
  10530. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10531. {
  10532. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10533. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10534. }
  10535. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10536. {
  10537. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10538. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10539. }
  10540. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10541. {
  10542. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10543. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10544. }
  10545. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10546. {
  10547. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10548. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10549. }
  10550. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10551. {
  10552. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10553. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10554. }
  10555. }
  10556. fclose(fp);
  10557. }
  10558. return 0;
  10559. }
  10560. void StoreConfigurationTable(void)
  10561. {
  10562. FILE *outfile;
  10563. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10564. if(outfile == NULL)
  10565. {
  10566. DEBUG_INFO("Error opening file");
  10567. return ;
  10568. }
  10569. /*Core Profile*/
  10570. //AllowOfflineTxForUnknownId
  10571. /*
  10572. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10573. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10576. */
  10577. //DEBUG_INFO("data=%s\n",data);
  10578. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10579. //AuthorizationCacheEnabled
  10580. /*
  10581. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10584. */
  10585. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10586. //AuthorizeRemoteTxRequests
  10587. /*
  10588. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10591. */
  10592. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10593. //BlinkRepeat
  10594. /*
  10595. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10598. */
  10599. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10600. //ClockAlignedDataInterval
  10601. /*
  10602. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10605. */
  10606. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10607. //ConnectionTimeOut
  10608. /*
  10609. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10612. */
  10613. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10614. //GetConfigurationMaxKeys
  10615. /*
  10616. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10619. */
  10620. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10621. // HeartbeatInterval
  10622. /*
  10623. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10626. */
  10627. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10628. // LightIntensity
  10629. /*
  10630. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10633. */
  10634. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10635. // LocalAuthorizeOffline
  10636. /*
  10637. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10640. */
  10641. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10642. // LocalPreAuthorize
  10643. /*
  10644. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10647. */
  10648. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10649. // MaxEnergyOnInvalidId
  10650. /*
  10651. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10654. */
  10655. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10656. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10657. // MeterValuesAlignedData
  10658. /*
  10659. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10662. */
  10663. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10664. // MeterValuesAlignedDataMaxLength
  10665. /*
  10666. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10669. */
  10670. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10671. // MeterValuesSampledData
  10672. /*
  10673. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10676. */
  10677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10678. // MeterValuesSampledDataMaxLength
  10679. /*
  10680. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10683. */
  10684. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10685. // MeterValueSampleInterval
  10686. /*
  10687. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10690. */
  10691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10692. // MinimumStatusDuration
  10693. /*
  10694. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10697. */
  10698. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10699. // NumberOfConnectors
  10700. /*
  10701. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10703. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10704. {
  10705. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10706. }
  10707. else
  10708. {
  10709. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10710. }
  10711. */
  10712. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10713. // ResetRetries
  10714. /*
  10715. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10718. */
  10719. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10720. // ConnectorPhaseRotation
  10721. /*
  10722. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10725. */
  10726. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10727. // ConnectorPhaseRotationMaxLength
  10728. /*
  10729. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10732. */
  10733. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10734. // StopTransactionOnEVSideDisconnect
  10735. /*
  10736. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10739. */
  10740. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10741. // StopTransactionOnInvalidId
  10742. /*
  10743. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10746. */
  10747. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10748. // StopTxnAlignedData
  10749. /*
  10750. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10753. */
  10754. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10755. // StopTxnAlignedDataMaxLength
  10756. /*
  10757. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10760. */
  10761. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10762. // StopTxnSampledData
  10763. /*
  10764. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10767. */
  10768. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10769. // StopTxnSampledDataMaxLength
  10770. /*
  10771. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10774. */
  10775. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10776. // SupportedFeatureProfiles
  10777. /*
  10778. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10781. */
  10782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10783. // SupportedFeatureProfilesMaxLength
  10784. /*
  10785. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10788. */
  10789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10790. // TransactionMessageAttempts
  10791. /*
  10792. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10795. */
  10796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10797. // TransactionMessageRetryInterval
  10798. /*
  10799. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10802. */
  10803. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10804. // UnlockConnectorOnEVSideDisconnect
  10805. /*
  10806. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10809. */
  10810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10811. // WebSocketPingInterval
  10812. /*
  10813. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10816. */
  10817. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10818. // QueueOffLineStartTransactionMessage
  10819. /*
  10820. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  10821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10823. */
  10824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10825. //* Local Auth List Management Profile*/
  10826. //LocalAuthListEnabled
  10827. /*
  10828. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10831. */
  10832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10833. //LocalAuthListMaxLength
  10834. /*
  10835. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10838. */
  10839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10840. //SendLocalListMaxLength
  10841. /*
  10842. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10845. */
  10846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10847. //ReserveConnectorZeroSupported
  10848. /*
  10849. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10852. */
  10853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10854. //* Smart Charging Profile */
  10855. //ChargeProfileMaxStackLevel
  10856. /*
  10857. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10860. */
  10861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10862. // ChargingScheduleAllowedChargingRateUnit
  10863. /*
  10864. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10867. */
  10868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10869. // ChargingScheduleMaxPeriods
  10870. /*
  10871. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10874. */
  10875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10876. // ConnectorSwitch3to1PhaseSupported
  10877. /*
  10878. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10881. */
  10882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10883. // MaxChargingProfilesInstalled
  10884. /*
  10885. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10888. */
  10889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10890. fclose(outfile);
  10891. }
  10892. void getKeyValue(char *keyReq)
  10893. {
  10894. int isEmpty = FALSE;
  10895. int isKnowKey = FALSE;
  10896. DEBUG_INFO("keyReq = %s\n", keyReq);
  10897. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10898. isEmpty = TRUE;
  10899. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10900. {
  10901. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10903. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10904. {
  10905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10906. }
  10907. else
  10908. {
  10909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10910. }
  10911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10912. isKnowKey = TRUE;
  10913. }
  10914. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10915. {
  10916. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10918. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10919. {
  10920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10921. }
  10922. else
  10923. {
  10924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10925. }
  10926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10927. isKnowKey = TRUE;
  10928. }
  10929. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10930. {
  10931. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10933. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10934. {
  10935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10936. }
  10937. else
  10938. {
  10939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10940. }
  10941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10942. isKnowKey = TRUE;
  10943. }
  10944. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10945. {
  10946. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10948. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10949. {
  10950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10951. }
  10952. else
  10953. {
  10954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10955. }
  10956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10957. isKnowKey = TRUE;
  10958. }
  10959. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10960. {
  10961. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10963. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10964. {
  10965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  10966. }
  10967. else
  10968. {
  10969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  10970. }
  10971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  10972. isKnowKey = TRUE;
  10973. }
  10974. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  10975. {
  10976. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  10977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  10978. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10979. {
  10980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  10981. }
  10982. else
  10983. {
  10984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  10985. }
  10986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  10987. isKnowKey = TRUE;
  10988. }
  10989. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  10990. {
  10991. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  10992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  10993. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10994. {
  10995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  10996. }
  10997. else
  10998. {
  10999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11000. }
  11001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11002. isKnowKey = TRUE;
  11003. }
  11004. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11005. {
  11006. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11008. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11009. {
  11010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11011. }
  11012. else
  11013. {
  11014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11015. }
  11016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11017. isKnowKey = TRUE;
  11018. }
  11019. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11020. {
  11021. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11023. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11024. {
  11025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11026. }
  11027. else
  11028. {
  11029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11030. }
  11031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11032. isKnowKey = TRUE;
  11033. }
  11034. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11035. {
  11036. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11038. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11039. {
  11040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11041. }
  11042. else
  11043. {
  11044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11045. }
  11046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11047. isKnowKey = TRUE;
  11048. }
  11049. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11050. {
  11051. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11053. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11054. {
  11055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11056. }
  11057. else
  11058. {
  11059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11060. }
  11061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11062. isKnowKey = TRUE;
  11063. }
  11064. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11065. {
  11066. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11067. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11068. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11069. {
  11070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11071. }
  11072. else
  11073. {
  11074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11075. }
  11076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11077. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11078. isKnowKey = TRUE;
  11079. }
  11080. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11081. {
  11082. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11084. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11085. {
  11086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11087. }
  11088. else
  11089. {
  11090. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11091. }
  11092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11093. isKnowKey = TRUE;
  11094. }
  11095. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11096. {
  11097. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11099. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11100. {
  11101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11102. }
  11103. else
  11104. {
  11105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11106. }
  11107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11108. isKnowKey = TRUE;
  11109. }
  11110. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11111. {
  11112. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11114. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11115. {
  11116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11117. }
  11118. else
  11119. {
  11120. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11121. }
  11122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11123. isKnowKey = TRUE;
  11124. }
  11125. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11126. {
  11127. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11129. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11130. {
  11131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11132. }
  11133. else
  11134. {
  11135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11136. }
  11137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11138. isKnowKey = TRUE;
  11139. }
  11140. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11141. {
  11142. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11144. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11145. {
  11146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11147. }
  11148. else
  11149. {
  11150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11151. }
  11152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11153. isKnowKey = TRUE;
  11154. }
  11155. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11156. {
  11157. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11159. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11160. {
  11161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11162. }
  11163. else
  11164. {
  11165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11166. }
  11167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11168. isKnowKey = TRUE;
  11169. }
  11170. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11171. {
  11172. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11174. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11175. {
  11176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11177. }
  11178. else
  11179. {
  11180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11181. }
  11182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11183. isKnowKey = TRUE;
  11184. }
  11185. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11186. {
  11187. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11189. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11190. {
  11191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11192. }
  11193. else
  11194. {
  11195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11196. }
  11197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11198. isKnowKey = TRUE;
  11199. }
  11200. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11201. {
  11202. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11204. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11205. {
  11206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11207. }
  11208. else
  11209. {
  11210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11211. }
  11212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11213. isKnowKey = TRUE;
  11214. }
  11215. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11216. {
  11217. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11219. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11220. {
  11221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11222. }
  11223. else
  11224. {
  11225. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11226. }
  11227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11228. isKnowKey = TRUE;
  11229. }
  11230. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11231. {
  11232. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11234. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11235. {
  11236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11237. }
  11238. else
  11239. {
  11240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11241. }
  11242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11243. isKnowKey = TRUE;
  11244. }
  11245. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11246. {
  11247. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11249. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11250. {
  11251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11252. }
  11253. else
  11254. {
  11255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11256. }
  11257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11258. isKnowKey = TRUE;
  11259. }
  11260. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11261. {
  11262. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11264. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11265. {
  11266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11267. }
  11268. else
  11269. {
  11270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11271. }
  11272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11273. isKnowKey = TRUE;
  11274. }
  11275. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11276. {
  11277. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11279. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11280. {
  11281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11282. }
  11283. else
  11284. {
  11285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11286. }
  11287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11288. isKnowKey = TRUE;
  11289. }
  11290. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11291. {
  11292. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11294. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11295. {
  11296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11297. }
  11298. else
  11299. {
  11300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11301. }
  11302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11303. isKnowKey = TRUE;
  11304. }
  11305. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11306. {
  11307. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11309. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11310. {
  11311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11312. }
  11313. else
  11314. {
  11315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11316. }
  11317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11318. isKnowKey = TRUE;
  11319. }
  11320. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11321. {
  11322. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11324. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11325. {
  11326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11327. }
  11328. else
  11329. {
  11330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11331. }
  11332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11333. isKnowKey = TRUE;
  11334. }
  11335. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11336. {
  11337. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11339. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11340. {
  11341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11342. }
  11343. else
  11344. {
  11345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11346. }
  11347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11348. isKnowKey = TRUE;
  11349. }
  11350. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11351. {
  11352. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11354. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11355. {
  11356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11357. }
  11358. else
  11359. {
  11360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11361. }
  11362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11363. isKnowKey = TRUE;
  11364. }
  11365. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11366. {
  11367. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11369. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11370. {
  11371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11372. }
  11373. else
  11374. {
  11375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11376. }
  11377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11378. isKnowKey = TRUE;
  11379. }
  11380. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11381. {
  11382. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11384. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11385. {
  11386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11387. }
  11388. else
  11389. {
  11390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11391. }
  11392. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11393. isKnowKey = TRUE;
  11394. }
  11395. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11396. {
  11397. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11399. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11400. {
  11401. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11402. }
  11403. else
  11404. {
  11405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11406. }
  11407. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11408. isKnowKey = TRUE;
  11409. }
  11410. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11411. {
  11412. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11414. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11415. {
  11416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11417. }
  11418. else
  11419. {
  11420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11421. }
  11422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11423. isKnowKey = TRUE;
  11424. }
  11425. #if 1
  11426. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11427. {
  11428. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11430. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11431. {
  11432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11433. }
  11434. else
  11435. {
  11436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11437. }
  11438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11439. isKnowKey = TRUE;
  11440. }
  11441. #endif
  11442. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11443. {
  11444. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11446. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11447. {
  11448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11449. }
  11450. else
  11451. {
  11452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11453. }
  11454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11455. isKnowKey = TRUE;
  11456. }
  11457. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11458. {
  11459. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11461. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11462. {
  11463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11464. }
  11465. else
  11466. {
  11467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11468. }
  11469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11470. isKnowKey = TRUE;
  11471. }
  11472. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11473. {
  11474. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11476. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11477. {
  11478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11479. }
  11480. else
  11481. {
  11482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11483. }
  11484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11485. isKnowKey = TRUE;
  11486. }
  11487. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11488. {
  11489. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11491. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11492. {
  11493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11494. }
  11495. else
  11496. {
  11497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11498. }
  11499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11500. isKnowKey = TRUE;
  11501. }
  11502. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11503. {
  11504. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11506. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11507. {
  11508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11509. }
  11510. else
  11511. {
  11512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11513. }
  11514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11515. isKnowKey = TRUE;
  11516. }
  11517. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11518. {
  11519. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11521. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11522. {
  11523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11524. }
  11525. else
  11526. {
  11527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11528. }
  11529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11530. isKnowKey = TRUE;
  11531. }
  11532. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11533. {
  11534. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11536. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11537. {
  11538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11539. }
  11540. else
  11541. {
  11542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11543. }
  11544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11545. isKnowKey = TRUE;
  11546. }
  11547. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11548. {
  11549. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11551. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11552. {
  11553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11554. }
  11555. else
  11556. {
  11557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11558. }
  11559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11560. isKnowKey = TRUE;
  11561. }
  11562. //=========================================================
  11563. if(!isEmpty && !isKnowKey)
  11564. {
  11565. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11566. strcpy(unknownkey[UnknownKeynum], keyReq);
  11567. UnknownKeynum = UnknownKeynum + 1;
  11568. }
  11569. }
  11570. void processUnkownKey(void)
  11571. {
  11572. DEBUG_INFO("processUnkownKey...\n");
  11573. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11574. for(int index=0; index < UnknownKeynum; index++)
  11575. {
  11576. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11577. {
  11578. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11579. }
  11580. }
  11581. }
  11582. int setKeyValue(char *key, char *value)
  11583. {
  11584. int isSuccess = NotSupported;
  11585. int check_ascii=0;
  11586. char str[10]={0};
  11587. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11588. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11589. {
  11590. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11591. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11592. {
  11593. strcpy(str, (const char*)value);
  11594. for(int i = 0; str[i]; i++){
  11595. str[i] = tolower(str[i]);
  11596. }
  11597. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11598. isSuccess = ConfigurationStatus_Accepted;
  11599. }
  11600. else
  11601. {
  11602. isSuccess = ConfigurationStatus_Rejected;
  11603. }
  11604. }
  11605. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11606. {
  11607. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11608. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11609. {
  11610. strcpy(str, (const char*)value);
  11611. for(int i = 0; str[i]; i++){
  11612. str[i] = tolower(str[i]);
  11613. }
  11614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11615. isSuccess = ConfigurationStatus_Accepted;
  11616. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11617. }
  11618. else
  11619. {
  11620. isSuccess = ConfigurationStatus_Rejected;
  11621. }
  11622. }
  11623. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11624. {
  11625. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11626. {
  11627. strcpy(str, (const char*)value);
  11628. for(int i = 0; str[i]; i++)
  11629. {
  11630. str[i] = tolower(str[i]);
  11631. }
  11632. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11633. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11634. isSuccess = ConfigurationStatus_Accepted;
  11635. }
  11636. else
  11637. {
  11638. isSuccess = ConfigurationStatus_Rejected;
  11639. }
  11640. }
  11641. if(strcmp(key, "BlinkRepeat") == 0)
  11642. {
  11643. //Charger.BlinkRepeat = Integer.parseInt(value);
  11644. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11645. {
  11646. check_ascii = value[0];
  11647. if( (check_ascii < 48) || (check_ascii > 57) )
  11648. {
  11649. isSuccess = ConfigurationStatus_Rejected;
  11650. }
  11651. else
  11652. {
  11653. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11654. isSuccess = ConfigurationStatus_Accepted;
  11655. }
  11656. }
  11657. else
  11658. {
  11659. isSuccess = ConfigurationStatus_Rejected;
  11660. }
  11661. }
  11662. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11663. {
  11664. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11665. {
  11666. check_ascii = value[0];
  11667. if( (check_ascii < 48) || (check_ascii > 57) )
  11668. {
  11669. isSuccess = ConfigurationStatus_Rejected;
  11670. }
  11671. else
  11672. {
  11673. if((atoi(value) == 0) || (atoi(value) >= 10))
  11674. {
  11675. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11676. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11677. isSuccess = ConfigurationStatus_Accepted;
  11678. }
  11679. else
  11680. isSuccess = ConfigurationStatus_Rejected;
  11681. }
  11682. }
  11683. else
  11684. {
  11685. isSuccess = ConfigurationStatus_Rejected;
  11686. }
  11687. }
  11688. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11689. {
  11690. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11691. {
  11692. check_ascii = value[0];
  11693. if( (check_ascii < 48) || (check_ascii > 57) )
  11694. {
  11695. isSuccess = ConfigurationStatus_Rejected;
  11696. }
  11697. else
  11698. {
  11699. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11700. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11701. isSuccess = ConfigurationStatus_Accepted;
  11702. }
  11703. }
  11704. else
  11705. {
  11706. isSuccess = ConfigurationStatus_Rejected;
  11707. }
  11708. }
  11709. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11710. {
  11711. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11712. {
  11713. check_ascii = value[0];
  11714. if( (check_ascii < 48) || (check_ascii > 57) )
  11715. {
  11716. isSuccess = ConfigurationStatus_Rejected;
  11717. }
  11718. else
  11719. {
  11720. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11721. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11722. isSuccess = ConfigurationStatus_Accepted;
  11723. }
  11724. }
  11725. else
  11726. {
  11727. isSuccess = ConfigurationStatus_Rejected;
  11728. }
  11729. }
  11730. if(strcmp(key, "HeartbeatInterval") == 0)
  11731. {
  11732. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11733. {
  11734. check_ascii = value[0];
  11735. if( (check_ascii < 48) || (check_ascii > 57) )
  11736. {
  11737. isSuccess = ConfigurationStatus_Rejected;
  11738. }
  11739. else
  11740. {
  11741. if((atoi(value) == 0) || (atoi(value) >= 10))
  11742. {
  11743. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11744. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11745. HeartBeatWaitTime = atoi(value);
  11746. isSuccess = ConfigurationStatus_Accepted;
  11747. }
  11748. else
  11749. {
  11750. isSuccess = ConfigurationStatus_Rejected;
  11751. }
  11752. }
  11753. }
  11754. else
  11755. {
  11756. isSuccess = ConfigurationStatus_Rejected;
  11757. }
  11758. }
  11759. if(strcmp(key, "LightIntensity") == 0)
  11760. {
  11761. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11762. {
  11763. check_ascii = value[0];
  11764. if( (check_ascii < 48) || (check_ascii > 57) )
  11765. {
  11766. isSuccess = ConfigurationStatus_Rejected;
  11767. }
  11768. else
  11769. {
  11770. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11771. isSuccess = ConfigurationStatus_Accepted;
  11772. }
  11773. }
  11774. else
  11775. {
  11776. isSuccess = ConfigurationStatus_Rejected;
  11777. }
  11778. }
  11779. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11780. {
  11781. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11782. {
  11783. strcpy(str, (const char*)value);
  11784. for(int i = 0; str[i]; i++)
  11785. {
  11786. str[i] = tolower(str[i]);
  11787. }
  11788. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11789. isSuccess = ConfigurationStatus_Accepted;
  11790. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11791. }
  11792. else
  11793. {
  11794. isSuccess = ConfigurationStatus_Rejected;
  11795. }
  11796. }
  11797. if(strcmp(key, "LocalPreAuthorize") == 0)
  11798. {
  11799. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11800. {
  11801. strcpy(str, (const char*)value);
  11802. for(int i = 0; str[i]; i++)
  11803. {
  11804. str[i] = tolower(str[i]);
  11805. }
  11806. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11807. isSuccess = ConfigurationStatus_Accepted;
  11808. }
  11809. else
  11810. {
  11811. isSuccess = ConfigurationStatus_Rejected;
  11812. }
  11813. }
  11814. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11815. {
  11816. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11817. {
  11818. check_ascii = value[0];
  11819. if( (check_ascii < 48) || (check_ascii > 57) )
  11820. {
  11821. isSuccess = ConfigurationStatus_Rejected;
  11822. }
  11823. else
  11824. {
  11825. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11826. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11827. isSuccess = ConfigurationStatus_Accepted;
  11828. }
  11829. }
  11830. else
  11831. {
  11832. isSuccess = ConfigurationStatus_Rejected;
  11833. }
  11834. }
  11835. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11836. {
  11837. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11838. {
  11839. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11840. isSuccess = ConfigurationStatus_Accepted;
  11841. }
  11842. else
  11843. {
  11844. isSuccess = ConfigurationStatus_Rejected;
  11845. }
  11846. }
  11847. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11848. {
  11849. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11850. {
  11851. check_ascii = value[0];
  11852. if( (check_ascii < 48) || (check_ascii > 57) )
  11853. {
  11854. isSuccess = ConfigurationStatus_Rejected;
  11855. }
  11856. else
  11857. {
  11858. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11859. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11860. isSuccess = ConfigurationStatus_Accepted;
  11861. }
  11862. }
  11863. else
  11864. {
  11865. isSuccess = ConfigurationStatus_Rejected;
  11866. }
  11867. }
  11868. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11869. {
  11870. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11871. {
  11872. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11873. isSuccess = ConfigurationStatus_Accepted;
  11874. }
  11875. else
  11876. {
  11877. isSuccess = ConfigurationStatus_Rejected;
  11878. }
  11879. }
  11880. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11881. {
  11882. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11883. {
  11884. check_ascii = value[0];
  11885. if( (check_ascii < 48) || (check_ascii > 57) )
  11886. {
  11887. isSuccess = ConfigurationStatus_Rejected;
  11888. }
  11889. else
  11890. {
  11891. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11892. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11893. isSuccess = ConfigurationStatus_Accepted;
  11894. }
  11895. }
  11896. else
  11897. {
  11898. isSuccess = ConfigurationStatus_Rejected;
  11899. }
  11900. }
  11901. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11902. {
  11903. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11904. {
  11905. check_ascii = value[0];
  11906. if( (check_ascii < 48) || (check_ascii > 57) )
  11907. {
  11908. isSuccess = ConfigurationStatus_Rejected;
  11909. }
  11910. else
  11911. {
  11912. if((atoi(value) == 0) || (atoi(value) >= 10))
  11913. {
  11914. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11915. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11916. isSuccess = ConfigurationStatus_Accepted;
  11917. }
  11918. else
  11919. {
  11920. isSuccess = ConfigurationStatus_Rejected;
  11921. }
  11922. }
  11923. }
  11924. else
  11925. {
  11926. isSuccess = ConfigurationStatus_Rejected;
  11927. }
  11928. }
  11929. if(strcmp(key, "MinimumStatusDuration") == 0)
  11930. {
  11931. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11932. {
  11933. check_ascii = value[0];
  11934. if( (check_ascii < 48) || (check_ascii > 57) )
  11935. {
  11936. isSuccess = ConfigurationStatus_Rejected;
  11937. }
  11938. else
  11939. {
  11940. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  11941. {
  11942. isSuccess = ConfigurationStatus_Rejected;
  11943. }
  11944. else
  11945. {
  11946. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  11947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  11948. server_cycle_Status = atoi(value); //StatusNotification Cycle
  11949. isSuccess = ConfigurationStatus_Accepted;
  11950. }
  11951. }
  11952. }
  11953. else
  11954. {
  11955. isSuccess = ConfigurationStatus_Rejected;
  11956. }
  11957. }
  11958. if(strcmp(key, "NumberOfConnectors") == 0)
  11959. {
  11960. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].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. //Charger.ResetRetries = Integer.parseInt(value);
  11970. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  11971. isSuccess = ConfigurationStatus_Accepted;
  11972. }
  11973. }
  11974. else
  11975. {
  11976. isSuccess = ConfigurationStatus_Rejected;
  11977. }
  11978. }
  11979. if(strcmp(key, "ResetRetries") == 0)
  11980. {
  11981. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11982. {
  11983. check_ascii = value[0];
  11984. if( (check_ascii < 48) || (check_ascii > 57) )
  11985. {
  11986. isSuccess = ConfigurationStatus_Rejected;
  11987. }
  11988. else
  11989. {
  11990. //Charger.ResetRetries = Integer.parseInt(value);
  11991. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  11992. isSuccess = ConfigurationStatus_Accepted;
  11993. }
  11994. }
  11995. else
  11996. {
  11997. isSuccess = ConfigurationStatus_Rejected;
  11998. }
  11999. }
  12000. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12001. {
  12002. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12003. {
  12004. strcpy(str, (const char*)value);
  12005. for(int i = 0; str[i]; i++)
  12006. {
  12007. str[i] = tolower(str[i]);
  12008. }
  12009. if(strcmp(str, "notapplicable")== 0)
  12010. {
  12011. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12012. isSuccess = ConfigurationStatus_Accepted;
  12013. }
  12014. else if(strcmp(str, "unknown")== 0)
  12015. {
  12016. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12017. isSuccess = ConfigurationStatus_Accepted;
  12018. }
  12019. else if(strcmp(str, "rst")== 0)
  12020. {
  12021. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12022. isSuccess = ConfigurationStatus_Accepted;
  12023. }
  12024. else if(strcmp(str, "rts")== 0)
  12025. {
  12026. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12027. isSuccess = ConfigurationStatus_Accepted;
  12028. }
  12029. else if(strcmp(str, "srt")== 0)
  12030. {
  12031. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12032. isSuccess = ConfigurationStatus_Accepted;
  12033. }
  12034. else if(strcmp(str, "str")== 0)
  12035. {
  12036. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12037. isSuccess = ConfigurationStatus_Accepted;
  12038. }
  12039. else if(strcmp(str, "trs")== 0)
  12040. {
  12041. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12042. isSuccess = ConfigurationStatus_Accepted;
  12043. }
  12044. else if(strcmp(str, "tsr")== 0)
  12045. {
  12046. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12047. isSuccess = ConfigurationStatus_Accepted;
  12048. }
  12049. else
  12050. {
  12051. isSuccess = ConfigurationStatus_Rejected;
  12052. }
  12053. }
  12054. else
  12055. {
  12056. isSuccess = ConfigurationStatus_Rejected;
  12057. }
  12058. }
  12059. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12060. {
  12061. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12062. {
  12063. check_ascii = value[0];
  12064. if( (check_ascii < 48) || (check_ascii > 57) )
  12065. {
  12066. isSuccess = ConfigurationStatus_Rejected;
  12067. }
  12068. else
  12069. {
  12070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12071. isSuccess = ConfigurationStatus_Accepted;
  12072. }
  12073. }
  12074. else
  12075. {
  12076. isSuccess = ConfigurationStatus_Rejected;
  12077. }
  12078. }
  12079. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12080. {
  12081. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12082. {
  12083. strcpy(str, (const char*)value);
  12084. for(int i = 0; str[i]; i++)
  12085. {
  12086. str[i] = tolower(str[i]);
  12087. }
  12088. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12089. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12090. isSuccess = ConfigurationStatus_Accepted;
  12091. }
  12092. else
  12093. {
  12094. isSuccess = ConfigurationStatus_Rejected;
  12095. }
  12096. }
  12097. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12098. {
  12099. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12100. {
  12101. strcpy(str, (const char*)value);
  12102. for(int i = 0; str[i]; i++)
  12103. {
  12104. str[i] = tolower(str[i]);
  12105. }
  12106. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12107. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12108. isSuccess = ConfigurationStatus_Accepted;
  12109. }
  12110. else
  12111. {
  12112. isSuccess = ConfigurationStatus_Rejected;
  12113. }
  12114. }
  12115. if(strcmp(key, "StopTxnAlignedData") == 0)
  12116. {
  12117. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12118. {
  12119. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12120. isSuccess = ConfigurationStatus_Accepted;
  12121. }
  12122. else
  12123. {
  12124. isSuccess = ConfigurationStatus_Rejected;
  12125. }
  12126. }
  12127. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12128. {
  12129. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12130. {
  12131. check_ascii = value[0];
  12132. if( (check_ascii < 48) || (check_ascii > 57) )
  12133. {
  12134. isSuccess = ConfigurationStatus_Rejected;
  12135. }
  12136. else
  12137. {
  12138. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12139. isSuccess = ConfigurationStatus_Accepted;
  12140. }
  12141. }
  12142. else
  12143. {
  12144. isSuccess = ConfigurationStatus_Rejected;
  12145. }
  12146. }
  12147. if(strcmp(key, "StopTxnSampledData") == 0)
  12148. {
  12149. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12150. {
  12151. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12152. isSuccess = ConfigurationStatus_Accepted;
  12153. }
  12154. else
  12155. {
  12156. isSuccess = ConfigurationStatus_Rejected;
  12157. }
  12158. }
  12159. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12160. {
  12161. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12162. {
  12163. check_ascii = value[0];
  12164. if( (check_ascii < 48) || (check_ascii > 57) )
  12165. {
  12166. isSuccess = ConfigurationStatus_Rejected;
  12167. }
  12168. else
  12169. {
  12170. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12171. isSuccess = ConfigurationStatus_Accepted;
  12172. }
  12173. }
  12174. else
  12175. {
  12176. isSuccess = ConfigurationStatus_Rejected;
  12177. }
  12178. }
  12179. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12180. {
  12181. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12182. {
  12183. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12184. isSuccess = ConfigurationStatus_Accepted;
  12185. }
  12186. else
  12187. {
  12188. isSuccess = ConfigurationStatus_Rejected;
  12189. }
  12190. }
  12191. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12192. {
  12193. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12194. {
  12195. check_ascii = value[0];
  12196. if( (check_ascii < 48) || (check_ascii > 57) )
  12197. {
  12198. isSuccess = ConfigurationStatus_Rejected;
  12199. }
  12200. else
  12201. {
  12202. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12203. isSuccess = ConfigurationStatus_Accepted;
  12204. }
  12205. }
  12206. else
  12207. {
  12208. isSuccess = ConfigurationStatus_Rejected;
  12209. }
  12210. }
  12211. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12212. {
  12213. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12214. {
  12215. check_ascii = value[0];
  12216. if( (check_ascii < 48) || (check_ascii > 57) )
  12217. {
  12218. isSuccess = ConfigurationStatus_Rejected;
  12219. }
  12220. else
  12221. {
  12222. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12223. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12224. TransactionMessageAttemptsValue = atoi(value);
  12225. isSuccess = ConfigurationStatus_Accepted;
  12226. }
  12227. }
  12228. else
  12229. {
  12230. isSuccess = ConfigurationStatus_Rejected;
  12231. }
  12232. }
  12233. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12234. {
  12235. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12236. {
  12237. check_ascii = value[0];
  12238. if( (check_ascii < 48) || (check_ascii > 57) )
  12239. {
  12240. isSuccess = ConfigurationStatus_Rejected;
  12241. }
  12242. else
  12243. {
  12244. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12245. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12246. TransactionMessageRetryIntervalValue = atoi(value);
  12247. isSuccess = ConfigurationStatus_Accepted;
  12248. }
  12249. }
  12250. else
  12251. {
  12252. isSuccess = ConfigurationStatus_Rejected;
  12253. }
  12254. }
  12255. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12256. {
  12257. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12258. {
  12259. strcpy(str, (const char*)value);
  12260. for(int i = 0; str[i]; i++)
  12261. {
  12262. str[i] = tolower(str[i]);
  12263. }
  12264. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12265. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12266. isSuccess = ConfigurationStatus_Accepted;
  12267. }
  12268. else
  12269. {
  12270. isSuccess = ConfigurationStatus_Rejected;
  12271. }
  12272. }
  12273. if(strcmp(key, "WebSocketPingInterval") == 0)
  12274. {
  12275. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12276. {
  12277. check_ascii = value[0];
  12278. if( (check_ascii < 48) || (check_ascii > 57) )
  12279. {
  12280. isSuccess = ConfigurationStatus_Rejected;
  12281. }
  12282. else
  12283. {
  12284. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12285. isSuccess = ConfigurationStatus_Accepted;
  12286. }
  12287. }
  12288. else
  12289. {
  12290. isSuccess = ConfigurationStatus_Rejected;
  12291. }
  12292. }
  12293. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12294. {
  12295. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12296. {
  12297. strcpy(str, (const char*)value);
  12298. for(int i = 0; str[i]; i++)
  12299. {
  12300. str[i] = tolower(str[i]);
  12301. }
  12302. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12303. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12304. isSuccess = ConfigurationStatus_Accepted;
  12305. }
  12306. else
  12307. {
  12308. isSuccess = ConfigurationStatus_Rejected;
  12309. }
  12310. }
  12311. #if 0
  12312. //For OCPP Test Case
  12313. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12314. {
  12315. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12316. {
  12317. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12318. isSuccess = ConfigurationStatus_Accepted;
  12319. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12320. }
  12321. else
  12322. {
  12323. isSuccess = ConfigurationStatus_Rejected;
  12324. }
  12325. }
  12326. #endif
  12327. #if 1
  12328. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12329. {
  12330. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12331. {
  12332. strcpy(str, (const char*)value);
  12333. for(int i = 0; str[i]; i++)
  12334. {
  12335. str[i] = tolower(str[i]);
  12336. }
  12337. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12338. isSuccess = ConfigurationStatus_Accepted;
  12339. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12340. }
  12341. else
  12342. {
  12343. isSuccess = ConfigurationStatus_Rejected;
  12344. }
  12345. }
  12346. #endif
  12347. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12348. {
  12349. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12350. {
  12351. check_ascii = value[0];
  12352. if( (check_ascii < 48) || (check_ascii > 57) )
  12353. {
  12354. isSuccess = ConfigurationStatus_Rejected;
  12355. }
  12356. else
  12357. {
  12358. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12359. isSuccess = ConfigurationStatus_Accepted;
  12360. }
  12361. }
  12362. else
  12363. {
  12364. isSuccess = ConfigurationStatus_Rejected;
  12365. }
  12366. }
  12367. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12368. {
  12369. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12370. {
  12371. check_ascii = value[0];
  12372. if( (check_ascii < 48) || (check_ascii > 57) )
  12373. {
  12374. isSuccess = ConfigurationStatus_Rejected;
  12375. }
  12376. else
  12377. {
  12378. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12379. isSuccess = ConfigurationStatus_Accepted;
  12380. }
  12381. }
  12382. else
  12383. {
  12384. isSuccess = ConfigurationStatus_Rejected;
  12385. }
  12386. }
  12387. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12388. {
  12389. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12390. {
  12391. strcpy(str, (const char*)value);
  12392. for(int i = 0; str[i]; i++)
  12393. {
  12394. str[i] = tolower(str[i]);
  12395. }
  12396. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12397. isSuccess = ConfigurationStatus_Accepted;
  12398. }
  12399. else
  12400. {
  12401. isSuccess = ConfigurationStatus_Rejected;
  12402. }
  12403. }
  12404. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12405. {
  12406. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].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.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12416. isSuccess = ConfigurationStatus_Accepted;
  12417. }
  12418. }
  12419. else
  12420. {
  12421. isSuccess = ConfigurationStatus_Rejected;
  12422. }
  12423. }
  12424. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12425. {
  12426. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12427. {
  12428. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12429. isSuccess = ConfigurationStatus_Accepted;
  12430. }
  12431. else
  12432. {
  12433. isSuccess = ConfigurationStatus_Rejected;
  12434. }
  12435. }
  12436. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12437. {
  12438. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12439. {
  12440. check_ascii = value[0];
  12441. if( (check_ascii < 48) || (check_ascii > 57) )
  12442. {
  12443. isSuccess = ConfigurationStatus_Rejected;
  12444. }
  12445. else
  12446. {
  12447. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12448. isSuccess = ConfigurationStatus_Accepted;
  12449. }
  12450. }
  12451. else
  12452. {
  12453. isSuccess = ConfigurationStatus_Rejected;
  12454. }
  12455. }
  12456. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12457. {
  12458. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12459. {
  12460. strcpy(str, (const char*)value);
  12461. for(int i = 0; str[i]; i++)
  12462. {
  12463. str[i] = tolower(str[i]);
  12464. }
  12465. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12466. isSuccess = ConfigurationStatus_Accepted;
  12467. }
  12468. else
  12469. {
  12470. isSuccess = ConfigurationStatus_Rejected;
  12471. }
  12472. }
  12473. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12474. {
  12475. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12476. {
  12477. check_ascii = value[0];
  12478. if( (check_ascii < 48) || (check_ascii > 57) )
  12479. {
  12480. isSuccess = ConfigurationStatus_Rejected;
  12481. }
  12482. else
  12483. {
  12484. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12485. isSuccess = ConfigurationStatus_Accepted;
  12486. }
  12487. }
  12488. else
  12489. {
  12490. isSuccess = ConfigurationStatus_Rejected;
  12491. }
  12492. }
  12493. return isSuccess;
  12494. }
  12495. int TransactionMessageAttemptsGet(void)
  12496. {
  12497. return TransactionMessageAttemptsValue;
  12498. }
  12499. int FirstHeartBeatResponse(void)
  12500. {
  12501. return FirstHeartBeat;
  12502. }
  12503. int TransactionMessageRetryIntervalGet(void)
  12504. {
  12505. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12506. }
  12507. int ReadHttpStatus(int sock)
  12508. {
  12509. //char c;
  12510. char buff[1024]="",*ptr=buff+1;
  12511. int bytes_received, status;
  12512. DEBUG_INFO("Begin Response ..\n");
  12513. while((bytes_received = recv(sock, ptr, 1, 0))){
  12514. if(bytes_received==-1){
  12515. perror("ReadHttpStatus");
  12516. exit(1);
  12517. }
  12518. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12519. ptr++;
  12520. }
  12521. *ptr=0;
  12522. ptr=buff+1;
  12523. sscanf(ptr,"%*s %d ", &status);
  12524. DEBUG_INFO("%s\n",ptr);
  12525. DEBUG_INFO("status=%d\n",status);
  12526. DEBUG_INFO("End Response ..\n");
  12527. return (bytes_received>0)?status:0;
  12528. }
  12529. //the only filed that it parsed is 'Content-Length'
  12530. int ParseHeader(int sock)
  12531. {
  12532. //char c;
  12533. char buff[1024]="",*ptr=buff+4;
  12534. int bytes_received;
  12535. DEBUG_INFO("Begin HEADER ..\n");
  12536. while((bytes_received = recv(sock, ptr, 1, 0))){
  12537. if(bytes_received==-1){
  12538. perror("Parse Header");
  12539. exit(1);
  12540. }
  12541. if(
  12542. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12543. (ptr[-1]=='\r') && (*ptr=='\n' )
  12544. ) break;
  12545. ptr++;
  12546. }
  12547. *ptr=0;
  12548. ptr=buff+4;
  12549. //printf("%s",ptr);
  12550. if(bytes_received){
  12551. ptr=strstr(ptr,"Content-Length:");
  12552. if(ptr){
  12553. sscanf(ptr,"%*s %d",&bytes_received);
  12554. }else
  12555. bytes_received=-1; //unknown size
  12556. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12557. }
  12558. DEBUG_INFO("End HEADER ..\n");
  12559. return bytes_received ;
  12560. }
  12561. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12562. {
  12563. char rmFileCmd[100]={0};
  12564. char FilePath[100]={0};
  12565. char ftpbuf[200];
  12566. int systemresult;
  12567. //DEBUG_INFO("filename=%s\n",filename);
  12568. //DEBUG_INFO("url=%s\n",url);
  12569. sprintf(FilePath,"/mnt/%s",filename);
  12570. if((access(FilePath,F_OK))!=-1)
  12571. {
  12572. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12573. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12574. system(rmFileCmd);
  12575. }
  12576. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12577. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12578. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12579. systemresult = system(ftpbuf);
  12580. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12581. if(systemresult != 0)
  12582. {
  12583. DEBUG_INFO("http DownLoad error!\n");
  12584. return FALSE;
  12585. }
  12586. return TRUE;
  12587. }
  12588. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12589. {
  12590. char rmFileCmd[100]={0};
  12591. char FilePath[100]={0};
  12592. char ftpbuf[200];
  12593. int systemresult;
  12594. //char temp[100];
  12595. sprintf(FilePath,"/mnt/%s",filename);
  12596. if((access(FilePath,F_OK))!=-1)
  12597. {
  12598. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12599. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12600. system(rmFileCmd);
  12601. }
  12602. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12603. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12604. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12605. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12606. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12607. systemresult = system(ftpbuf);
  12608. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12609. if(systemresult != 0)
  12610. {
  12611. printf("wget error!\n");
  12612. return FALSE;
  12613. }
  12614. return TRUE;
  12615. }
  12616. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12617. {
  12618. char rmFileCmd[100]={0};
  12619. char FilePath[100]={0};
  12620. char ftpbuf[200];
  12621. int systemresult;
  12622. //DEBUG_INFO("filename=%s\n",filename);
  12623. //DEBUG_INFO("url=%s\n",url);
  12624. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12625. if((access(FilePath,F_OK))!=-1)
  12626. {
  12627. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12628. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12629. system(rmFileCmd);
  12630. }
  12631. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12632. if(fp == NULL)
  12633. {
  12634. DEBUG_INFO("log is NULL\n");
  12635. return FALSE;
  12636. }
  12637. else
  12638. {
  12639. fprintf(fp, "%s\n", url);
  12640. fprintf(fp, "%s\n", filename);
  12641. fclose(fp);
  12642. }
  12643. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12644. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12645. systemresult = system(ftpbuf);
  12646. DEBUG_INFO("systemresult = %d\n",systemresult);
  12647. if(systemresult != 0)
  12648. {
  12649. DEBUG_INFO("http upload error!\n");
  12650. return FALSE;
  12651. }
  12652. return TRUE;
  12653. }
  12654. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12655. {
  12656. struct hostent* server;
  12657. char *IPbuffer;
  12658. char ftpbuf[200];
  12659. int systemresult;
  12660. // To retrieve host information
  12661. server = gethostbyname(location);
  12662. // To convert an Internet network
  12663. // address into ASCII string
  12664. IPbuffer = inet_ntoa(*((struct in_addr*)
  12665. server->h_addr_list[0]));
  12666. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12667. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12668. /* format : ftpput -u username -p passwd IP target source*/
  12669. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12670. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12671. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12672. systemresult = system(ftpbuf);
  12673. DEBUG_INFO("systemresult=%d\n",systemresult);
  12674. if(systemresult != 0)
  12675. {
  12676. DEBUG_INFO("ftpput error!\n");
  12677. return FALSE;
  12678. }
  12679. return TRUE;
  12680. }
  12681. /**
  12682. * Place the contents of the specified file into a memory buffer
  12683. *
  12684. * @param[in] filename The path and name of the file to read
  12685. * @param[out] filebuffer A pointer to the contents in memory
  12686. * @return status 0 success, 1 on failure
  12687. */
  12688. int get_file_contents(const char* filename, char** outbuffer) {
  12689. FILE* file = NULL;
  12690. long filesize;
  12691. const int blocksize = 1;
  12692. size_t readsize;
  12693. char* filebuffer;
  12694. // Open the file
  12695. file = fopen(filename, "r");
  12696. if (NULL == file)
  12697. {
  12698. printf("'%s' not opened\n", filename);
  12699. exit(EXIT_FAILURE);
  12700. }
  12701. // Determine the file size
  12702. fseek(file, 0, SEEK_END);
  12703. filesize = ftell(file);
  12704. rewind (file);
  12705. // Allocate memory for the file contents
  12706. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12707. *outbuffer = filebuffer;
  12708. if (filebuffer == NULL)
  12709. {
  12710. fputs ("malloc out-of-memory", stderr);
  12711. exit(EXIT_FAILURE);
  12712. }
  12713. // Read in the file
  12714. readsize = fread(filebuffer, blocksize, filesize, file);
  12715. if (readsize != filesize)
  12716. {
  12717. fputs ("didn't read file completely",stderr);
  12718. exit(EXIT_FAILURE);
  12719. }
  12720. // Clean exit
  12721. fclose(file);
  12722. return EXIT_SUCCESS;
  12723. }
  12724. static int selectSqlCount = 0;
  12725. static int callback(void *data, int argc, char **argv, char **azColName){
  12726. int i;
  12727. //printf("%s: ", (const char*)data);
  12728. selectSqlCount = argc;
  12729. for(i = 0; i<argc; i++){
  12730. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12731. }
  12732. //printf("\n");
  12733. return 0;
  12734. }
  12735. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12736. //int i;
  12737. //printf("%s:\n", (const char*)data);
  12738. localversion = argv[5] ? atoi(argv[5]) : 0;
  12739. //printf("localversion=%d\n", localversion);
  12740. return 0;
  12741. }
  12742. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12743. //int i;
  12744. //printf("%s:\n", (const char*)data);
  12745. //idTag
  12746. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12747. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12748. //parentIdTag
  12749. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12750. //expir_date
  12751. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12752. //status
  12753. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12754. //version
  12755. idTagQuery.listVersionInt = atoi(argv[5]);
  12756. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12757. return 0;
  12758. }
  12759. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12760. {
  12761. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12762. // printf("localversion=%d\n", localversion);
  12763. return 0;
  12764. }
  12765. //=========================================
  12766. // Sqlite3 related function
  12767. //=========================================
  12768. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12769. {
  12770. for (int i = 0; i < n_columns; i++)
  12771. {
  12772. DEBUG_INFO("%s\t", col_values[i]);
  12773. }
  12774. DEBUG_INFO("\n");
  12775. return 0;
  12776. }
  12777. void OCPP_getListVerion()
  12778. {
  12779. int rc = 0;
  12780. // const char* data = "Callback function called";
  12781. char sql[100];
  12782. char zErrMsg[100];
  12783. memset(sql, 0, 100);
  12784. memset(zErrMsg, 0, 100);
  12785. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12786. /* Execute SQL statement */
  12787. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12788. if( rc != SQLITE_OK )
  12789. {
  12790. DEBUG_INFO("SQL error: %s", zErrMsg);
  12791. }
  12792. }
  12793. void OCPP_getIdTag(char idTag[])
  12794. {
  12795. int rc = 0;
  12796. // const char* data = "Callback function called";
  12797. char sql[100];
  12798. char zErrMsg[100];
  12799. memset(sql, 0, 100);
  12800. memset(zErrMsg, 0, 100);
  12801. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  12802. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12803. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12804. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12805. /* Execute SQL statement */
  12806. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12807. if( rc != SQLITE_OK )
  12808. {
  12809. DEBUG_INFO("SQL error: %s", zErrMsg);
  12810. }
  12811. //return ver;
  12812. }
  12813. void OCPP_get_TableAuthlocalAllData(void)
  12814. {
  12815. int rc = 0;
  12816. char sql[100];
  12817. char zErrMsg[100];
  12818. memset(sql, 0, 100);
  12819. memset(zErrMsg, 0, 100);
  12820. sprintf(sql,"select * from ocpp_auth_local ");
  12821. /* Execute SQL statement */
  12822. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12823. if( rc != SQLITE_OK )
  12824. {
  12825. DEBUG_INFO("SQL error: %s", zErrMsg);
  12826. }
  12827. //return ver;
  12828. }
  12829. int OCPP_cleanLocalList()
  12830. {
  12831. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12832. char *errMsg = 0;
  12833. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12834. if (SQLITE_OK != rc)
  12835. {
  12836. DEBUG_INFO("%s\n",errMsg);
  12837. return FALSE;
  12838. }
  12839. return TRUE;
  12840. }
  12841. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12842. {
  12843. int isSuccess = FALSE;
  12844. int ret = 0;
  12845. //const char* data = "Callback function called";
  12846. char sql[300];
  12847. char zErrMsg[200];
  12848. memset(sql, 0, 300);
  12849. memset(zErrMsg, 0, 200);
  12850. 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);
  12851. //* Execute SQL statement */
  12852. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12853. if( ret != SQLITE_OK )
  12854. {
  12855. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12856. return isSuccess;
  12857. }
  12858. memset(sql, 0, 300);
  12859. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  12860. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  12861. if( ret != SQLITE_OK )
  12862. {
  12863. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12864. return isSuccess;
  12865. }
  12866. isSuccess = TRUE;
  12867. return isSuccess;
  12868. }
  12869. void OCPP_deleteIdTag(char idTag[])
  12870. {
  12871. //int ver = 0;
  12872. //int isSuccess = FALSE;
  12873. int rc = 0;
  12874. char sql[100];
  12875. char zErrMsg[100];
  12876. memset(sql, 0, 100);
  12877. memset(zErrMsg, 0, 100);
  12878. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12879. //* Execute SQL statement */
  12880. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12881. if( rc != SQLITE_OK )
  12882. {
  12883. DEBUG_INFO("SQL error: %s", zErrMsg);
  12884. }
  12885. }
  12886. int GetOcppServerURL()
  12887. {
  12888. int result = FALSE;
  12889. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  12890. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  12891. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  12892. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12893. {
  12894. #if 1
  12895. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12896. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12897. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12898. #endif
  12899. result = TRUE;
  12900. goto End;
  12901. }
  12902. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12903. {
  12904. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12905. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12906. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12907. result = TRUE;
  12908. goto End;
  12909. }
  12910. else
  12911. {
  12912. strcpy(OcppHost,"");
  12913. }
  12914. End:
  12915. return result;
  12916. }
  12917. int GetOcppPath()
  12918. {
  12919. int result = FALSE;
  12920. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12921. {
  12922. if(OcppTempPath == NULL)
  12923. {
  12924. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12925. }
  12926. else
  12927. {
  12928. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12929. }
  12930. result = TRUE;
  12931. goto End;
  12932. }
  12933. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12934. {
  12935. if(OcppTempPath == NULL)
  12936. {
  12937. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12938. }
  12939. else
  12940. {
  12941. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12942. }
  12943. result = TRUE;
  12944. goto End;
  12945. }
  12946. else
  12947. {
  12948. strcpy(OcppPath,"");
  12949. }
  12950. End:
  12951. return result;
  12952. }
  12953. int GetOcppPort()
  12954. {
  12955. return OcppPort;
  12956. }
  12957. int GetOcppConnStatus(void)
  12958. {
  12959. return ShmOCPP16Data->OcppConnStatus;
  12960. }
  12961. void SetOcppConnStatus(uint8_t status)
  12962. {
  12963. ShmOCPP16Data->OcppConnStatus = status;
  12964. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12965. }
  12966. int GetHeartBeatWithNOResponse(void)
  12967. {
  12968. return HeartBeatWithNOResponse;
  12969. }
  12970. void SetHeartBeatWithNOResponse(void)
  12971. {
  12972. HeartBeatWithNOResponse = 0;
  12973. }
  12974. void GetStartTransactionIdTag(int gun_index)
  12975. {
  12976. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  12977. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  12978. }
  12979. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  12980. {
  12981. char ch;
  12982. FILE *fptr1;
  12983. int temptransactionId;
  12984. char str[100]={0};
  12985. temptransactionId = 0;
  12986. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  12987. {
  12988. DEBUG_INFO("IdTag is empty.\n");
  12989. return temptransactionId;
  12990. }
  12991. /*------ Read the file ----------------*/
  12992. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  12993. if (!fptr1)
  12994. {
  12995. DEBUG_INFO("QueueTransactionId file open error.\n");
  12996. //printf(" File not found or unable to open the input file!!\n");
  12997. return temptransactionId;
  12998. }
  12999. ch=fgetc(fptr1);
  13000. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13001. rewind(fptr1);
  13002. if(ch!=EOF)
  13003. {
  13004. // printf("%c",ch);
  13005. while (fgets(str, 100, fptr1) != NULL)
  13006. {
  13007. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13008. if(str[0]=='\0')
  13009. {
  13010. break;
  13011. }
  13012. char *revbuf[8] = {0}; //存放分割後的子字串
  13013. int num = 0;//分割後子字串的個數
  13014. DEBUG_INFO("str: %s\n", str);
  13015. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13016. DEBUG_INFO("revbuf[0]: %s\n", revbuf[0]);
  13017. DEBUG_INFO("revbuf[1]: %s\n", revbuf[1]);
  13018. DEBUG_INFO("revbuf[2]: %s\n", revbuf[2]);
  13019. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13020. {
  13021. if(isStopTransaction)
  13022. {
  13023. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13024. {
  13025. temptransactionId = atoi(revbuf[2]);
  13026. break;
  13027. }
  13028. }
  13029. else
  13030. {
  13031. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13032. {
  13033. temptransactionId = atoi(revbuf[2]);
  13034. break;
  13035. }
  13036. }
  13037. }
  13038. }
  13039. }
  13040. else
  13041. DEBUG_INFO("EOF\n");
  13042. fclose(fptr1);
  13043. /*------- End of reading ---------------*/
  13044. return temptransactionId;
  13045. }
  13046. void SetTransactionIdZero(int transactionId)
  13047. {
  13048. char ch;
  13049. FILE *fptr1, *fptr2;
  13050. int temptransactionId = 0;
  13051. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13052. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13053. if (!fptr1)
  13054. {
  13055. //printf(" File not found or unable to open the input file!!\n");
  13056. return ;
  13057. }
  13058. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13059. if (!fptr2)
  13060. {
  13061. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13062. fclose(fptr1);
  13063. return ;
  13064. }
  13065. ch=fgetc(fptr1);
  13066. rewind(fptr1);
  13067. if(ch!=EOF)
  13068. {
  13069. // copy all contents to the temporary file except the specific line
  13070. while (fgets(str, 100, fptr1) != NULL)
  13071. {
  13072. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13073. if(str[0]=='\0')
  13074. {
  13075. break;
  13076. }
  13077. char *revbuf[8] = {0};
  13078. int num = 0;
  13079. strcpy(strtemp, str);
  13080. splitstring(str,",",revbuf,&num);
  13081. if(revbuf[2][0] != '\0')
  13082. {
  13083. temptransactionId = atoi(revbuf[2]);
  13084. if(transactionId != temptransactionId)
  13085. {
  13086. fprintf(fptr2, "%s\n", strtemp);
  13087. }
  13088. }
  13089. }
  13090. }
  13091. fclose(fptr1);
  13092. fclose(fptr2);
  13093. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13094. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13095. /*------ Read the file ----------------*/
  13096. }
  13097. int InternetDisconnect(void)
  13098. {
  13099. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13100. }
  13101. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13102. void storeTempStopTransaction(int gun_index)
  13103. {
  13104. char guid[37]={0};
  13105. int tempIndex = 0;
  13106. char TempStopTransaction[256];
  13107. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13108. DEBUG_INFO("storeTempStopTransaction...\n");
  13109. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13110. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13111. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13112. if(gunType[gun_index] == 'J')
  13113. {
  13114. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13115. {
  13116. tempIndex = ((gun_index==2) ? 1: 0);
  13117. }
  13118. else
  13119. {
  13120. tempIndex = gun_index;
  13121. }
  13122. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13123. {
  13124. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13125. {
  13126. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13127. }
  13128. }// END OF CHAdeMO_QUANTITY
  13129. }
  13130. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13131. {
  13132. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13133. {
  13134. tempIndex = ((gun_index==2) ? 1: 0);
  13135. }
  13136. else
  13137. {
  13138. tempIndex = gun_index;
  13139. }
  13140. for (int index = 0; index < CCS_QUANTITY; index++)
  13141. {
  13142. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13143. {
  13144. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13145. }
  13146. }// END OF CCS_QUANTITY
  13147. }
  13148. else if(gunType[gun_index] == 'G')
  13149. {
  13150. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13151. {
  13152. tempIndex = ((gun_index==2) ? 1: 0);
  13153. }
  13154. else
  13155. {
  13156. tempIndex = gun_index;
  13157. }
  13158. for (int index = 0; index < GB_QUANTITY; index++)
  13159. {
  13160. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13161. {
  13162. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13163. }
  13164. }// END OF GB_QUANTITY
  13165. }
  13166. else
  13167. {
  13168. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13169. {
  13170. tempIndex = 2;
  13171. }
  13172. else
  13173. {
  13174. tempIndex = gun_index;
  13175. }
  13176. for (int index = 0; index < AC_QUANTITY; index++)
  13177. {
  13178. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13179. {
  13180. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13181. }
  13182. }// END OF AC_QUANTITY
  13183. }
  13184. //Stop Transaction Time
  13185. struct timeval tmnow;
  13186. struct tm *tm;
  13187. char buf[28];//, usec_buf[6];
  13188. gettimeofday(&tmnow, NULL);
  13189. time_t t;
  13190. t = time(NULL);
  13191. /*UTC time and date*/
  13192. tm = gmtime(&t);
  13193. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13194. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13195. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13197. random_uuid(guid);
  13198. /***********************************transactionData******************************************************/
  13199. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13201. //=================================
  13202. //1. Transaction_Begin
  13203. //=================================
  13204. //============================== Energy.Active.Import.Interval ===========================================
  13205. //idx_sample=0;
  13206. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  13207. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13208. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13209. 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*/]);
  13210. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13211. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13212. {
  13213. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13214. }
  13215. else
  13216. {
  13217. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13218. }
  13219. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13220. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13221. //=================================
  13222. //2. Transaction_End
  13223. //=================================
  13224. //2.1====================================== Current.Import L1 ==============================================
  13225. //idx_sample=1;
  13226. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13227. if(gunType[gun_index] == 'J')
  13228. {
  13229. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13230. {
  13231. tempIndex = ((gun_index==2) ? 1: 0);
  13232. }
  13233. else
  13234. {
  13235. tempIndex = gun_index;
  13236. }
  13237. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13238. {
  13239. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13240. {
  13241. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13242. }
  13243. }// End of for CHAdeMO_QUANTITY
  13244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13245. }
  13246. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13247. {
  13248. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13249. {
  13250. tempIndex = ((gun_index==2) ? 1: 0);
  13251. }
  13252. else
  13253. {
  13254. tempIndex = gun_index;
  13255. }
  13256. for (int index = 0; index < CCS_QUANTITY; index++)
  13257. {
  13258. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13259. {
  13260. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13261. }
  13262. }// End of for CCS_QUANTITY
  13263. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13264. }
  13265. else if(gunType[gun_index] == 'G')
  13266. {
  13267. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13268. {
  13269. tempIndex = ((gun_index==2) ? 1: 0);
  13270. }
  13271. else
  13272. {
  13273. tempIndex = gun_index;
  13274. }
  13275. for (int index = 0; index < GB_QUANTITY; index++)
  13276. {
  13277. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13278. {
  13279. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13280. }
  13281. }// End of for GB_QUANTITY
  13282. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13283. }
  13284. else
  13285. {
  13286. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13287. {
  13288. tempIndex = 2;
  13289. }
  13290. else
  13291. {
  13292. tempIndex = gun_index;
  13293. }
  13294. for (int index = 0; index < AC_QUANTITY; index++)
  13295. {
  13296. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13297. {
  13298. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13299. }
  13300. }// End of for AC_QUANTITY
  13301. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13302. }
  13303. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13304. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13305. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13306. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13307. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13308. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13309. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13310. //idx_sample=2;
  13311. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13312. if(gunType[gun_index] == 'J')
  13313. {
  13314. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13315. {
  13316. tempIndex = ((gun_index==2) ? 1: 0);
  13317. }
  13318. else
  13319. {
  13320. tempIndex = gun_index;
  13321. }
  13322. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13323. {
  13324. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13325. {
  13326. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13327. }
  13328. }// END OF CHAdeMO_QUANTITY
  13329. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13330. }
  13331. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13332. {
  13333. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13334. {
  13335. tempIndex = ((gun_index==2) ? 1: 0);
  13336. }
  13337. else
  13338. {
  13339. tempIndex = gun_index;
  13340. }
  13341. for (int index = 0; index < CCS_QUANTITY; index++)
  13342. {
  13343. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13344. {
  13345. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13346. }
  13347. }// END OF CCS_QUANTITY
  13348. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13349. }
  13350. else if(gunType[gun_index] == 'G')
  13351. {
  13352. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13353. {
  13354. tempIndex = ((gun_index==2) ? 1: 0);
  13355. }
  13356. else
  13357. {
  13358. tempIndex = gun_index;
  13359. }
  13360. for (int index = 0; index < GB_QUANTITY; index++)
  13361. {
  13362. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13363. {
  13364. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13365. }
  13366. }// END OF GB_QUANTITY
  13367. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13368. }
  13369. else
  13370. {
  13371. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13372. {
  13373. tempIndex = 2;
  13374. }
  13375. else
  13376. {
  13377. tempIndex = gun_index;
  13378. }
  13379. for (int index = 0; index < AC_QUANTITY; index++)
  13380. {
  13381. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13382. {
  13383. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13384. }
  13385. }// END OF AC_QUANTITY
  13386. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13387. }
  13388. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13389. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13390. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13391. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13392. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13393. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13394. //2.3====================================== Power.Active.Import =========================================
  13395. //idx_sample=3;
  13396. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13397. if(gunType[gun_index] == 'J')
  13398. {
  13399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13400. {
  13401. tempIndex = ((gun_index==2) ? 1: 0);
  13402. }
  13403. else
  13404. {
  13405. tempIndex = gun_index;
  13406. }
  13407. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13408. {
  13409. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13410. {
  13411. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13412. }
  13413. } // End for CHAdeMO_QUANTITY
  13414. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13415. }
  13416. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13417. {
  13418. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13419. {
  13420. tempIndex = ((gun_index==2) ? 1: 0);
  13421. }
  13422. else
  13423. {
  13424. tempIndex = gun_index;
  13425. }
  13426. for (int index = 0; index < CCS_QUANTITY; index++)
  13427. {
  13428. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13429. {
  13430. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13431. }
  13432. } // END for CCS_QUANTITY
  13433. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13434. }
  13435. else if(gunType[gun_index] == 'G')
  13436. {
  13437. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13438. {
  13439. tempIndex = ((gun_index==2) ? 1: 0);
  13440. }
  13441. else
  13442. {
  13443. tempIndex = gun_index;
  13444. }
  13445. for (int index = 0; index < GB_QUANTITY; index++)
  13446. {
  13447. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13448. {
  13449. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13450. }
  13451. }// END for GB_QUANTITY
  13452. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13453. }
  13454. else
  13455. {
  13456. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13457. {
  13458. tempIndex = 2;
  13459. }
  13460. else
  13461. {
  13462. tempIndex = gun_index;
  13463. }
  13464. for (int index = 0; index < AC_QUANTITY; index++)
  13465. {
  13466. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13467. {
  13468. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13469. }
  13470. } // END for AC_QUANTITY
  13471. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13472. }
  13473. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13474. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13475. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13476. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13477. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13479. //2.4====================================== Voltage L1 ====================================================
  13480. //idx_sample=4;
  13481. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13482. if(gunType[gun_index] == 'J')
  13483. {
  13484. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13485. {
  13486. tempIndex = ((gun_index==2) ? 1: 0);
  13487. }
  13488. else
  13489. {
  13490. tempIndex = gun_index;
  13491. }
  13492. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13493. {
  13494. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13495. {
  13496. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13497. }
  13498. } // END OF FOR CHAdeMO_QUANTITY
  13499. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13500. }
  13501. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13502. {
  13503. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13504. {
  13505. tempIndex = ((gun_index==2) ? 1: 0);
  13506. }
  13507. else
  13508. {
  13509. tempIndex = gun_index;
  13510. }
  13511. for (int index = 0; index < CCS_QUANTITY; index++)
  13512. {
  13513. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13514. {
  13515. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13516. }
  13517. } // END OF FOR CCS_QUANTITY
  13518. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13519. }
  13520. else if(gunType[gun_index] == 'G')
  13521. {
  13522. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13523. {
  13524. tempIndex = ((gun_index==2) ? 1: 0);
  13525. }
  13526. else
  13527. {
  13528. tempIndex = gun_index;
  13529. }
  13530. for (int index = 0; index < GB_QUANTITY; index++)
  13531. {
  13532. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13533. {
  13534. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13535. }
  13536. } // END OF FOR GB_QUANTITY
  13537. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13538. }
  13539. else
  13540. {
  13541. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13542. {
  13543. tempIndex = 2;
  13544. }
  13545. else
  13546. {
  13547. tempIndex = gun_index;
  13548. }
  13549. for (int index = 0; index < AC_QUANTITY; index++)
  13550. {
  13551. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13552. {
  13553. 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
  13554. }
  13555. } // END OF FOR AC_QUANTITY
  13556. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13557. }
  13558. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13559. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13560. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13561. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13562. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13563. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13564. //2.5============================================== SoC =========================================================
  13565. //idx_sample=5;
  13566. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13567. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13568. {
  13569. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13570. {
  13571. tempIndex = ((gun_index==2) ? 1: 0);
  13572. }
  13573. else
  13574. {
  13575. tempIndex = gun_index;
  13576. }
  13577. if(gunType[gun_index] == 'J')
  13578. {
  13579. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13580. {
  13581. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13582. {
  13583. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13584. }
  13585. }
  13586. }
  13587. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13588. {
  13589. for (int index = 0; index < CCS_QUANTITY; index++)
  13590. {
  13591. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13592. {
  13593. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13594. }
  13595. }
  13596. }
  13597. else if(gunType[gun_index] == 'G')
  13598. {
  13599. for (int index = 0; index < GB_QUANTITY; index++)
  13600. {
  13601. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13602. {
  13603. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13604. }
  13605. }
  13606. }
  13607. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13608. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13609. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13610. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13611. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  13612. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13613. } // END FOR DC CASE
  13614. //2.6====================================== Current.Import L2 ==============================================
  13615. // idx_sample=6;
  13616. // AC 3 phase L2 current
  13617. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13618. {
  13619. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13620. {
  13621. tempIndex = 2;
  13622. }
  13623. else
  13624. {
  13625. tempIndex = gun_index;
  13626. }
  13627. for (int index = 0; index < AC_QUANTITY; index++)
  13628. {
  13629. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13630. {
  13631. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  13632. }
  13633. }// End of for AC_QUANTITY
  13634. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  13635. }
  13636. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13637. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  13638. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  13639. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  13640. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13641. //2.7====================================== Current.Import L3 ==============================================
  13642. // idx_sample=7;
  13643. // AC 3 phase L3 current
  13644. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13645. {
  13646. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13647. {
  13648. tempIndex = 2;
  13649. }
  13650. else
  13651. {
  13652. tempIndex = gun_index;
  13653. }
  13654. for (int index = 0; index < AC_QUANTITY; index++)
  13655. {
  13656. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13657. {
  13658. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  13659. }
  13660. }// End of for AC_QUANTITY
  13661. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  13662. }
  13663. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13664. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  13665. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  13666. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  13667. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13668. //2.9====================================== Voltage L2 ====================================================
  13669. //idx_sample=8;
  13670. // AC 3 phase L2 volatge
  13671. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13672. {
  13673. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13674. {
  13675. tempIndex = 2;
  13676. }
  13677. else
  13678. {
  13679. tempIndex = gun_index;
  13680. }
  13681. for (int index = 0; index < AC_QUANTITY; index++)
  13682. {
  13683. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13684. {
  13685. 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
  13686. }
  13687. } // END OF FOR AC_QUANTITY
  13688. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  13689. }
  13690. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13691. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  13692. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  13693. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  13694. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13695. //2.10====================================== Voltage L3 ====================================================
  13696. //idx_sample=9;
  13697. // AC 3 phase L3 volatge
  13698. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13699. {
  13700. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13701. {
  13702. tempIndex = 2;
  13703. }
  13704. else
  13705. {
  13706. tempIndex = gun_index;
  13707. }
  13708. for (int index = 0; index < AC_QUANTITY; index++)
  13709. {
  13710. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13711. {
  13712. 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
  13713. }
  13714. } // END OF FOR AC_QUANTITY
  13715. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  13716. }
  13717. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13718. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  13719. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  13720. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  13721. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13722. //======================================== Message create ==============================================
  13723. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13724. {
  13725. 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\"}]}]}]"
  13726. ,gun_index+1
  13727. ,MESSAGE_TYPE_CALL
  13728. ,guid
  13729. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13730. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13731. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13732. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13733. ,"PowerLoss"
  13734. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13735. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13736. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13737. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13738. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13739. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13740. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13741. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13742. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13743. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13744. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13745. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13746. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13747. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13748. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13749. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13750. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13751. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13752. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13753. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13754. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13755. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13756. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13757. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13758. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13759. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13760. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13761. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13762. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13763. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13764. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13765. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13766. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13767. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13768. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13769. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13770. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  13771. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  13772. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  13773. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  13774. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  13775. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  13776. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  13777. );
  13778. }
  13779. else
  13780. {
  13781. if(((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W')))
  13782. {
  13783. 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\"}]}]}]"
  13784. ,gun_index+1
  13785. ,MESSAGE_TYPE_CALL
  13786. ,guid
  13787. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13788. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13789. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13790. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13791. ,"PowerLoss"
  13792. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13793. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13794. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13795. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13796. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13797. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13798. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13799. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13800. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13801. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13802. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13803. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13804. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13805. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13806. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13807. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13808. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13809. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13810. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13811. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13812. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13813. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13814. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13815. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13816. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13817. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13818. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13819. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13820. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13821. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13822. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13823. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13824. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13825. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13826. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13827. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13828. );
  13829. }
  13830. else
  13831. {
  13832. 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\"}]}]}]"
  13833. ,gun_index+1
  13834. ,MESSAGE_TYPE_CALL
  13835. ,guid
  13836. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13837. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13838. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13839. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13840. ,"PowerLoss"
  13841. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13842. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13843. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13844. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13845. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13846. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13847. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13848. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13849. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13850. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13851. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13852. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13853. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13854. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13855. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13856. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13857. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13858. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13859. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13860. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13861. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13862. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13863. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13864. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13865. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13866. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13867. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13868. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13869. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13870. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13871. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  13878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  13879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  13880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  13881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  13882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  13883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  13884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  13885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  13886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  13887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  13888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  13889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  13890. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  13891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  13892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  13893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  13894. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  13895. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  13896. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  13897. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  13898. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  13899. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  13900. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  13901. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  13902. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  13903. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  13904. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  13905. );
  13906. }
  13907. }
  13908. // Check File "TempStopTransaction" Exist
  13909. if((access(TempStopTransaction,F_OK))!=-1)
  13910. {
  13911. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  13912. fclose(fopen(TempStopTransaction, "w"));
  13913. }
  13914. else
  13915. {
  13916. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  13917. FILE *log = fopen(TempStopTransaction, "w+");
  13918. if(log == NULL)
  13919. {
  13920. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  13921. return ;
  13922. }
  13923. else
  13924. {
  13925. fclose(log);
  13926. }
  13927. }
  13928. //Add TempStopTransaction | Update TempStopTransaction
  13929. // open file for writing
  13930. FILE *outfile;
  13931. outfile = fopen (TempStopTransaction, "a");
  13932. //DEBUG_INFO("data = %s\n", queuedata);
  13933. fputs(queuedata, outfile);
  13934. fputs("\n", outfile);
  13935. fclose (outfile);
  13936. }
  13937. void checkTempStopTransaction(int gun_index)
  13938. {
  13939. FILE *fptr1;
  13940. char ch;
  13941. char str[QUEUE_MESSAGE_LENGTH]={0};
  13942. char guid[37]={0};
  13943. char tempdata[65]={0};
  13944. char connectorStr[2]={0};
  13945. char TempStopTransaction[256];
  13946. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13947. fptr1 = fopen(TempStopTransaction, "r");
  13948. //TempStopTransaction格式: 槍號,StopTransaction封包
  13949. if (!fptr1)
  13950. {
  13951. //printf(" File not found or unable to open the input file!!\n");
  13952. return ;
  13953. }
  13954. ch=fgetc(fptr1);
  13955. //printf(" Now the content of the file %s is : \n",fname);
  13956. rewind(fptr1);
  13957. if(ch!=EOF)
  13958. {
  13959. // copy all contents to the temporary file except the specific line
  13960. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  13961. {
  13962. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13963. if(str[0]=='\0')
  13964. {
  13965. break;
  13966. }
  13967. //TempStopTransaction格式: 槍號,StopTransaction封包
  13968. strncpy(connectorStr, str, 1);
  13969. if(atoi(connectorStr) != (gun_index+1))
  13970. {
  13971. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  13972. fclose(fptr1);
  13973. return ;
  13974. }
  13975. //random_uuid(guid);
  13976. strncpy(guid, str+6, 36); //copy guid
  13977. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  13978. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  13979. {
  13980. DEBUG_INFO("StopTransaction mapitem pass\n");
  13981. }
  13982. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  13983. memset(str,0,ARRAY_SIZE(str));
  13984. }
  13985. }
  13986. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  13987. fclose(fptr1);
  13988. remove(TempStopTransaction); // remove the original file
  13989. }
  13990. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  13991. {
  13992. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  13993. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  13994. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  13995. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  13996. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  13997. }
  13998. int GetWebSocketPingInterval(void)
  13999. {
  14000. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14001. }
  14002. int GetServerSign(void)
  14003. {
  14004. return server_sign;
  14005. }
  14006. void SetServerSign(int value)
  14007. {
  14008. server_sign = value;
  14009. }
  14010. int GetBootNotificationInterval(void)
  14011. {
  14012. return BootNotificationInterval;
  14013. }
  14014. int GetInternetConn(void)
  14015. {
  14016. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14017. }
  14018. void InitialSystemValue(void)
  14019. {
  14020. int connectorIndex = 0;
  14021. //int valueASCII = 0;
  14022. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14023. gunTotalNumber=0;
  14024. SystemInitial = 0;
  14025. localversion=0;
  14026. BootNotificationInterval = 0;
  14027. authorizeRetryTimes = 0;
  14028. GunStatusInterval = 10;
  14029. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14030. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14031. //Hear Beat
  14032. HeartBeatWithNOResponse = 0;
  14033. HeartBeatCountPerHour = 0;
  14034. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14035. FirstHeartBeat = 0;
  14036. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14037. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14038. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14039. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14040. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14041. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14042. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14043. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14044. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14045. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14046. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14047. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14048. memset(gunType, 0, ARRAY_SIZE(gunType));
  14049. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14050. {
  14051. //check connector / socket type (index: 8, 9, 10)
  14052. for(int index=7; index <10 ; index++)
  14053. {
  14054. if(index != 8)
  14055. {
  14056. // DC Connector
  14057. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  14058. {
  14059. SystemInitial = SystemInitial + 1;
  14060. gunTotalNumber = gunTotalNumber + 1;
  14061. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14062. connectorIndex = connectorIndex + 1;
  14063. }
  14064. }
  14065. else
  14066. {
  14067. // AC Connector
  14068. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14069. {
  14070. SystemInitial = SystemInitial + 1;
  14071. gunTotalNumber = gunTotalNumber + 1;
  14072. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14073. connectorIndex = connectorIndex + 1;
  14074. }
  14075. }
  14076. }
  14077. //DEBUG_INFO("DC ...\n");
  14078. }
  14079. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14080. {
  14081. //check connector / socket type (index: 8, 9, 10)
  14082. for(int index=7; index <10 ; index++)
  14083. {
  14084. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14085. {
  14086. SystemInitial = SystemInitial + 1;
  14087. gunTotalNumber = gunTotalNumber + 1;
  14088. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14089. connectorIndex = connectorIndex + 1;
  14090. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14091. }
  14092. }
  14093. }
  14094. //Status && ConnectorPlugIn Setting
  14095. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14096. {
  14097. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14098. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14099. }
  14100. for (int index = 0; index < CCS_QUANTITY; index++)
  14101. {
  14102. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14103. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14104. }
  14105. for (int index = 0; index < GB_QUANTITY; index++)
  14106. {
  14107. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14108. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14109. }
  14110. for (int index = 0; index < AC_QUANTITY; index++)
  14111. {
  14112. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14113. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14114. }
  14115. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14116. {
  14117. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14118. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14119. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14120. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14121. }
  14122. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14123. clientTime.Heartbeat=time((time_t*)NULL);
  14124. sleep(1);
  14125. }
  14126. void LWS_Send(char * str)
  14127. {
  14128. //=====================================================
  14129. // Check InternetConn 0: disconnected, 1: connected
  14130. //====================================================
  14131. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14132. {
  14133. DEBUG_INFO("offline now !!!\n");
  14134. return;
  14135. }
  14136. pthread_mutex_lock(&lock_send);
  14137. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14138. sprintf((char *)SendBuffer, "%s", str);
  14139. SendBufLen = strlen(str);
  14140. pthread_mutex_unlock(&lock_send);
  14141. lws_callback_on_writable(wsi_client);
  14142. //lws_service(context, 0);
  14143. //sleep(1);
  14144. }
  14145. void LWS_SendNow(char * str)
  14146. {
  14147. //=====================================================
  14148. // Check InternetConn 0: disconnected, 1: connected
  14149. //====================================================
  14150. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14151. {
  14152. DEBUG_INFO("offline now !!!\n");
  14153. return;
  14154. }
  14155. pthread_mutex_lock(&lock_send);
  14156. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14157. sprintf((char *)SendBuffer, "%s", str);
  14158. SendBufLen = strlen(str);
  14159. pthread_mutex_unlock(&lock_send);
  14160. lws_callback_on_writable(wsi_client);
  14161. lws_service(context, 0);
  14162. //sleep(1);
  14163. }