MessageHandler.c 676 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258
  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 getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  444. {
  445. int result = -1;
  446. struct tm tmStart;
  447. struct timeb tbStart;
  448. struct tm tmStop;
  449. struct timeb tbStop;
  450. 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) &&
  451. (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))
  452. {
  453. tmStart.tm_year -= 1900;
  454. tmStart.tm_mon -= 1;
  455. tbStart.time = mktime(&tmStart);
  456. tbStart.millitm = 0;
  457. tmStop.tm_year -= 1900;
  458. tmStop.tm_mon -= 1;
  459. tbStop.time = mktime(&tmStop);
  460. tbStop.millitm = 0;
  461. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  462. }
  463. return result;
  464. }
  465. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  466. {
  467. FILE *fp;
  468. char profileFileName[128];
  469. char *line = NULL;
  470. size_t len = 0;
  471. time_t CurrentTime;
  472. struct tm *tmComposite;
  473. struct StructChargingProfile maxProfile;
  474. struct StructChargingProfile defaultTxProfile;
  475. struct StructChargingProfile txProfile;
  476. struct StructChargingSchedulePeriod tmpPeriod;
  477. uint8_t limitMax=0;
  478. uint8_t limitDef=0;
  479. uint8_t limitTx=0;
  480. int compositePeriodIdx = 0;
  481. CurrentTime = time(NULL);
  482. tmComposite=localtime(&CurrentTime);
  483. 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);
  484. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  485. compositeProfile->ChargingSchedule.Duration = durationReq;
  486. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  487. {
  488. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  489. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  490. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  491. }
  492. compositeProfile->ChargingProfileId = 0;
  493. compositeProfile->StackLevel = 99 ;
  494. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  495. maxProfile.ChargingProfileId = -1;
  496. defaultTxProfile.ChargingProfileId = -1;
  497. txProfile.ChargingProfileId = -1;
  498. maxProfile.ChargingSchedule.Duration = -1;
  499. defaultTxProfile.ChargingSchedule.Duration = -1;
  500. txProfile.ChargingSchedule.Duration = -1;
  501. system("yes|rm /tmp/*.json");
  502. system("cp /Storage/OCPP/*.json /tmp");
  503. /*
  504. * Search valid charging profile
  505. */
  506. //DEBUG_INFO("====================================\n");
  507. // Search tx profile
  508. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  509. if((access(profileFileName, F_OK))!=-1)
  510. {
  511. fp = fopen(profileFileName, "r");
  512. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  513. {
  514. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  515. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  516. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  517. }
  518. txProfile.ChargingProfileId = -1;
  519. txProfile.StackLevel = -1;
  520. while(getline(&line, &len, fp) != -1)
  521. {
  522. json_object *obj = NULL;
  523. obj = json_tokener_parse(line);
  524. if(is_error(obj))
  525. {
  526. DEBUG_ERROR("Parse txProfile from file error.\n");
  527. }
  528. else
  529. {
  530. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  531. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  532. )
  533. {
  534. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  535. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  536. )
  537. {
  538. struct tm tmFrom, tmTo;
  539. struct timeb tbFrom, tbTo;
  540. 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) &&
  541. (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))
  542. {
  543. tmFrom.tm_year -= 1900;
  544. tmFrom.tm_mon -= 1;
  545. tbFrom.time = mktime(&tmFrom);
  546. tmTo.tm_year -= 1900;
  547. tmTo.tm_mon -= 1;
  548. tbTo.time = mktime(&tmTo);
  549. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  550. {
  551. if(txProfile.ChargingProfileId == -1)
  552. DEBUG_INFO("TxProfile found.\n");
  553. else
  554. DEBUG_INFO("TxProfile updated.\n");
  555. // Required item
  556. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  557. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  558. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  559. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  560. 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++)
  561. {
  562. 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"));
  563. 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")));
  564. 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?
  565. 3:
  566. 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")));
  567. }
  568. // Optional item
  569. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  570. {
  571. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  572. }
  573. else
  574. {
  575. sprintf((char*)txProfile.ValidFrom, " ");
  576. }
  577. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  578. {
  579. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  580. }
  581. else
  582. {
  583. sprintf((char*)txProfile.ValidTo, " ");
  584. }
  585. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  586. {
  587. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  588. }
  589. else
  590. {
  591. sprintf((char*)txProfile.RecurrencyKind, " ");
  592. }
  593. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  594. {
  595. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  596. }
  597. else
  598. {
  599. txProfile.TransactionId = -1;
  600. }
  601. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  602. {
  603. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  604. }
  605. else
  606. {
  607. txProfile.ChargingSchedule.Duration = 86400;
  608. }
  609. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  610. {
  611. 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")));
  612. }
  613. else
  614. {
  615. 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));
  616. }
  617. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  618. {
  619. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  620. }
  621. else
  622. {
  623. txProfile.ChargingSchedule.MinChargingRate = -1;
  624. }
  625. }
  626. }
  627. }
  628. else
  629. {
  630. if(txProfile.ChargingProfileId == -1)
  631. DEBUG_INFO("TxProfile found.\n");
  632. else
  633. DEBUG_INFO("TxProfile updated.\n");
  634. // Required item
  635. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  636. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  637. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  638. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  639. 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++)
  640. {
  641. 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"));
  642. 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")));
  643. 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?
  644. 3:
  645. 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")));
  646. }
  647. // Optional item
  648. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  649. {
  650. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  651. }
  652. else
  653. {
  654. sprintf((char*)txProfile.ValidFrom, " ");
  655. }
  656. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  657. {
  658. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  659. }
  660. else
  661. {
  662. sprintf((char*)txProfile.ValidTo, " ");
  663. }
  664. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  665. {
  666. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  667. }
  668. else
  669. {
  670. sprintf((char*)txProfile.RecurrencyKind, " ");
  671. }
  672. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  673. {
  674. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  675. }
  676. else
  677. {
  678. txProfile.TransactionId = -1;
  679. }
  680. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  681. {
  682. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  683. }
  684. else
  685. {
  686. txProfile.ChargingSchedule.Duration = 86400;
  687. }
  688. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  689. {
  690. 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")));
  691. }
  692. else
  693. {
  694. 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));
  695. }
  696. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  697. {
  698. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  699. }
  700. else
  701. {
  702. txProfile.ChargingSchedule.MinChargingRate = -1;
  703. }
  704. }
  705. }
  706. }
  707. json_object_put(obj);
  708. }
  709. fclose(fp);
  710. /*
  711. if(txProfile.ChargingProfileId != -1)
  712. {
  713. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  714. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  715. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  716. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  717. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  718. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  719. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  720. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  721. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  722. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  723. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  724. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  725. {
  726. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  727. {
  728. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  729. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  730. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  731. }
  732. }
  733. }
  734. else
  735. DEBUG_INFO("TxProfile not found.\n");*/
  736. }
  737. // Search default tx profile
  738. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  739. if((access(profileFileName, F_OK))==-1)
  740. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  741. if((access(profileFileName, F_OK))!=-1)
  742. {
  743. fp = fopen(profileFileName, "r");
  744. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  745. {
  746. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  747. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  748. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  749. }
  750. defaultTxProfile.ChargingProfileId = -1;
  751. defaultTxProfile.StackLevel = -1;
  752. while(getline(&line, &len, fp) != -1)
  753. {
  754. json_object *obj = NULL;
  755. obj = json_tokener_parse(line);
  756. if(is_error(obj))
  757. {
  758. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  759. }
  760. else
  761. {
  762. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  763. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  764. )
  765. {
  766. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  767. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  768. )
  769. {
  770. struct tm tmFrom, tmTo;
  771. struct timeb tbFrom, tbTo;
  772. 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) &&
  773. (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))
  774. {
  775. tmFrom.tm_year -= 1900;
  776. tmFrom.tm_mon -= 1;
  777. tbFrom.time = mktime(&tmFrom);
  778. tmTo.tm_year -= 1900;
  779. tmTo.tm_mon -= 1;
  780. tbTo.time = mktime(&tmTo);
  781. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  782. {
  783. if(defaultTxProfile.ChargingProfileId == -1)
  784. DEBUG_INFO("TxDefaultProfile found.\n");
  785. else
  786. DEBUG_INFO("TxDefaultProfile updated.\n");
  787. // Required item
  788. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  789. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  790. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  791. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  792. 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++)
  793. {
  794. 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"));
  795. 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")));
  796. 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?
  797. 3:
  798. 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")));
  799. }
  800. // Optional item
  801. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  802. {
  803. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  804. }
  805. else
  806. {
  807. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  808. }
  809. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  810. {
  811. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  812. }
  813. else
  814. {
  815. sprintf((char*)defaultTxProfile.ValidTo, " ");
  816. }
  817. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  818. {
  819. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  820. }
  821. else
  822. {
  823. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  824. }
  825. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  826. {
  827. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  828. }
  829. else
  830. {
  831. defaultTxProfile.TransactionId = -1;
  832. }
  833. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  834. {
  835. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  836. }
  837. else
  838. {
  839. defaultTxProfile.ChargingSchedule.Duration = 86400;
  840. }
  841. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  842. {
  843. 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")));
  844. }
  845. else
  846. {
  847. 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));
  848. }
  849. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  850. {
  851. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  852. }
  853. else
  854. {
  855. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  856. }
  857. }
  858. }
  859. }
  860. else
  861. {
  862. if(defaultTxProfile.ChargingProfileId == -1)
  863. DEBUG_INFO("TxDefaultProfile found.\n");
  864. else
  865. DEBUG_INFO("TxDefaultProfile updated.\n");
  866. // Required item
  867. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  868. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  869. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  870. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  871. 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++)
  872. {
  873. 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"));
  874. 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")));
  875. 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?
  876. 3:
  877. 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")));
  878. }
  879. // Optional item
  880. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  881. {
  882. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  883. }
  884. else
  885. {
  886. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  887. }
  888. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  889. {
  890. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  891. }
  892. else
  893. {
  894. sprintf((char*)defaultTxProfile.ValidTo, " ");
  895. }
  896. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  897. {
  898. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  899. }
  900. else
  901. {
  902. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  903. }
  904. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  905. {
  906. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  907. }
  908. else
  909. {
  910. defaultTxProfile.TransactionId = -1;
  911. }
  912. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  913. {
  914. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  915. }
  916. else
  917. {
  918. defaultTxProfile.ChargingSchedule.Duration = 86400;
  919. }
  920. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  921. {
  922. 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")));
  923. }
  924. else
  925. {
  926. 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));
  927. }
  928. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  929. {
  930. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  931. }
  932. else
  933. {
  934. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  935. }
  936. }
  937. }
  938. }
  939. json_object_put(obj);
  940. }
  941. fclose(fp);
  942. /*
  943. if(defaultTxProfile.ChargingProfileId != -1)
  944. {
  945. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  946. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  947. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  948. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  949. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  950. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  951. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  952. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  953. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  954. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  955. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  956. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  957. {
  958. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  959. {
  960. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  961. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  962. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  963. }
  964. }
  965. }
  966. else
  967. DEBUG_INFO("TxDefaultProfile not found.\n");
  968. DEBUG_INFO("------------------------------------\n");*/
  969. }
  970. // Search max profile
  971. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  972. if((access(profileFileName, F_OK))!=-1)
  973. {
  974. fp = fopen(profileFileName, "r");
  975. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  976. {
  977. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  978. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  979. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  980. }
  981. maxProfile.ChargingProfileId = -1;
  982. maxProfile.StackLevel = -1;
  983. while(getline(&line, &len, fp) != -1)
  984. {
  985. json_object *obj = NULL;
  986. obj = json_tokener_parse(line);
  987. if(is_error(obj))
  988. {
  989. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  990. }
  991. else
  992. {
  993. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  994. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  995. )
  996. {
  997. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  998. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  999. )
  1000. {
  1001. struct tm tmFrom, tmTo;
  1002. struct timeb tbFrom, tbTo;
  1003. 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) &&
  1004. (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))
  1005. {
  1006. tmFrom.tm_year -= 1900;
  1007. tmFrom.tm_mon -= 1;
  1008. tbFrom.time = mktime(&tmFrom);
  1009. tmTo.tm_year -= 1900;
  1010. tmTo.tm_mon -= 1;
  1011. tbTo.time = mktime(&tmTo);
  1012. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1013. {
  1014. if(maxProfile.ChargingProfileId == -1)
  1015. DEBUG_INFO("MaxProfile found.\n");
  1016. else
  1017. DEBUG_INFO("MaxProfile updated.\n");
  1018. // Required item
  1019. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1020. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1021. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1022. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1023. 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++)
  1024. {
  1025. 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"));
  1026. 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")));
  1027. 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?
  1028. 3:
  1029. 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")));
  1030. }
  1031. // Optional item
  1032. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1033. {
  1034. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1035. }
  1036. else
  1037. {
  1038. sprintf((char*)maxProfile.ValidFrom, " ");
  1039. }
  1040. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1041. {
  1042. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1043. }
  1044. else
  1045. {
  1046. sprintf((char*)maxProfile.ValidTo, " ");
  1047. }
  1048. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1049. {
  1050. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1051. }
  1052. else
  1053. {
  1054. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1055. }
  1056. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1057. {
  1058. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1059. }
  1060. else
  1061. {
  1062. maxProfile.TransactionId = -1;
  1063. }
  1064. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1065. {
  1066. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1067. }
  1068. else
  1069. {
  1070. maxProfile.ChargingSchedule.Duration = 86400;
  1071. }
  1072. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1073. {
  1074. 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")));
  1075. }
  1076. else
  1077. {
  1078. 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));
  1079. }
  1080. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1081. {
  1082. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1083. }
  1084. else
  1085. {
  1086. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1087. }
  1088. }
  1089. }
  1090. }
  1091. else
  1092. {
  1093. if(maxProfile.ChargingProfileId == -1)
  1094. DEBUG_INFO("MaxProfile found.\n");
  1095. else
  1096. DEBUG_INFO("MaxProfile updated.\n");
  1097. // Required item
  1098. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1099. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1100. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1101. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1102. 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++)
  1103. {
  1104. 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"));
  1105. 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")));
  1106. 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?
  1107. 3:
  1108. 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")));
  1109. }
  1110. // Optional item
  1111. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1112. {
  1113. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1114. }
  1115. else
  1116. {
  1117. sprintf((char*)maxProfile.ValidFrom, " ");
  1118. }
  1119. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1120. {
  1121. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1122. }
  1123. else
  1124. {
  1125. sprintf((char*)maxProfile.ValidTo, " ");
  1126. }
  1127. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1128. {
  1129. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1130. }
  1131. else
  1132. {
  1133. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1134. }
  1135. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1136. {
  1137. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1138. }
  1139. else
  1140. {
  1141. maxProfile.TransactionId = -1;
  1142. }
  1143. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1144. {
  1145. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1146. }
  1147. else
  1148. {
  1149. maxProfile.ChargingSchedule.Duration = 86400;
  1150. }
  1151. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1152. {
  1153. 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")));
  1154. }
  1155. else
  1156. {
  1157. 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));
  1158. }
  1159. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1160. {
  1161. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1162. }
  1163. else
  1164. {
  1165. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1166. }
  1167. }
  1168. }
  1169. }
  1170. json_object_put(obj);
  1171. }
  1172. fclose(fp);
  1173. /*
  1174. if(maxProfile.ChargingProfileId !=-1)
  1175. {
  1176. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1177. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1178. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1179. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1180. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1181. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1182. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1183. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1184. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1185. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1186. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1187. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1188. {
  1189. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1190. {
  1191. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1192. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1193. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1194. }
  1195. }
  1196. }
  1197. else
  1198. DEBUG_INFO("MaxProfile not found.\n");
  1199. DEBUG_INFO("------------------------------------\n");*/
  1200. }
  1201. /*
  1202. * Align found profile start schedule & periods
  1203. */
  1204. //DEBUG_INFO("====================================\n");
  1205. /*
  1206. // For local test usage, force modify found profile start schedule info
  1207. 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);
  1208. 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);
  1209. 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);
  1210. */
  1211. if(txProfile.ChargingProfileId != -1)
  1212. {
  1213. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1214. {
  1215. if(txProfile.ChargingSchedule.Duration != -1)
  1216. {
  1217. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1218. 0:
  1219. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1220. }
  1221. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1222. {
  1223. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1224. {
  1225. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1226. 0:
  1227. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1228. if(idxPeriod > 0)
  1229. {
  1230. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1231. {
  1232. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1233. }
  1234. }
  1235. }
  1236. }
  1237. }
  1238. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1239. {
  1240. if(txProfile.ChargingSchedule.Duration != -1)
  1241. {
  1242. 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?
  1243. 0:
  1244. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1245. }
  1246. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1247. {
  1248. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1249. {
  1250. 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?
  1251. 0:
  1252. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1253. if(idxPeriod > 0)
  1254. {
  1255. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1256. {
  1257. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1258. }
  1259. }
  1260. }
  1261. }
  1262. }
  1263. else
  1264. {
  1265. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1266. {
  1267. if(txProfile.ChargingSchedule.Duration != -1)
  1268. {
  1269. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1270. 0:
  1271. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1272. }
  1273. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1274. {
  1275. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1276. {
  1277. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1278. 0:
  1279. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1280. if(idxPeriod > 0)
  1281. {
  1282. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1283. {
  1284. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1285. }
  1286. }
  1287. }
  1288. }
  1289. }
  1290. else
  1291. {
  1292. if(txProfile.ChargingSchedule.Duration != -1)
  1293. {
  1294. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1295. 0:
  1296. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1297. }
  1298. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1299. {
  1300. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1301. {
  1302. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1303. 0:
  1304. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1305. if(idxPeriod > 0)
  1306. {
  1307. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1308. {
  1309. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1310. }
  1311. }
  1312. }
  1313. }
  1314. }
  1315. }
  1316. /*
  1317. DEBUG_INFO("txProfile after align.\n");
  1318. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1319. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1320. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1321. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1322. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1323. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1324. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1325. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1326. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1327. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1328. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1329. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1330. {
  1331. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1332. {
  1333. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1334. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1335. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1336. }
  1337. }*/
  1338. }
  1339. if(defaultTxProfile.ChargingProfileId != -1)
  1340. {
  1341. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1342. {
  1343. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1344. {
  1345. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1346. 0:
  1347. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1348. }
  1349. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1350. {
  1351. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1352. {
  1353. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1354. 0:
  1355. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1356. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1357. {
  1358. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1359. }
  1360. if(idxPeriod > 0)
  1361. {
  1362. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1363. {
  1364. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1365. }
  1366. }
  1367. }
  1368. }
  1369. }
  1370. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1371. {
  1372. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1373. {
  1374. 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?
  1375. 0:
  1376. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1377. }
  1378. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1379. {
  1380. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1381. {
  1382. 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?
  1383. 0:
  1384. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1385. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1386. {
  1387. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1388. }
  1389. if(idxPeriod > 0)
  1390. {
  1391. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1392. {
  1393. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1394. }
  1395. }
  1396. }
  1397. }
  1398. }
  1399. else
  1400. {
  1401. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1402. {
  1403. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1404. {
  1405. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1406. 0:
  1407. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1408. }
  1409. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1410. {
  1411. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1412. {
  1413. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1414. 0:
  1415. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1416. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1417. {
  1418. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1419. }
  1420. if(idxPeriod > 0)
  1421. {
  1422. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1423. {
  1424. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1425. }
  1426. }
  1427. }
  1428. }
  1429. }
  1430. else
  1431. {
  1432. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1433. {
  1434. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1435. 0:
  1436. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1437. }
  1438. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1439. {
  1440. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1441. {
  1442. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1443. 0:
  1444. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1445. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1446. {
  1447. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1448. }
  1449. if(idxPeriod > 0)
  1450. {
  1451. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1452. {
  1453. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1454. }
  1455. }
  1456. }
  1457. }
  1458. }
  1459. }
  1460. /*
  1461. DEBUG_INFO("defaultTxProfile after align.\n");
  1462. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1463. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1464. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1465. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1466. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1467. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1468. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1469. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1470. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1471. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1472. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1473. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1474. {
  1475. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1476. {
  1477. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1478. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1479. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1480. }
  1481. }
  1482. DEBUG_INFO("------------------------------------\n");*/
  1483. }
  1484. if(maxProfile.ChargingProfileId != -1)
  1485. {
  1486. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1487. {
  1488. if(maxProfile.ChargingSchedule.Duration != -1)
  1489. {
  1490. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1491. 0:
  1492. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1493. }
  1494. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1495. {
  1496. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1497. {
  1498. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1499. 0:
  1500. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1501. if(idxPeriod > 0)
  1502. {
  1503. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1504. {
  1505. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1506. }
  1507. }
  1508. }
  1509. }
  1510. }
  1511. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1512. {
  1513. if(maxProfile.ChargingSchedule.Duration != -1)
  1514. {
  1515. 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?
  1516. 0:
  1517. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1518. }
  1519. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1520. {
  1521. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1522. {
  1523. 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?
  1524. 0:
  1525. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1526. if(idxPeriod > 0)
  1527. {
  1528. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1529. {
  1530. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1531. }
  1532. }
  1533. }
  1534. }
  1535. }
  1536. else
  1537. {
  1538. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1539. {
  1540. if(maxProfile.ChargingSchedule.Duration != -1)
  1541. {
  1542. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1543. 0:
  1544. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1545. }
  1546. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1547. {
  1548. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1549. {
  1550. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1551. 0:
  1552. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1553. if(idxPeriod > 0)
  1554. {
  1555. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1556. {
  1557. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1558. }
  1559. }
  1560. }
  1561. }
  1562. }
  1563. else
  1564. {
  1565. if(maxProfile.ChargingSchedule.Duration != -1)
  1566. {
  1567. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1568. 0:
  1569. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1570. }
  1571. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1572. {
  1573. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1574. {
  1575. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1576. 0:
  1577. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1578. if(idxPeriod > 0)
  1579. {
  1580. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1581. {
  1582. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1583. }
  1584. }
  1585. }
  1586. }
  1587. }
  1588. }
  1589. /*
  1590. DEBUG_INFO("MaxProfile after align.\n");
  1591. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1592. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1593. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1594. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1595. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1596. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1597. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1598. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1599. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1600. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1601. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1602. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1603. {
  1604. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1605. {
  1606. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1607. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1608. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1609. }
  1610. }
  1611. DEBUG_INFO("------------------------------------\n");*/
  1612. }
  1613. /*
  1614. * Merge to conposite schedule
  1615. */
  1616. //DEBUG_INFO("====================================\n");
  1617. // Find each profile period quantity
  1618. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1619. {
  1620. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1621. limitMax = idx+1;
  1622. }
  1623. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1624. {
  1625. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1626. limitDef = idx+1;
  1627. }
  1628. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1629. {
  1630. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1631. limitTx = idx+1;
  1632. }
  1633. // TxProfile found, composite schedule based on it
  1634. if(txProfile.ChargingProfileId != -1)
  1635. {
  1636. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1637. {
  1638. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1639. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  1640. (txProfile.ChargingSchedule.Duration > 0))
  1641. {
  1642. if(maxProfile.ChargingProfileId != -1)
  1643. {
  1644. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1645. {
  1646. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  1647. {
  1648. if((maxProfile.ChargingSchedule.Duration > 0))
  1649. {
  1650. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1651. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1652. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1653. }
  1654. else
  1655. {
  1656. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1657. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1658. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  1659. }
  1660. }
  1661. if(idxMaxPeriod == (limitMax-1))
  1662. {
  1663. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1664. {
  1665. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1666. {
  1667. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1668. compositePeriodIdx++;
  1669. }
  1670. else
  1671. {
  1672. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1673. }
  1674. }
  1675. }
  1676. }
  1677. }
  1678. else
  1679. {
  1680. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1681. {
  1682. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1683. compositePeriodIdx++;
  1684. }
  1685. else
  1686. {
  1687. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1688. }
  1689. }
  1690. }
  1691. if(idxTxPeriod == (limitTx-1))
  1692. {
  1693. if(defaultTxProfile.ChargingProfileId != -1)
  1694. {
  1695. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1696. {
  1697. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  1698. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1699. (defaultTxProfile.ChargingSchedule.Duration>0))
  1700. {
  1701. if(maxProfile.ChargingProfileId != -1)
  1702. {
  1703. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1704. {
  1705. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1706. {
  1707. if((maxProfile.ChargingSchedule.Duration > 0))
  1708. {
  1709. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1710. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1711. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1712. }
  1713. else
  1714. {
  1715. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1716. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1717. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1718. }
  1719. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1720. {
  1721. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1722. {
  1723. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1724. compositePeriodIdx++;
  1725. }
  1726. else
  1727. {
  1728. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1729. }
  1730. }
  1731. break;
  1732. }
  1733. }
  1734. }
  1735. else
  1736. {
  1737. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1738. {
  1739. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1740. compositePeriodIdx++;
  1741. }
  1742. else
  1743. {
  1744. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1745. }
  1746. }
  1747. }
  1748. }
  1749. }
  1750. }
  1751. }
  1752. }
  1753. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1754. else if(defaultTxProfile.ChargingProfileId != -1)
  1755. {
  1756. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1757. {
  1758. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1759. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1760. (defaultTxProfile.ChargingSchedule.Duration > 0))
  1761. {
  1762. if(maxProfile.ChargingProfileId != -1)
  1763. {
  1764. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1765. {
  1766. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1767. {
  1768. if((maxProfile.ChargingSchedule.Duration > 0))
  1769. {
  1770. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1771. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1772. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1773. }
  1774. else
  1775. {
  1776. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1777. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1778. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1779. }
  1780. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1781. {
  1782. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1783. {
  1784. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1785. compositePeriodIdx++;
  1786. }
  1787. else
  1788. {
  1789. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1790. }
  1791. }
  1792. break;
  1793. }
  1794. }
  1795. }
  1796. else
  1797. {
  1798. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1799. {
  1800. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1801. compositePeriodIdx++;
  1802. }
  1803. else
  1804. {
  1805. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1806. }
  1807. }
  1808. }
  1809. }
  1810. }
  1811. // Fill other period by MaxProfile
  1812. if(maxProfile.ChargingProfileId != -1)
  1813. {
  1814. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1815. {
  1816. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1817. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1818. (maxProfile.ChargingSchedule.Duration > 0))
  1819. {
  1820. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  1821. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1822. {
  1823. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  1824. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  1825. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1826. }
  1827. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1828. {
  1829. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  1830. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  1831. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1832. }
  1833. if(tmpPeriod.Limit != -1)
  1834. {
  1835. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1836. {
  1837. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1838. {
  1839. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1840. compositePeriodIdx++;
  1841. }
  1842. else
  1843. {
  1844. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1845. }
  1846. }
  1847. }
  1848. }
  1849. }
  1850. }
  1851. DEBUG_INFO("Composite schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1852. DEBUG_INFO("Composite schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1853. DEBUG_INFO("Composite rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1854. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1855. {
  1856. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1857. {
  1858. compositeProfile->ChargingProfileId = 1;
  1859. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1860. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1861. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1862. }
  1863. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1864. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1865. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1866. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1867. }
  1868. if(line)
  1869. free(line);
  1870. }
  1871. //==========================================
  1872. // Init all share memory
  1873. //==========================================
  1874. int InitShareMemory()
  1875. {
  1876. int result = PASS;
  1877. int MeterSMId;
  1878. //creat ShmSysConfigAndInfo
  1879. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1880. {
  1881. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1882. result = FAIL;
  1883. }
  1884. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1885. {
  1886. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  1887. result = FAIL;
  1888. }
  1889. else
  1890. {}
  1891. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1892. {
  1893. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1894. result = FAIL;
  1895. }
  1896. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1897. {
  1898. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1899. result = FAIL;
  1900. }
  1901. else
  1902. {}
  1903. //creat ShmPsuData
  1904. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  1905. {
  1906. DEBUG_ERROR("shmget ShmPsuData NG\n");
  1907. result = FAIL;
  1908. }
  1909. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1910. {
  1911. DEBUG_ERROR("shmat ShmPsuData NG\n");
  1912. result = FAIL;
  1913. }
  1914. else
  1915. {}
  1916. //creat ShmOCPP16Data
  1917. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1918. {
  1919. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  1920. result = FAIL;
  1921. }
  1922. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1923. {
  1924. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  1925. result = FAIL;
  1926. }
  1927. else
  1928. {}
  1929. /****************************** For Initial Settings************************************************/
  1930. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  1931. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  1932. // allocate Configuration memory address
  1933. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  1934. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  1935. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  1936. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  1937. //offline MeterValue Interval
  1938. TempMeterValueInterval = 0;
  1939. return result;
  1940. }
  1941. int ProcessShareMemory()
  1942. {
  1943. if(InitShareMemory() == FAIL)
  1944. {
  1945. DEBUG_ERROR("InitShareMemory NG\n");
  1946. if(ShmStatusCodeData!=NULL)
  1947. {
  1948. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1949. }
  1950. sleep(5);
  1951. return FAIL;
  1952. }
  1953. return PASS;
  1954. }
  1955. //---------------------common routine---------------------------//
  1956. int isOFFline(void)
  1957. {
  1958. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  1959. {
  1960. if(TempMeterValueInterval >= 2 )
  1961. {
  1962. TempMeterValueInterval = 0;
  1963. return TRUE;
  1964. }
  1965. else
  1966. {
  1967. TempMeterValueInterval = TempMeterValueInterval+ 1;
  1968. return FALSE;
  1969. }
  1970. }
  1971. else
  1972. {
  1973. return FALSE;
  1974. }
  1975. }
  1976. //---------------------------------------------
  1977. // new:
  1978. // enum SYSTEM_STATUS
  1979. // {
  1980. // SYS_MODE_BOOTING = 0,
  1981. // SYS_MODE_IDLE = 1,
  1982. // SYS_MODE_AUTHORIZING = 2,
  1983. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  1984. // SYS_MODE_REASSIGN = 4,
  1985. // SYS_MODE_PREPARING = 5,
  1986. // SYS_MODE_PREPARE_FOR_EV = 6,
  1987. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  1988. // SYS_MODE_CHARGING = 8,
  1989. // SYS_MODE_TERMINATING = 9,
  1990. // SYS_MODE_COMPLETE = 10,
  1991. // SYS_MODE_ALARM = 11,
  1992. // SYS_MODE_FAULT = 12,
  1993. // SYS_MODE_RESERVATION = 13,
  1994. // SYS_MODE_BOOKING = 14,
  1995. // SYS_MODE_MAINTAIN = 15,
  1996. // SYS_MODE_DEBUG = 16,
  1997. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  1998. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  1999. // SYS_MODE_UPDATE = 19
  2000. // };
  2001. //
  2002. //
  2003. //-----------------------------------------
  2004. void CheckSystemValue(void)
  2005. {
  2006. uint8_t reqSampleMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2007. uint8_t reqClockAlignMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2008. char filenmae[100]={0};
  2009. char str[100]={0};
  2010. int tempIndex = 0;
  2011. //===============================
  2012. // send Heartbeat
  2013. //===============================
  2014. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2015. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2016. {
  2017. clientTime.Heartbeat=time((time_t*)NULL);
  2018. if(server_sign == TRUE)
  2019. {
  2020. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2021. }
  2022. else
  2023. {
  2024. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2025. }
  2026. }
  2027. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  2028. {
  2029. //parameter for test
  2030. sendHeartbeatRequest(0);
  2031. //==============================================
  2032. // Reset Waiting Time
  2033. //==============================================
  2034. clientTime.Heartbeat=time((time_t*)NULL);
  2035. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  2036. }
  2037. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2038. {
  2039. //===============================
  2040. // CSU Trigger Reset Conf
  2041. //===============================
  2042. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2043. {
  2044. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2045. }
  2046. //===============================
  2047. // CSU Trigger Authorize Request
  2048. //===============================
  2049. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2050. {
  2051. sendAuthorizeRequest(0);
  2052. authorizeRetryTimes = authorizeRetryTimes + 1;
  2053. if(authorizeRetryTimes < 3)
  2054. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2055. }
  2056. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2057. {
  2058. authorizeRetryTimes = 0;
  2059. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  2060. server_sign = FALSE;
  2061. }
  2062. 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))
  2063. {
  2064. sendAuthorizeRequest(0);
  2065. }
  2066. //===============================
  2067. // CSU Trigger Smart Charging Profilw
  2068. //===============================
  2069. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2070. {
  2071. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  2072. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2073. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  2074. }
  2075. //==============================================
  2076. // Charger start transaction
  2077. //==============================================
  2078. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2079. {
  2080. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  2081. sendStartTransactionRequest(gun_index);
  2082. clientTime.StartTransaction = time((time_t*)NULL);
  2083. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2084. }
  2085. //==============================================
  2086. // Charger stop transaction
  2087. //==============================================
  2088. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2089. {
  2090. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  2091. sendStopTransactionRequest(gun_index);
  2092. clientTime.StopTransaction = time((time_t*)NULL);
  2093. }
  2094. //==============================================
  2095. // Charger status report
  2096. //==============================================
  2097. //--- Check Mode Change ---//
  2098. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2099. if(gunType[gun_index] == 'J')
  2100. {
  2101. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2102. {
  2103. tempIndex = ((gun_index==2) ? 1: 0);
  2104. }
  2105. else
  2106. {
  2107. tempIndex = gun_index;
  2108. }
  2109. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2110. {
  2111. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2112. {
  2113. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2114. {
  2115. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2116. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2117. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2118. statusModeChage[gun_index] = TRUE;
  2119. }
  2120. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2121. {
  2122. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2123. if((access(filenmae,F_OK))!=-1)
  2124. {
  2125. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2126. sprintf(str,"rm -f %s",filenmae);
  2127. system(str);
  2128. }
  2129. }
  2130. #if 1 // for TempStopTransaction
  2131. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2132. {
  2133. checkTempStopTransaction(gun_index);
  2134. }
  2135. #endif
  2136. }
  2137. }
  2138. }
  2139. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2140. {
  2141. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2142. {
  2143. tempIndex = ((gun_index==2) ? 1: 0);
  2144. }
  2145. else
  2146. {
  2147. tempIndex = gun_index;
  2148. }
  2149. for (int index = 0; index < CCS_QUANTITY; index++)
  2150. {
  2151. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2152. {
  2153. 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]*/ )
  2154. {
  2155. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2156. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2157. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2158. statusModeChage[gun_index] = TRUE;
  2159. }
  2160. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2161. {
  2162. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2163. if((access(filenmae,F_OK))!=-1)
  2164. {
  2165. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2166. sprintf(str,"rm -f %s",filenmae);
  2167. system(str);
  2168. }
  2169. }
  2170. #if 1 // for TempStopTransaction
  2171. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2172. {
  2173. checkTempStopTransaction(gun_index);
  2174. }
  2175. #endif
  2176. }
  2177. }
  2178. }
  2179. else if(gunType[gun_index] == 'G')
  2180. {
  2181. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2182. {
  2183. tempIndex = ((gun_index==2) ? 1: 0);
  2184. }
  2185. else
  2186. {
  2187. tempIndex = gun_index;
  2188. }
  2189. for (int index = 0; index < GB_QUANTITY; index++)
  2190. {
  2191. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2192. {
  2193. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2194. {
  2195. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2196. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2197. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2198. statusModeChage[gun_index] = TRUE;
  2199. }
  2200. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2201. {
  2202. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2203. if((access(filenmae,F_OK))!=-1)
  2204. {
  2205. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2206. sprintf(str,"rm -f %s",filenmae);
  2207. system(str);
  2208. }
  2209. }
  2210. #if 1 // for TempStopTransaction
  2211. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2212. {
  2213. checkTempStopTransaction(gun_index);
  2214. }
  2215. #endif
  2216. }
  2217. }
  2218. }
  2219. else
  2220. {
  2221. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2222. {
  2223. tempIndex = 2;
  2224. }
  2225. else
  2226. {
  2227. tempIndex = gun_index;
  2228. }
  2229. for (int index = 0; index < AC_QUANTITY; index++)
  2230. {
  2231. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2232. {
  2233. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2234. {
  2235. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2236. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2237. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2238. statusModeChage[gun_index] = TRUE;
  2239. }
  2240. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2241. {
  2242. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2243. if((access(filenmae,F_OK))!=-1)
  2244. {
  2245. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2246. sprintf(str,"rm -f %s",filenmae);
  2247. system(str);
  2248. }
  2249. }
  2250. #if 1 // for TempStopTransaction
  2251. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2252. {
  2253. checkTempStopTransaction(gun_index);
  2254. }
  2255. #endif
  2256. }
  2257. }// END
  2258. }
  2259. if(isWebsocketSendable &&
  2260. (((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)))) )
  2261. {
  2262. if(SystemInitial > 0)
  2263. SystemInitial -= 1;
  2264. sendStatusNotificationRequest(gun_index);
  2265. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2266. statusModeChage[gun_index] = FALSE;
  2267. }
  2268. //==============================================
  2269. // Meter report
  2270. //==============================================
  2271. if(cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2272. {
  2273. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2274. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2275. }
  2276. if(/*(server_sign == TRUE) &&(isOFFline() == TRUE) ||*/
  2277. (((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)))
  2278. {
  2279. //check Transaction active
  2280. if(gunType[gun_index] == 'J')
  2281. {
  2282. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2283. {
  2284. tempIndex = ((gun_index==2) ? 1: 0);
  2285. }
  2286. else
  2287. {
  2288. tempIndex = gun_index;
  2289. }
  2290. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2291. {
  2292. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2293. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2294. {
  2295. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2296. {
  2297. reqSampleMeter[gun_index] = 1;
  2298. }
  2299. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2300. {
  2301. reqClockAlignMeter[gun_index] = 1;
  2302. }
  2303. }
  2304. }// End for CHAdeMO
  2305. }
  2306. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2307. {
  2308. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2309. {
  2310. tempIndex = ((gun_index==2) ? 1: 0);
  2311. }
  2312. else
  2313. {
  2314. tempIndex = gun_index;
  2315. }
  2316. for (int index = 0; index < CCS_QUANTITY; index++)
  2317. {
  2318. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2319. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2320. {
  2321. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2322. {
  2323. reqSampleMeter[gun_index] = 1;
  2324. }
  2325. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2326. {
  2327. reqClockAlignMeter[gun_index] = 1;
  2328. }
  2329. }
  2330. } // End for CCS
  2331. }
  2332. else if(gunType[gun_index] == 'G')
  2333. {
  2334. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2335. {
  2336. tempIndex = ((gun_index==2) ? 1: 0);
  2337. }
  2338. else
  2339. {
  2340. tempIndex = gun_index;
  2341. }
  2342. for (int index = 0; index < GB_QUANTITY; index++)
  2343. {
  2344. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2345. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2346. {
  2347. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2348. {
  2349. reqSampleMeter[gun_index] = 1;
  2350. }
  2351. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2352. {
  2353. reqClockAlignMeter[gun_index] = 1;
  2354. }
  2355. }
  2356. }// End for GB
  2357. }
  2358. else
  2359. {
  2360. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2361. {
  2362. tempIndex = 2;
  2363. }
  2364. else
  2365. {
  2366. tempIndex = gun_index;
  2367. }
  2368. for (int index = 0; index < AC_QUANTITY; index++)
  2369. {
  2370. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2371. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2372. {
  2373. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2374. {
  2375. reqSampleMeter[gun_index] = 1;
  2376. }
  2377. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2378. {
  2379. reqClockAlignMeter[gun_index] = 1;
  2380. }
  2381. }
  2382. }//End for AC
  2383. }
  2384. if(reqSampleMeter[gun_index] == 1)
  2385. {
  2386. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2387. storeTempStopTransaction(gun_index);
  2388. }
  2389. else if(reqClockAlignMeter[gun_index] == 1)
  2390. {
  2391. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2392. }
  2393. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2394. sleep(1);
  2395. }
  2396. //==============================================
  2397. // Check Connector reserved
  2398. //==============================================
  2399. //===============================
  2400. // Check if Reserve is expired
  2401. //===============================
  2402. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2403. {
  2404. double diff_t;
  2405. struct tm tp;
  2406. // current time
  2407. time_t t = time(NULL);
  2408. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2409. tp.tm_isdst = -1;
  2410. time_t utc = mktime(&tp);
  2411. diff_t = difftime(utc, t);
  2412. if(diff_t <= 0)
  2413. {
  2414. DEBUG_INFO("reserve expired.\n");
  2415. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2416. }
  2417. }//END OF Check if Reserve is expired
  2418. //==========================================
  2419. // csu trigger FirmwareStatusNotificationReq
  2420. //==========================================
  2421. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2422. {
  2423. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2424. }
  2425. //==========================================
  2426. // csu trigger CancelReservationConf
  2427. //==========================================
  2428. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2429. {
  2430. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2431. }
  2432. //==========================================
  2433. // csu trigger ChangeAvailabilityConf
  2434. //==========================================
  2435. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2436. {
  2437. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2438. }
  2439. //==========================================
  2440. // csu trigger UnlockConnectorConf
  2441. //==========================================
  2442. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2443. {
  2444. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2445. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2446. }
  2447. //==========================================
  2448. // csu trigger ReserveNowConf
  2449. //==========================================
  2450. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2451. {
  2452. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2453. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2454. }
  2455. //==========================================
  2456. // csu trigger DataTransferReq
  2457. //==========================================
  2458. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2459. {
  2460. sendDataTransferRequest(gun_index);
  2461. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2462. }
  2463. }
  2464. }
  2465. //==========================================
  2466. // send request routine
  2467. //==========================================
  2468. int sendAuthorizeRequest(int gun_index)
  2469. {
  2470. mtrace();
  2471. int result = FAIL;
  2472. char message[100]={0};
  2473. char guid[37];
  2474. char tempdata[65]={0};
  2475. DEBUG_INFO("sendAuthorizeRequest...\n");
  2476. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2477. //Local Authorize
  2478. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2479. {
  2480. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2481. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2482. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2483. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2484. result = PASS;
  2485. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2486. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2487. authorizeRetryTimes = 0;
  2488. return result;
  2489. }
  2490. 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))||
  2491. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2492. {
  2493. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2494. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2495. {
  2496. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2497. {
  2498. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2499. }
  2500. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2501. {
  2502. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2503. }
  2504. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  2505. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2506. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2507. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2508. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2509. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2510. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2511. authorizeRetryTimes = 0;
  2512. return result;
  2513. }
  2514. else
  2515. {
  2516. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  2517. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2518. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2519. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2520. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2521. result = PASS;
  2522. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2523. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2524. authorizeRetryTimes = 0;
  2525. return result;
  2526. }
  2527. }
  2528. //initailize struct Authorize
  2529. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2530. //get data from shared memory
  2531. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2532. random_uuid(guid);
  2533. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2534. LWS_Send(message);
  2535. sprintf(tempdata, "Authorize,%d", gun_index);
  2536. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2537. {
  2538. result = PASS;
  2539. DEBUG_INFO("Authorize mapItem pass\n");
  2540. }
  2541. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2542. return result;
  2543. }
  2544. int sendBootNotificationRequest(void)
  2545. {
  2546. mtrace();
  2547. int result = FAIL;
  2548. char message[500]={0}, payload[700]={0};
  2549. char guid[37]={0};
  2550. char tempdata[65]={0};
  2551. /*
  2552. int IsGunCharging = FALSE;
  2553. //check Transaction active
  2554. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2555. {
  2556. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2557. {
  2558. IsGunCharging = TRUE;
  2559. }
  2560. }
  2561. for (int index = 0; index < CCS_QUANTITY; index++)
  2562. {
  2563. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2564. {
  2565. IsGunCharging = TRUE;
  2566. }
  2567. }
  2568. for (int index = 0; index < GB_QUANTITY; index++)
  2569. {
  2570. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2571. {
  2572. IsGunCharging = TRUE;
  2573. }
  2574. }
  2575. for (int index = 0; index < AC_QUANTITY; index++)
  2576. {
  2577. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2578. {
  2579. IsGunCharging = TRUE;
  2580. }
  2581. }
  2582. if(IsGunCharging == TRUE)
  2583. {
  2584. server_sign = TRUE;
  2585. return result;
  2586. }
  2587. */
  2588. // Fill BootNotification fields
  2589. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2590. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2591. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2592. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2593. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2594. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2595. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2596. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2597. ShmOCPP16Data->ChargeBoxId
  2598. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2599. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2600. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2601. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2602. ,ShmOCPP16Data->BootNotification.CpIccid
  2603. ,ShmOCPP16Data->BootNotification.CpImsi);
  2604. random_uuid(guid);
  2605. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2606. LWS_Send(message);
  2607. sprintf(tempdata, "BootNotification,0");
  2608. 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*/)
  2609. {
  2610. result = PASS;
  2611. }
  2612. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2613. strcpy(queuedata,message);
  2614. return result;
  2615. }
  2616. int sendDataTransferRequest(int gun_index)
  2617. {
  2618. mtrace();
  2619. char message[1000]={0};
  2620. char guid[37]={0};
  2621. char tempdata[65]={0};
  2622. int result = FAIL;
  2623. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2624. random_uuid(guid);
  2625. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2626. MESSAGE_TYPE_CALL,
  2627. guid,
  2628. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2629. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2630. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2631. LWS_Send(message);
  2632. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2633. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2634. {
  2635. result = PASS;
  2636. DEBUG_INFO("DataTransfer mapItem pass\n");
  2637. }
  2638. return result;
  2639. }
  2640. int sendDiagnosticsStatusNotificationRequest(char *status)
  2641. {
  2642. mtrace();
  2643. int result = FAIL;
  2644. char message[110]={0};
  2645. char guid[37]={0};
  2646. char tempdata[65]={0};
  2647. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2648. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2649. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2650. random_uuid(guid);
  2651. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2652. LWS_Send(message);
  2653. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2654. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2655. {
  2656. result = PASS;
  2657. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2658. }
  2659. //#ifdef SystemLogMessage
  2660. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2661. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2662. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2663. //#endif
  2664. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2665. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2666. //record status
  2667. if(strcmp(status,"Idle")==0)
  2668. {
  2669. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2670. }
  2671. else if(strcmp(status,"Uploaded")==0)
  2672. {
  2673. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2674. }
  2675. else if(strcmp(status,"UploadFailed")==0)
  2676. {
  2677. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2678. }
  2679. else if(strcmp(status,"Uploading")==0)
  2680. {
  2681. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2682. }
  2683. return result;
  2684. }
  2685. int sendFirmwareStatusNotificationRequest(char *status)
  2686. {
  2687. mtrace();
  2688. int result = FAIL;
  2689. char message[110]={0};
  2690. char guid[37]={0};
  2691. char tempdata[65]={0};
  2692. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2693. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2694. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2695. random_uuid(guid);
  2696. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2697. LWS_Send(message);
  2698. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2699. 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*/)
  2700. {
  2701. result = PASS;
  2702. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2703. }
  2704. //#ifdef SystemLogMessage
  2705. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2706. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2707. //#endif
  2708. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2709. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2710. //record status
  2711. if(strcmp(status,"Downloaded")==0)
  2712. {
  2713. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2714. }
  2715. else if(strcmp(status,"DownloadFailed")==0)
  2716. {
  2717. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  2718. }
  2719. else if(strcmp(status,"Downloading")==0)
  2720. {
  2721. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2722. }
  2723. else if(strcmp(status,"Idle")==0)
  2724. {
  2725. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2726. }
  2727. else if(strcmp(status,"InstallationFailed")==0)
  2728. {
  2729. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2730. }
  2731. else if(strcmp(status,"Installing")==0)
  2732. {
  2733. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2734. }
  2735. else if(strcmp(status,"Installed")==0)
  2736. {
  2737. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2738. }
  2739. return result;
  2740. }
  2741. int sendHeartbeatRequest(int gun_index)
  2742. {
  2743. mtrace();
  2744. int result = FAIL;
  2745. char message[80]={0};
  2746. char guid[37]={0};
  2747. char tempdata[65]={0};
  2748. random_uuid(guid);
  2749. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2750. , MESSAGE_TYPE_CALL
  2751. , guid );
  2752. LWS_Send(message);
  2753. sprintf(tempdata, "Heartbeat,%d", 0);
  2754. 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*/)
  2755. {
  2756. result = PASS;
  2757. }
  2758. return result;
  2759. }
  2760. int sendStartTransactionRequest(int gun_index)
  2761. {
  2762. mtrace();
  2763. int result = FAIL;
  2764. char message[250]={0};
  2765. char guid[37]={0};
  2766. struct timeval tmnow;
  2767. struct tm *tm;
  2768. char buf[28];//, usec_buf[6];
  2769. char tempdata[65]={0};
  2770. int tempIndex = 0;
  2771. DEBUG_INFO("sendStartTransactionRequest...\n");
  2772. gettimeofday(&tmnow, NULL);
  2773. time_t t;
  2774. t = time(NULL);
  2775. /*UTC time and date*/
  2776. tm = gmtime(&t);
  2777. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2778. #if 0 // remove temporally
  2779. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2780. strcat(buf,".");
  2781. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2782. strcat(buf,usec_buf);
  2783. #endif
  2784. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2785. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2786. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2787. // clear StartTransaction Response
  2788. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2789. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2790. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2791. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2792. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2793. if(gunType[gun_index] == 'J')
  2794. {
  2795. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2796. {
  2797. tempIndex = ((gun_index==2) ? 1: 0);
  2798. }
  2799. else
  2800. {
  2801. tempIndex = gun_index;
  2802. }
  2803. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2804. {
  2805. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2806. {
  2807. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  2808. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2809. }
  2810. }
  2811. }
  2812. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2813. {
  2814. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2815. {
  2816. tempIndex = ((gun_index==2) ? 1: 0);
  2817. }
  2818. else
  2819. {
  2820. tempIndex = gun_index;
  2821. }
  2822. for (int index = 0; index < CCS_QUANTITY; index++)
  2823. {
  2824. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2825. {
  2826. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  2827. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  2828. }
  2829. }
  2830. }
  2831. else if(gunType[gun_index] == 'G')
  2832. {
  2833. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2834. {
  2835. tempIndex = ((gun_index==2) ? 1: 0);
  2836. }
  2837. else
  2838. {
  2839. tempIndex = gun_index;
  2840. }
  2841. for (int index = 0; index < GB_QUANTITY; index++)
  2842. {
  2843. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2844. {
  2845. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  2846. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  2847. }
  2848. }
  2849. }
  2850. else
  2851. {
  2852. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2853. {
  2854. tempIndex = 2;
  2855. }
  2856. else
  2857. {
  2858. tempIndex = gun_index;
  2859. }
  2860. for (int index = 0; index < AC_QUANTITY; index++)
  2861. {
  2862. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2863. {
  2864. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  2865. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  2866. }
  2867. }
  2868. }
  2869. random_uuid(guid);
  2870. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  2871. {
  2872. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  2873. , gun_index +1
  2874. , MESSAGE_TYPE_CALL
  2875. , guid
  2876. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2877. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2878. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2879. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2880. }
  2881. else
  2882. {
  2883. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  2884. , gun_index +1
  2885. , MESSAGE_TYPE_CALL
  2886. , guid
  2887. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2888. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2889. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2890. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  2891. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2892. }
  2893. #if 1
  2894. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  2895. 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*/)
  2896. {
  2897. result = PASS;
  2898. }
  2899. #endif
  2900. strcpy(queuedata, message);
  2901. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2902. /*
  2903. if(GetTransactionQueueNum() == 1)
  2904. {
  2905. LWS_Send(message + 2);
  2906. }*/
  2907. return result;
  2908. }
  2909. int sendStatusNotificationRequest(int gun_index)
  2910. {
  2911. mtrace();
  2912. int result = FAIL;
  2913. char message[600]={0};
  2914. char guid[37];
  2915. int currentStatus = 0;
  2916. struct timeval tmnow;
  2917. struct tm *tm;
  2918. char buf[28];//, usec_buf[6];
  2919. char tempdata[65]={0};
  2920. int tempIndex = 0;
  2921. gettimeofday(&tmnow, NULL);
  2922. time_t t;
  2923. t = time(NULL);
  2924. /*UTC time and date*/
  2925. tm = gmtime(&t);
  2926. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2927. #if 0 // remove temporally
  2928. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2929. strcat(buf,".");
  2930. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2931. strcat(buf,usec_buf);
  2932. #endif
  2933. printf("%s",buf);
  2934. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  2935. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  2936. // it's option
  2937. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  2938. /*
  2939. enum _SYSTEM_STATUS
  2940. {
  2941. S_BOOTING = 0,
  2942. S_IDLE, = 1
  2943. S_AUTHORIZING, =2
  2944. S_REASSIGN_CHECK, =3
  2945. S_REASSIGN, =4
  2946. S_PRECHARGE, =5
  2947. S_PREPARING_FOR_EV, =6
  2948. S_PREPARING_FOR_EVSE, =7
  2949. S_CHARGING, =8
  2950. S_TERMINATING, =9
  2951. S_COMPLETE, =10
  2952. S_ALARM, =11
  2953. S_FAULT =12
  2954. }
  2955. */
  2956. //check Transaction active
  2957. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2958. if(gunType[gun_index] == 'J')
  2959. {
  2960. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2961. {
  2962. tempIndex = ((gun_index==2) ? 1: 0);
  2963. }
  2964. else
  2965. {
  2966. tempIndex = gun_index;
  2967. }
  2968. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2969. {
  2970. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  2971. {
  2972. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  2973. {
  2974. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  2975. {
  2976. currentStatus = 1; //OCPP Status: Preparing
  2977. }
  2978. else
  2979. {
  2980. currentStatus = 0; //OCPP Status: Available
  2981. }
  2982. }
  2983. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  2984. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  2985. ) //S_PRECHARGE
  2986. {
  2987. currentStatus = 1; //OCPP Status: Preparing
  2988. }
  2989. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2990. {
  2991. currentStatus = 2; //OCPP Status: Charging
  2992. }
  2993. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  2994. {
  2995. currentStatus = 5; //OCPP Status: Finishing
  2996. }
  2997. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  2998. {
  2999. currentStatus = 4; //OCPP Status: SuspendedEV
  3000. }
  3001. 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
  3002. {
  3003. currentStatus = 7; //OCPP Status: Unavailable
  3004. }
  3005. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3006. {
  3007. currentStatus = 8; //OCPP Status: Faulted
  3008. }
  3009. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3010. {
  3011. currentStatus = 6; //OCPP Status: Reserved
  3012. }
  3013. } //end of the same index
  3014. }//end of for CHAdeMO_QUANTITY
  3015. }
  3016. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3017. {
  3018. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3019. {
  3020. tempIndex = ((gun_index==2) ? 1: 0);
  3021. }
  3022. else
  3023. {
  3024. tempIndex = gun_index;
  3025. }
  3026. for (int index = 0; index < CCS_QUANTITY; index++)
  3027. {
  3028. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3029. {
  3030. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3031. {
  3032. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3033. {
  3034. currentStatus = 1; //OCPP Status: Preparing
  3035. }
  3036. else
  3037. {
  3038. currentStatus = 0; //OCPP Status: Available
  3039. }
  3040. }
  3041. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3042. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3043. ) //S_PRECHARGE
  3044. {
  3045. currentStatus = 1; //OCPP Status: Preparing
  3046. }
  3047. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3048. {
  3049. currentStatus = 2; //OCPP Status: Charging
  3050. }
  3051. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3052. {
  3053. currentStatus = 5; //OCPP Status: Finishing
  3054. }
  3055. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3056. {
  3057. currentStatus = 4; //OCPP Status: SuspendedEV
  3058. }
  3059. 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
  3060. {
  3061. currentStatus = 7; //OCPP Status : Unavailable
  3062. }
  3063. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3064. {
  3065. currentStatus = 8; //OCPP Status: Faulted
  3066. }
  3067. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3068. {
  3069. currentStatus = 6; //OCPP Status: Reserved
  3070. }
  3071. } //end of the same index
  3072. } // end of for CCS_QUANTITY
  3073. }
  3074. else if(gunType[gun_index] == 'G')
  3075. {
  3076. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3077. {
  3078. tempIndex = ((gun_index==2) ? 1: 0);
  3079. }
  3080. else
  3081. {
  3082. tempIndex = gun_index;
  3083. }
  3084. for (int index = 0; index < GB_QUANTITY; index++)
  3085. {
  3086. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3087. {
  3088. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3089. {
  3090. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3091. {
  3092. currentStatus = 1; //OCPP Status: Preparing
  3093. }
  3094. else
  3095. {
  3096. currentStatus = 0; //OCPP Status: Available
  3097. }
  3098. }
  3099. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3100. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3101. ) //S_PRECHARGE
  3102. {
  3103. currentStatus = 1; //OCPP Status: Preparing
  3104. }
  3105. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3106. {
  3107. currentStatus = 2; //OCPP Status: Charging
  3108. }
  3109. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3110. {
  3111. currentStatus = 5; //OCPP Status: Finishing
  3112. }
  3113. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3114. {
  3115. currentStatus = 4; //OCPP Status: SuspendedEV
  3116. }
  3117. 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
  3118. {
  3119. currentStatus = 7; //OCPP Status: Unavailable
  3120. }
  3121. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3122. {
  3123. currentStatus = 8; //OCPP Status: Faulted
  3124. }
  3125. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3126. {
  3127. currentStatus = 6; //OCPP Status: Reserved
  3128. }
  3129. } //end of the same index
  3130. } // end of for GB_QUANTITY
  3131. }
  3132. else
  3133. {
  3134. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3135. {
  3136. tempIndex = 2;
  3137. }
  3138. else
  3139. {
  3140. tempIndex = gun_index;
  3141. }
  3142. for (int index = 0; index < AC_QUANTITY; index++)
  3143. {
  3144. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3145. {
  3146. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3147. {
  3148. 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))
  3149. {
  3150. currentStatus = 1; //OCPP Status: Preparing
  3151. }
  3152. else
  3153. {
  3154. currentStatus = 0; //OCPP Status: Available
  3155. }
  3156. }
  3157. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3158. {
  3159. currentStatus = 1; //OCPP Status: Preparing
  3160. }
  3161. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3162. {
  3163. currentStatus = 2; //OCPP Status: Charging
  3164. }
  3165. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3166. {
  3167. currentStatus = 5; //OCPP Status: Finishing
  3168. }
  3169. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3170. {
  3171. currentStatus = 4; //OCPP Status: SuspendedEV
  3172. }
  3173. 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
  3174. {
  3175. currentStatus = 7; //OCPP Status: Unavailable
  3176. }
  3177. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3178. {
  3179. currentStatus = 8; //OCPP Status: Faulted
  3180. }
  3181. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3182. {
  3183. currentStatus = 6; //OCPP Status: Reserved
  3184. }
  3185. }//end of the same index
  3186. }//end of for AC_QUANTITY
  3187. }
  3188. //it's option
  3189. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3190. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3191. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3192. random_uuid(guid);
  3193. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3194. , MESSAGE_TYPE_CALL
  3195. , guid
  3196. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3197. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3198. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3199. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3200. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3201. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3202. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3203. if((server_sign == TRUE))
  3204. {
  3205. LWS_Send(message);
  3206. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3207. 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*/)
  3208. {
  3209. //DEBUG_ERROR("statusNotification mapitem pass");
  3210. result = PASS;
  3211. }
  3212. }
  3213. else
  3214. {
  3215. result = PASS;
  3216. }
  3217. return result;
  3218. }
  3219. int sendStopTransactionRequest(int gun_index)
  3220. {
  3221. mtrace();
  3222. int result = FAIL;
  3223. //char message[1500]={0};
  3224. char guid[37]={0};
  3225. char tempdata[65]={0};
  3226. int tempIndex = 0;
  3227. char TempStopTransaction[256];
  3228. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3229. //int idx_sample=0;
  3230. DEBUG_ERROR("sendStopTransactionRequest \n");
  3231. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3232. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3233. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3234. if(gunType[gun_index] == 'J')
  3235. {
  3236. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3237. {
  3238. tempIndex = ((gun_index==2) ? 1: 0);
  3239. }
  3240. else
  3241. {
  3242. tempIndex = gun_index;
  3243. }
  3244. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3245. {
  3246. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3247. {
  3248. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3249. }
  3250. }// END OF CHAdeMO_QUANTITY
  3251. }
  3252. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3253. {
  3254. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3255. {
  3256. tempIndex = ((gun_index==2) ? 1: 0);
  3257. }
  3258. else
  3259. {
  3260. tempIndex = gun_index;
  3261. }
  3262. for (int index = 0; index < CCS_QUANTITY; index++)
  3263. {
  3264. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3265. {
  3266. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3267. }
  3268. }// END OF CCS_QUANTITY
  3269. }
  3270. else if(gunType[gun_index] == 'G')
  3271. {
  3272. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3273. {
  3274. tempIndex = ((gun_index==2) ? 1: 0);
  3275. }
  3276. else
  3277. {
  3278. tempIndex = gun_index;
  3279. }
  3280. for (int index = 0; index < GB_QUANTITY; index++)
  3281. {
  3282. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3283. {
  3284. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3285. }
  3286. }// END OF GB_QUANTITY
  3287. }
  3288. else
  3289. {
  3290. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3291. {
  3292. tempIndex = 2;
  3293. }
  3294. else
  3295. {
  3296. tempIndex = gun_index;
  3297. }
  3298. for (int index = 0; index < AC_QUANTITY; index++)
  3299. {
  3300. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3301. {
  3302. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3303. }
  3304. }// END OF AC_QUANTITY
  3305. }
  3306. //====================================== Stop Transaction Time =====================================================
  3307. struct timeval tmnow;
  3308. struct tm *tm;
  3309. char buf[28];//, usec_buf[6];
  3310. gettimeofday(&tmnow, NULL);
  3311. time_t t;
  3312. t = time(NULL);
  3313. /*UTC time and date*/
  3314. tm = gmtime(&t);
  3315. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3316. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3317. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3318. random_uuid(guid);
  3319. /***********************************transactionData******************************************************/
  3320. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3321. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3322. //=================================
  3323. // Transaction_Begin
  3324. //=================================
  3325. //============================================ Energy.Active.Import.Interval ================================
  3326. //idx_sample=0;
  3327. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  3328. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3329. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3330. 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*/]);
  3331. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3332. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3333. {
  3334. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3335. }
  3336. else
  3337. {
  3338. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3339. }
  3340. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3341. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3342. //=================================
  3343. // Transaction_End
  3344. //=================================
  3345. // ================================= Current.Import L1 ===============================================
  3346. //idx_sample=1;
  3347. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3348. if(gunType[gun_index] == 'J')
  3349. {
  3350. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3351. {
  3352. tempIndex = ((gun_index==2) ? 1: 0);
  3353. }
  3354. else
  3355. {
  3356. tempIndex = gun_index;
  3357. }
  3358. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3359. {
  3360. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3361. {
  3362. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3363. }
  3364. }// End of for CHAdeMO_QUANTITY
  3365. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3366. }
  3367. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3368. {
  3369. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3370. {
  3371. tempIndex = ((gun_index==2) ? 1: 0);
  3372. }
  3373. else
  3374. {
  3375. tempIndex = gun_index;
  3376. }
  3377. for (int index = 0; index < CCS_QUANTITY; index++)
  3378. {
  3379. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3380. {
  3381. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3382. }
  3383. }// End of for CCS_QUANTITY
  3384. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3385. }
  3386. else if(gunType[gun_index] == 'G')
  3387. {
  3388. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3389. {
  3390. tempIndex = ((gun_index==2) ? 1: 0);
  3391. }
  3392. else
  3393. {
  3394. tempIndex = gun_index;
  3395. }
  3396. for (int index = 0; index < GB_QUANTITY; index++)
  3397. {
  3398. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3399. {
  3400. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3401. }
  3402. }// End of for GB_QUANTITY
  3403. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3404. }
  3405. else
  3406. {
  3407. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3408. {
  3409. tempIndex = 2;
  3410. }
  3411. else
  3412. {
  3413. tempIndex = gun_index;
  3414. }
  3415. for (int index = 0; index < AC_QUANTITY; index++)
  3416. {
  3417. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3418. {
  3419. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3420. }
  3421. }// End of for AC_QUANTITY
  3422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3423. }
  3424. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3425. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3426. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3427. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3428. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3429. // ================================= Energy.Active.Import.Interval ==============================================
  3430. //idx_sample=2;
  3431. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3432. if(gunType[gun_index] == 'J')
  3433. {
  3434. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3435. {
  3436. tempIndex = ((gun_index==2) ? 1: 0);
  3437. }
  3438. else
  3439. {
  3440. tempIndex = gun_index;
  3441. }
  3442. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3443. {
  3444. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3445. {
  3446. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3447. }
  3448. }// END OF CHAdeMO_QUANTITY
  3449. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3450. }
  3451. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3452. {
  3453. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3454. {
  3455. tempIndex = ((gun_index==2) ? 1: 0);
  3456. }
  3457. else
  3458. {
  3459. tempIndex = gun_index;
  3460. }
  3461. for (int index = 0; index < CCS_QUANTITY; index++)
  3462. {
  3463. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3464. {
  3465. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3466. }
  3467. }// END OF CCS_QUANTITY
  3468. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3469. }
  3470. else if(gunType[gun_index] == 'G')
  3471. {
  3472. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3473. {
  3474. tempIndex = ((gun_index==2) ? 1: 0);
  3475. }
  3476. else
  3477. {
  3478. tempIndex = gun_index;
  3479. }
  3480. for (int index = 0; index < GB_QUANTITY; index++)
  3481. {
  3482. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3483. {
  3484. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3485. }
  3486. }// END OF GB_QUANTITY
  3487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3488. }
  3489. else
  3490. {
  3491. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3492. {
  3493. tempIndex = 2;
  3494. }
  3495. else
  3496. {
  3497. tempIndex = gun_index;
  3498. }
  3499. for (int index = 0; index < AC_QUANTITY; index++)
  3500. {
  3501. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3502. {
  3503. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3504. }
  3505. }// END OF AC_QUANTITY
  3506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3507. }
  3508. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3512. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3513. //=================================== Power.Active.Import ==================================================
  3514. //idx_sample=3;
  3515. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3516. if(gunType[gun_index] == 'J')
  3517. {
  3518. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3519. {
  3520. tempIndex = ((gun_index==2) ? 1: 0);
  3521. }
  3522. else
  3523. {
  3524. tempIndex = gun_index;
  3525. }
  3526. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3527. {
  3528. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3529. {
  3530. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3531. }
  3532. } // End for CHAdeMO_QUANTITY
  3533. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3534. }
  3535. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3536. {
  3537. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3538. {
  3539. tempIndex = ((gun_index==2) ? 1: 0);
  3540. }
  3541. else
  3542. {
  3543. tempIndex = gun_index;
  3544. }
  3545. for (int index = 0; index < CCS_QUANTITY; index++)
  3546. {
  3547. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3548. {
  3549. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3550. }
  3551. } // END for CCS_QUANTITY
  3552. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3553. }
  3554. else if(gunType[gun_index] == 'G')
  3555. {
  3556. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3557. {
  3558. tempIndex = ((gun_index==2) ? 1: 0);
  3559. }
  3560. else
  3561. {
  3562. tempIndex = gun_index;
  3563. }
  3564. for (int index = 0; index < GB_QUANTITY; index++)
  3565. {
  3566. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3567. {
  3568. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3569. }
  3570. }// END for GB_QUANTITY
  3571. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3572. }
  3573. else
  3574. {
  3575. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3576. {
  3577. tempIndex = 2;
  3578. }
  3579. else
  3580. {
  3581. tempIndex = gun_index;
  3582. }
  3583. for (int index = 0; index < AC_QUANTITY; index++)
  3584. {
  3585. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3586. {
  3587. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3588. }
  3589. } // END for AC_QUANTITY
  3590. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3591. }
  3592. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3593. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3596. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3597. //============================ Voltage L1 ====================================
  3598. //idx_sample=4;
  3599. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3600. if(gunType[gun_index] == 'J')
  3601. {
  3602. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3603. {
  3604. tempIndex = ((gun_index==2) ? 1: 0);
  3605. }
  3606. else
  3607. {
  3608. tempIndex = gun_index;
  3609. }
  3610. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3611. {
  3612. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3613. {
  3614. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3615. }
  3616. } // END OF FOR CHAdeMO_QUANTITY
  3617. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3618. }
  3619. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3620. {
  3621. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3622. {
  3623. tempIndex = ((gun_index==2) ? 1: 0);
  3624. }
  3625. else
  3626. {
  3627. tempIndex = gun_index;
  3628. }
  3629. for (int index = 0; index < CCS_QUANTITY; index++)
  3630. {
  3631. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3632. {
  3633. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3634. }
  3635. } // END OF FOR CCS_QUANTITY
  3636. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3637. }
  3638. else if(gunType[gun_index] == 'G')
  3639. {
  3640. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3641. {
  3642. tempIndex = ((gun_index==2) ? 1: 0);
  3643. }
  3644. else
  3645. {
  3646. tempIndex = gun_index;
  3647. }
  3648. for (int index = 0; index < GB_QUANTITY; index++)
  3649. {
  3650. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3651. {
  3652. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3653. }
  3654. } // END OF FOR GB_QUANTITY
  3655. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3656. }
  3657. else
  3658. {
  3659. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3660. {
  3661. tempIndex = 2;
  3662. }
  3663. else
  3664. {
  3665. tempIndex = gun_index;
  3666. }
  3667. for (int index = 0; index < AC_QUANTITY; index++)
  3668. {
  3669. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3670. {
  3671. 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
  3672. }
  3673. } // END OF FOR AC_QUANTITY
  3674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3675. }
  3676. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3677. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3678. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3679. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3680. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3681. //====================== SoC ================================
  3682. //idx_sample=5;
  3683. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3684. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3685. {
  3686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3687. {
  3688. tempIndex = ((gun_index==2) ? 1: 0);
  3689. }
  3690. else
  3691. {
  3692. tempIndex = gun_index;
  3693. }
  3694. if(gunType[gun_index] == 'J')
  3695. {
  3696. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3697. {
  3698. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3699. {
  3700. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3701. }
  3702. }
  3703. }
  3704. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3705. {
  3706. for (int index = 0; index < CCS_QUANTITY; index++)
  3707. {
  3708. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3709. {
  3710. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3711. }
  3712. }
  3713. }
  3714. else if(gunType[gun_index] == 'G')
  3715. {
  3716. for (int index = 0; index < GB_QUANTITY; index++)
  3717. {
  3718. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3719. {
  3720. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  3721. }
  3722. }
  3723. }
  3724. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3725. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  3726. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  3727. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  3728. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  3729. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  3730. } // END FOR DC CASE
  3731. // ================================= Current.Import L2 ===============================================
  3732. //idx_sample=6;
  3733. // AC 3 phse L2 current
  3734. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3735. {
  3736. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3737. {
  3738. tempIndex = 2;
  3739. }
  3740. else
  3741. {
  3742. tempIndex = gun_index;
  3743. }
  3744. for (int index = 0; index < AC_QUANTITY; index++)
  3745. {
  3746. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3747. {
  3748. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  3749. }
  3750. }// End of for AC_QUANTITY
  3751. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  3752. }
  3753. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3754. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  3755. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  3756. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  3757. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3758. // ================================= Current.Import L3 ===============================================
  3759. //idx_sample=7;
  3760. // AC 3 phse L3 current
  3761. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3762. {
  3763. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3764. {
  3765. tempIndex = 2;
  3766. }
  3767. else
  3768. {
  3769. tempIndex = gun_index;
  3770. }
  3771. for (int index = 0; index < AC_QUANTITY; index++)
  3772. {
  3773. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3774. {
  3775. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  3776. }
  3777. }// End of for AC_QUANTITY
  3778. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  3779. }
  3780. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3781. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  3782. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  3783. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  3784. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3785. //============================ Voltage L2 ====================================
  3786. //idx_sample=8;
  3787. // AC 3 phse L2 voltage
  3788. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3789. {
  3790. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3791. {
  3792. tempIndex = 2;
  3793. }
  3794. else
  3795. {
  3796. tempIndex = gun_index;
  3797. }
  3798. for (int index = 0; index < AC_QUANTITY; index++)
  3799. {
  3800. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3801. {
  3802. 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
  3803. }
  3804. } // END OF FOR AC_QUANTITY
  3805. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  3806. }
  3807. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3808. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  3809. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  3810. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  3811. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3812. //============================ Voltage L3 ====================================
  3813. //idx_sample=8;
  3814. // AC 3 phse L3 voltage
  3815. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3816. {
  3817. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3818. {
  3819. tempIndex = 2;
  3820. }
  3821. else
  3822. {
  3823. tempIndex = gun_index;
  3824. }
  3825. for (int index = 0; index < AC_QUANTITY; index++)
  3826. {
  3827. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3828. {
  3829. 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
  3830. }
  3831. } // END OF FOR AC_QUANTITY
  3832. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  3833. }
  3834. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3835. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  3836. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  3837. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  3838. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3839. //================================================ Message create ====================================================
  3840. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3841. {
  3842. 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\"}]}]}]"
  3843. ,gun_index+1
  3844. ,MESSAGE_TYPE_CALL
  3845. ,guid
  3846. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3847. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3848. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3849. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3850. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3851. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3852. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3853. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3854. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3855. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3856. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3857. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3858. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3859. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3860. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3861. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3862. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3863. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3864. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3865. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3866. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3867. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3868. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3869. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3870. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3871. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  3888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  3889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  3890. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  3891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  3892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  3893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  3894. );
  3895. }
  3896. else
  3897. {
  3898. if((ShmSysConfigAndInfo->SysConfig.ModelName[2]!='Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2]!='W'))
  3899. {
  3900. 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\"}]}]}]"
  3901. ,gun_index+1
  3902. ,MESSAGE_TYPE_CALL
  3903. ,guid
  3904. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3905. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3906. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3907. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3908. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3909. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3910. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3911. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3912. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3913. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3914. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3915. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3916. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3917. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3918. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3919. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3920. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3921. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3922. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3923. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3924. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3925. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3926. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3927. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3928. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3929. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3930. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3931. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3932. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3933. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3934. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3935. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3936. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3937. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3938. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3939. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3940. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3941. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3942. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3943. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3944. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3945. );
  3946. }
  3947. else
  3948. {
  3949. 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\"}]}]}]"
  3950. ,gun_index+1
  3951. ,MESSAGE_TYPE_CALL
  3952. ,guid
  3953. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3954. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3955. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3956. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3957. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3958. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3959. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3960. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3961. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3962. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3963. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3964. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3965. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3966. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3967. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3968. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3969. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3970. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3971. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3972. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3973. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3974. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3975. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3976. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3977. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3978. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3979. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3980. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3981. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3982. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3983. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3984. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3985. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3986. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3987. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3988. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3989. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3990. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3991. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3992. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3993. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3994. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  3995. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  3996. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  3997. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  3998. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  3999. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  4000. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  4001. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  4002. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  4003. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  4004. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  4005. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  4006. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  4007. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  4008. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  4009. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  4010. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  4011. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  4012. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  4013. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  4014. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  4015. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  4016. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  4017. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  4018. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  4019. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  4020. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  4021. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  4022. );
  4023. }
  4024. }
  4025. #if 1 // for TempStopTransaction
  4026. //Delete TempStopTransaction
  4027. if((access(TempStopTransaction,F_OK))!=-1)
  4028. {
  4029. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4030. }
  4031. #endif
  4032. #if 1
  4033. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4034. if(hashmap_operation(0, guid, tempdata) == 1)
  4035. {
  4036. result = PASS;
  4037. DEBUG_INFO("StopTransaction mapitem pass\n");
  4038. }
  4039. #endif
  4040. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4041. /*
  4042. if(GetTransactionQueueNum() == 1)
  4043. {
  4044. LWS_Send(queuedata+2);
  4045. }*/
  4046. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4047. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4048. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4049. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4050. {
  4051. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4052. }
  4053. //for test
  4054. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4055. return result;
  4056. }
  4057. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4058. {
  4059. mtrace();
  4060. int result = FAIL;
  4061. char guid[37]={0};
  4062. char tempdata[65]={0};
  4063. int tempIndex = 0;
  4064. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4065. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4066. //set value
  4067. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4068. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) ? ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId : 0);
  4069. random_uuid(guid);
  4070. //UTC Date time
  4071. struct timeval tmnow;
  4072. struct tm *tm;
  4073. char buf[28];//, usec_buf[6];
  4074. gettimeofday(&tmnow, NULL);
  4075. time_t t;
  4076. t = time(NULL);
  4077. /*UTC time and date*/
  4078. tm = gmtime(&t);
  4079. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4080. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4081. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4082. //idx_sample=0;
  4083. //********************************(1)Current.Import L1************************************************/
  4084. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4085. if(gunType[gun_index] == 'J')
  4086. {
  4087. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4088. {
  4089. tempIndex = ((gun_index==2) ? 1: 0);
  4090. }
  4091. else
  4092. {
  4093. tempIndex = gun_index;
  4094. }
  4095. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4096. {
  4097. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4098. {
  4099. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4100. }
  4101. }
  4102. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4103. }
  4104. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4105. {
  4106. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4107. {
  4108. tempIndex = ((gun_index==2) ? 1: 0);
  4109. }
  4110. else
  4111. {
  4112. tempIndex = gun_index;
  4113. }
  4114. for (int index = 0; index < CCS_QUANTITY; index++)
  4115. {
  4116. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4117. {
  4118. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4119. }
  4120. }
  4121. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4122. }
  4123. else if(gunType[gun_index] == 'G')
  4124. {
  4125. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4126. {
  4127. tempIndex = ((gun_index==2) ? 1: 0);
  4128. }
  4129. else
  4130. {
  4131. tempIndex = gun_index;
  4132. }
  4133. for (int index = 0; index < GB_QUANTITY; index++)
  4134. {
  4135. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4136. {
  4137. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4138. }
  4139. }
  4140. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4141. }
  4142. else
  4143. {
  4144. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4145. {
  4146. tempIndex = 2;
  4147. }
  4148. else
  4149. {
  4150. tempIndex = gun_index;
  4151. }
  4152. for (int index = 0; index < AC_QUANTITY; index++)
  4153. {
  4154. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4155. {
  4156. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4157. }
  4158. }
  4159. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4160. }
  4161. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4162. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4163. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4164. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4165. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4166. //idx_sample=1;
  4167. //********************************(2)Energy.Active.Import.Register ************************************************/
  4168. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4169. if(gunType[gun_index] == 'J')
  4170. {
  4171. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4172. {
  4173. tempIndex = ((gun_index==2) ? 1: 0);
  4174. }
  4175. else
  4176. {
  4177. tempIndex = gun_index;
  4178. }
  4179. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4180. {
  4181. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4182. {
  4183. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4184. }
  4185. }
  4186. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4187. }
  4188. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4189. {
  4190. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4191. {
  4192. tempIndex = ((gun_index==2) ? 1: 0);
  4193. }
  4194. else
  4195. {
  4196. tempIndex = gun_index;
  4197. }
  4198. for (int index = 0; index < CCS_QUANTITY; index++)
  4199. {
  4200. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4201. {
  4202. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4203. }
  4204. }
  4205. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4206. }
  4207. else if(gunType[gun_index] == 'G')
  4208. {
  4209. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4210. {
  4211. tempIndex = ((gun_index==2) ? 1: 0);
  4212. }
  4213. else
  4214. {
  4215. tempIndex = gun_index;
  4216. }
  4217. for (int index = 0; index < GB_QUANTITY; index++)
  4218. {
  4219. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4220. {
  4221. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4222. }
  4223. }
  4224. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4225. }
  4226. else
  4227. {
  4228. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4229. {
  4230. tempIndex = 2;
  4231. }
  4232. else
  4233. {
  4234. tempIndex = gun_index;
  4235. }
  4236. for (int index = 0; index < AC_QUANTITY; index++)
  4237. {
  4238. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4239. {
  4240. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4241. }
  4242. }
  4243. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4244. }
  4245. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4246. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4247. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4248. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4249. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4250. //idx_sample=2;
  4251. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4252. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4253. if(gunType[gun_index] == 'J')
  4254. {
  4255. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4256. {
  4257. tempIndex = ((gun_index==2) ? 1: 0);
  4258. }
  4259. else
  4260. {
  4261. tempIndex = gun_index;
  4262. }
  4263. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4264. {
  4265. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4266. {
  4267. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4268. }
  4269. } // END OF FOR CHAdeMO_QUANTITY
  4270. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4271. }
  4272. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4273. {
  4274. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4275. {
  4276. tempIndex = ((gun_index==2) ? 1: 0);
  4277. }
  4278. else
  4279. {
  4280. tempIndex = gun_index;
  4281. }
  4282. for (int index = 0; index < CCS_QUANTITY; index++)
  4283. {
  4284. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4285. {
  4286. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4287. }
  4288. } // END OF CCS_QUANTITY
  4289. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4290. }
  4291. else if(gunType[gun_index] == 'G')
  4292. {
  4293. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4294. {
  4295. tempIndex = ((gun_index==2) ? 1: 0);
  4296. }
  4297. else
  4298. {
  4299. tempIndex = gun_index;
  4300. }
  4301. for (int index = 0; index < GB_QUANTITY; index++)
  4302. {
  4303. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4304. {
  4305. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4306. }
  4307. } // END OF GB_QUANTITY
  4308. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4309. }
  4310. else
  4311. {
  4312. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4313. {
  4314. tempIndex = 2;
  4315. }
  4316. else
  4317. {
  4318. tempIndex = gun_index;
  4319. }
  4320. for (int index = 0; index < AC_QUANTITY; index++)
  4321. {
  4322. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4323. {
  4324. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4325. }
  4326. }
  4327. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4328. }
  4329. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4330. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4331. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4332. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4333. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4334. //idx_sample=3;
  4335. //********************************(4)Power.Active.Import************************************************/
  4336. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4337. if(gunType[gun_index] == 'J')
  4338. {
  4339. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4340. {
  4341. tempIndex = ((gun_index==2) ? 1: 0);
  4342. }
  4343. else
  4344. {
  4345. tempIndex = gun_index;
  4346. }
  4347. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4348. {
  4349. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4350. {
  4351. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4352. }
  4353. } // END OF FOR
  4354. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4355. }
  4356. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4357. {
  4358. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4359. {
  4360. tempIndex = ((gun_index==2) ? 1: 0);
  4361. }
  4362. else
  4363. {
  4364. tempIndex = gun_index;
  4365. }
  4366. for (int index = 0; index < CCS_QUANTITY; index++)
  4367. {
  4368. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4369. {
  4370. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4371. }
  4372. }
  4373. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4374. }
  4375. else if(gunType[gun_index] == 'G')
  4376. {
  4377. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4378. {
  4379. tempIndex = ((gun_index==2) ? 1: 0);
  4380. }
  4381. else
  4382. {
  4383. tempIndex = gun_index;
  4384. }
  4385. for (int index = 0; index < GB_QUANTITY; index++)
  4386. {
  4387. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4388. {
  4389. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4390. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4391. }
  4392. }
  4393. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4394. }
  4395. else
  4396. {
  4397. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4398. {
  4399. tempIndex = 2;
  4400. }
  4401. else
  4402. {
  4403. tempIndex = gun_index;
  4404. }
  4405. for (int index = 0; index < AC_QUANTITY; index++)
  4406. {
  4407. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4408. {
  4409. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4410. }
  4411. }
  4412. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4413. }
  4414. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4415. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4416. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4417. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4418. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4419. //idx_sample=4;
  4420. //***********************************************(5)VOLTAGE L1******************************************************/
  4421. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4422. if(gunType[gun_index] == 'J')
  4423. {
  4424. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4425. {
  4426. tempIndex = ((gun_index==2) ? 1: 0);
  4427. }
  4428. else
  4429. {
  4430. tempIndex = gun_index;
  4431. }
  4432. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4433. {
  4434. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4435. {
  4436. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4437. }
  4438. }
  4439. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4440. }
  4441. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4442. {
  4443. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4444. {
  4445. tempIndex = ((gun_index==2) ? 1: 0);
  4446. }
  4447. else
  4448. {
  4449. tempIndex = gun_index;
  4450. }
  4451. for (int index = 0; index < CCS_QUANTITY; index++)
  4452. {
  4453. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4454. {
  4455. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4456. }
  4457. }
  4458. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4459. }
  4460. else if(gunType[gun_index] == 'G')
  4461. {
  4462. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4463. {
  4464. tempIndex = ((gun_index==2) ? 1: 0);
  4465. }
  4466. else
  4467. {
  4468. tempIndex = gun_index;
  4469. }
  4470. for (int index = 0; index < GB_QUANTITY; index++)
  4471. {
  4472. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4473. {
  4474. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4475. }
  4476. }
  4477. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4478. }
  4479. else
  4480. {
  4481. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4482. {
  4483. tempIndex = 2;
  4484. }
  4485. else
  4486. {
  4487. tempIndex = gun_index;
  4488. }
  4489. for (int index = 0; index < AC_QUANTITY; index++)
  4490. {
  4491. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4492. {
  4493. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4494. }
  4495. }
  4496. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4497. }
  4498. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4499. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4500. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4501. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4502. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4503. //***********************************************(6)SOC******************************************************/
  4504. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4505. {
  4506. //idx_sample=5;
  4507. //sampledValue = NULL;
  4508. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4509. {
  4510. tempIndex = ((gun_index==2) ? 1: 0);
  4511. }
  4512. else
  4513. {
  4514. tempIndex = gun_index;
  4515. }
  4516. if(gunType[gun_index] == 'J')
  4517. {
  4518. //tempIndex = ((gun_index==2) ? 1: 0);
  4519. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4520. {
  4521. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4522. {
  4523. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4524. }
  4525. }
  4526. }
  4527. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4528. {
  4529. //tempIndex = ((gun_index==2) ? 1: 0);
  4530. for (int index = 0; index < CCS_QUANTITY; index++)
  4531. {
  4532. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4533. {
  4534. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4535. }
  4536. }
  4537. }
  4538. else if(gunType[gun_index] == 'G')
  4539. {
  4540. //tempIndex = ((gun_index==2) ? 1: 0);
  4541. for (int index = 0; index < GB_QUANTITY; index++)
  4542. {
  4543. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4544. {
  4545. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4546. }
  4547. }
  4548. }
  4549. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4550. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4551. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4552. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4553. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_Outlet]);
  4554. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4555. }
  4556. //********************************(7)Current.Import L2************************************************/
  4557. // Only for AC 3 phase
  4558. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4559. {
  4560. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4561. {
  4562. tempIndex = 2;
  4563. }
  4564. else
  4565. {
  4566. tempIndex = gun_index;
  4567. }
  4568. for (int index = 0; index < AC_QUANTITY; index++)
  4569. {
  4570. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4571. {
  4572. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  4573. }
  4574. }
  4575. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  4576. }
  4577. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  4578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  4579. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  4580. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  4581. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4582. //********************************(8)Current.Import L3************************************************/
  4583. // Only for AC 3 phase
  4584. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4585. {
  4586. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4587. {
  4588. tempIndex = 2;
  4589. }
  4590. else
  4591. {
  4592. tempIndex = gun_index;
  4593. }
  4594. for (int index = 0; index < AC_QUANTITY; index++)
  4595. {
  4596. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4597. {
  4598. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  4599. }
  4600. }
  4601. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  4602. }
  4603. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  4604. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  4605. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  4606. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  4607. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4608. //***********************************************(9)VOLTAGE L2******************************************************/
  4609. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4610. {
  4611. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4612. {
  4613. tempIndex = 2;
  4614. }
  4615. else
  4616. {
  4617. tempIndex = gun_index;
  4618. }
  4619. for (int index = 0; index < AC_QUANTITY; index++)
  4620. {
  4621. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4622. {
  4623. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  4624. }
  4625. }
  4626. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  4627. }
  4628. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  4629. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  4630. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  4631. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  4632. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4633. //***********************************************(10)VOLTAGE L3******************************************************/
  4634. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4635. {
  4636. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4637. {
  4638. tempIndex = 2;
  4639. }
  4640. else
  4641. {
  4642. tempIndex = gun_index;
  4643. }
  4644. for (int index = 0; index < AC_QUANTITY; index++)
  4645. {
  4646. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4647. {
  4648. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  4649. }
  4650. }
  4651. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  4652. }
  4653. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  4654. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  4655. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  4656. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  4657. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4658. // Message create ====================================================================================================
  4659. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4660. {
  4661. 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\"}]}]}]"
  4662. ,gun_index + 1
  4663. ,MESSAGE_TYPE_CALL
  4664. ,guid
  4665. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4666. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4667. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4668. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4669. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4670. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4671. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4672. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4673. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4674. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4675. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4676. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4677. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4678. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4679. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4680. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4681. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4682. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4683. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4684. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4685. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4686. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4687. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4688. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4689. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4690. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4691. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4692. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4693. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4694. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4695. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4696. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4697. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4698. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4699. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4700. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4701. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4702. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4703. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value
  4704. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context
  4705. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format
  4706. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand
  4707. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase
  4708. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location
  4709. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit
  4710. );
  4711. }
  4712. else
  4713. {
  4714. if((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W'))
  4715. {
  4716. 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\"}]}]}]"
  4717. ,gun_index + 1
  4718. ,MESSAGE_TYPE_CALL
  4719. ,guid
  4720. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4721. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4722. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4723. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4724. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4725. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4726. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4727. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4728. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4729. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4730. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4731. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4732. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4733. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4734. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4735. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4736. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4737. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4738. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4739. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4740. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4741. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4742. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4743. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4744. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4745. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4746. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4747. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4748. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4749. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4750. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4751. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4752. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4753. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4754. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4755. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4756. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4757. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4758. );
  4759. }
  4760. else
  4761. {
  4762. 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\"}]}]}]"
  4763. ,gun_index + 1
  4764. ,MESSAGE_TYPE_CALL
  4765. ,guid
  4766. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4767. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4768. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4769. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4770. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4771. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4772. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4773. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4774. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4775. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4776. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4777. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4778. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4779. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4780. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4781. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4782. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4783. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4784. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4785. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4786. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4787. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4788. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4789. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4790. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4791. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4792. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4793. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4794. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4795. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4796. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4797. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4798. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4799. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4800. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4801. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4802. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4803. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4804. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value
  4805. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context
  4806. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format
  4807. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand
  4808. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase
  4809. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location
  4810. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit
  4811. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value
  4812. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context
  4813. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format
  4814. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand
  4815. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase
  4816. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location
  4817. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit
  4818. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value
  4819. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context
  4820. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format
  4821. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand
  4822. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase
  4823. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location
  4824. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit
  4825. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value
  4826. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context
  4827. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format
  4828. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand
  4829. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase
  4830. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location
  4831. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit
  4832. );
  4833. }
  4834. }
  4835. // Put request guid to hash map
  4836. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4837. 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*/)
  4838. {
  4839. result = PASS;
  4840. DEBUG_INFO("MeterValues mapitem pass\n");
  4841. }
  4842. if(dataType != ReadingContext_Trigger)
  4843. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4844. else
  4845. LWS_Send(queuedata +2);
  4846. /*
  4847. if(GetTransactionQueueNum() == 1)
  4848. {
  4849. LWS_Send(queuedata +2);
  4850. }*/
  4851. return result;
  4852. }
  4853. //==========================================
  4854. // send confirm routine
  4855. //==========================================
  4856. int sendCancelReservationConfirmation(char *uuid,char *payload)
  4857. {
  4858. mtrace();
  4859. int result = FAIL;
  4860. char message[100]={0};
  4861. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  4862. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4863. LWS_Send(message);
  4864. result = TRUE;
  4865. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  4866. return result;
  4867. }
  4868. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  4869. {
  4870. mtrace();
  4871. int result = FAIL;
  4872. char message[100]={0};
  4873. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  4874. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4875. LWS_Send(message);
  4876. result = TRUE;
  4877. return result;
  4878. }
  4879. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  4880. {
  4881. mtrace();
  4882. int result = FAIL;
  4883. char message[100]={0};
  4884. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  4885. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4886. LWS_Send(message);
  4887. result = TRUE;
  4888. return result;
  4889. }
  4890. int sendClearCacheConfirmation(char *uuid,char *payload)
  4891. {
  4892. mtrace();
  4893. int result = FAIL;
  4894. char message[500]={0};
  4895. DEBUG_INFO("sendClearCacheConfirmation...\n");
  4896. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4897. LWS_Send(message);
  4898. return result;
  4899. }
  4900. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  4901. {
  4902. mtrace();
  4903. int result = FAIL;
  4904. char message[500]={0};
  4905. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  4906. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4907. LWS_Send(message);
  4908. return result;
  4909. }
  4910. int sendDataTransferConfirmation(char *uuid,char *payload)
  4911. {
  4912. mtrace();
  4913. char statusStr[20]={0};
  4914. char dataStr[10]={0};
  4915. char sstr[20]={0};
  4916. int c = 0;
  4917. char *loc;
  4918. int result = FAIL;
  4919. DEBUG_INFO("sendDataTransferConfirmation...\n");
  4920. /**********************status**************************/
  4921. loc = strstr(payload, "status");
  4922. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4923. c = 0;
  4924. while (loc[3+strlen("status")+c] != '\"')
  4925. {
  4926. sstr[c] = loc[3+strlen("status")+c];
  4927. c++;
  4928. }
  4929. sstr[c] = '\0';
  4930. strcpy(statusStr, sstr);
  4931. /**********************data**************************/
  4932. loc = strstr(payload, "data");
  4933. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4934. c = 0;
  4935. while (loc[3+strlen("data")+c] != '\"')
  4936. {
  4937. sstr[c] = loc[3+strlen("data")+c];
  4938. c++;
  4939. }
  4940. sstr[c] = '\0';
  4941. strcpy(dataStr, sstr);
  4942. return result;
  4943. }
  4944. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  4945. {
  4946. mtrace();
  4947. int result = FAIL;
  4948. char message[1000]={0};
  4949. int CompositeScheduleIndex = 0;
  4950. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  4951. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  4952. if(nPeriod == 0)
  4953. {
  4954. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  4955. {
  4956. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  4957. ,MESSAGE_TYPE_CALLRESULT
  4958. ,uuid
  4959. ,payload
  4960. ,connectorIdInt);
  4961. }
  4962. else
  4963. {
  4964. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  4965. ,MESSAGE_TYPE_CALLRESULT
  4966. ,uuid
  4967. ,payload
  4968. ,connectorIdInt
  4969. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4970. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4971. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4972. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  4973. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  4974. }
  4975. }
  4976. else
  4977. {
  4978. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  4979. ,MESSAGE_TYPE_CALLRESULT
  4980. ,uuid
  4981. ,payload
  4982. ,connectorIdInt
  4983. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4984. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4985. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4986. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  4987. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  4988. {
  4989. if (idx_sample == 0)
  4990. {
  4991. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4992. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4993. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4994. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4995. }
  4996. else
  4997. {
  4998. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4999. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5000. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5001. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5002. }
  5003. }
  5004. sprintf(message + strlen(message), "]}}]");
  5005. }
  5006. LWS_Send(message);
  5007. result = TRUE;
  5008. return result;
  5009. }
  5010. int sendGetConfigurationConfirmation(char *uuid)
  5011. {
  5012. mtrace();
  5013. int result = FAIL;
  5014. int MaxKeySupported = 0;
  5015. int sentConfigurationNumber= 0;
  5016. int sentunConfigurationNumber= 0;
  5017. char message[4000]={0};
  5018. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5019. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5020. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5021. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5022. ,MESSAGE_TYPE_CALLRESULT
  5023. ,uuid );
  5024. //configuration key
  5025. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5026. {
  5027. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5028. {
  5029. if (sentConfigurationNumber == 0)
  5030. {
  5031. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5032. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5033. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5034. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5035. }
  5036. else
  5037. {
  5038. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5039. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5040. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5041. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5042. }
  5043. sentConfigurationNumber = sentConfigurationNumber + 1;
  5044. }
  5045. }
  5046. sprintf(message + strlen(message), "]");
  5047. if(UnknownKeynum != 0)
  5048. {
  5049. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5050. //unkown key
  5051. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5052. {
  5053. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5054. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5055. if(sentunConfigurationNumber == 0)
  5056. {
  5057. sprintf(message + strlen(message), "\"%s\""
  5058. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5059. }
  5060. else
  5061. {
  5062. sprintf(message + strlen(message), ",\"%s\""
  5063. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5064. }
  5065. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5066. }
  5067. sprintf(message + strlen(message), "]");
  5068. }
  5069. sprintf(message + strlen(message), "}]");
  5070. LWS_Send(message);
  5071. return result;
  5072. }
  5073. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5074. {
  5075. mtrace();
  5076. int result = FAIL;
  5077. char message[400]={0};
  5078. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5079. if(strcmp(payload,"")==0)
  5080. {
  5081. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5082. }
  5083. else
  5084. {
  5085. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5086. }
  5087. LWS_Send(message);
  5088. result = TRUE;
  5089. return result;
  5090. }
  5091. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5092. {
  5093. mtrace();
  5094. int result = FAIL;
  5095. char message[80]={0};
  5096. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5097. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5098. LWS_Send(message);
  5099. result = TRUE;
  5100. return result;
  5101. }
  5102. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5103. {
  5104. mtrace();
  5105. int result = FAIL;
  5106. char message[80]={0};
  5107. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5108. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5109. LWS_Send(message);
  5110. result = TRUE;
  5111. return result;
  5112. }
  5113. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5114. {
  5115. mtrace();
  5116. int result = FAIL;
  5117. char message[80]={0};
  5118. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5119. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5120. LWS_Send(message);
  5121. result = TRUE;
  5122. return result;
  5123. }
  5124. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5125. {
  5126. mtrace();
  5127. int result = FAIL;
  5128. char message[80]={0};
  5129. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5130. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5131. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5132. LWS_Send(message);
  5133. result = TRUE;
  5134. return result;
  5135. }
  5136. int sendResetConfirmation(char *uuid,char *payload)
  5137. {
  5138. mtrace();
  5139. int result = FAIL;
  5140. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5141. char message[80]={0};
  5142. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  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 sendSendLocalListConfirmation(char *uuid,char *payload)
  5149. {
  5150. mtrace();
  5151. int result = FAIL;
  5152. char message[500]={0};
  5153. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5154. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5155. LWS_Send(message);
  5156. result = TRUE;
  5157. return result;
  5158. }
  5159. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5160. {
  5161. mtrace();
  5162. int result = FAIL;
  5163. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5164. char message[80]={0};
  5165. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5166. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5167. LWS_Send(message);
  5168. result = TRUE;
  5169. return result;
  5170. }
  5171. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5172. {
  5173. mtrace();
  5174. int result = FAIL;
  5175. char message[80]={0};
  5176. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5177. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5178. LWS_Send(message);
  5179. result = TRUE;
  5180. return result;
  5181. }
  5182. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5183. {
  5184. mtrace();
  5185. int result = FAIL;
  5186. char message[80]={0};
  5187. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5188. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5189. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5190. LWS_Send(message);
  5191. result = TRUE;
  5192. return result;
  5193. }
  5194. int sendUpdateFirmwareConfirmation(char *uuid)
  5195. {
  5196. mtrace();
  5197. int result = FAIL;
  5198. char message[60]={0};
  5199. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5200. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5201. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5202. LWS_Send(message);
  5203. result = TRUE;
  5204. return result;
  5205. }
  5206. //==========================================
  5207. // send CallError routine
  5208. //==========================================
  5209. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5210. {
  5211. mtrace();
  5212. char message[220]={0};
  5213. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5214. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5215. LWS_Send(message);
  5216. }
  5217. //==========================================
  5218. // Handle server request routine Start
  5219. //==========================================
  5220. int handleCancelReservationRequest(char *uuid, char *payload)
  5221. {
  5222. mtrace();
  5223. int result = FAIL;
  5224. int gunNO = 0;
  5225. int reservationIdInt =0;
  5226. char comfirmstr[20];
  5227. DEBUG_INFO("handleCancelReservationRequest...\n");
  5228. json_object *CancelReservation;
  5229. CancelReservation = json_tokener_parse(payload);
  5230. if(!is_error(CancelReservation))
  5231. {
  5232. // Required data
  5233. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5234. }
  5235. json_object_put(CancelReservation);
  5236. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5237. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5238. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5239. //check Transaction active
  5240. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5241. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5242. {
  5243. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5244. {
  5245. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5246. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5247. if(gunType[2] == 'J')
  5248. {
  5249. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5250. }
  5251. else
  5252. {
  5253. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5254. }
  5255. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5256. goto end;
  5257. }
  5258. }
  5259. for (int index = 0; index < CCS_QUANTITY; index++)
  5260. {
  5261. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5262. {
  5263. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5264. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5265. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5266. {
  5267. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5268. }
  5269. else
  5270. {
  5271. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5272. }
  5273. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5274. goto end;
  5275. }
  5276. }
  5277. for (int index = 0; index < GB_QUANTITY; index++)
  5278. {
  5279. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5280. {
  5281. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5282. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5283. if(gunType[2] == 'G')
  5284. {
  5285. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5286. }
  5287. else
  5288. {
  5289. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5290. }
  5291. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5292. goto end;
  5293. }
  5294. }
  5295. for (int index = 0; index < AC_QUANTITY; index++)
  5296. {
  5297. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5298. {
  5299. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5300. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5301. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5302. {
  5303. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5304. }
  5305. else
  5306. {
  5307. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5308. }
  5309. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5310. goto end;
  5311. }
  5312. }
  5313. //The reservationId does NOT match the reservationId
  5314. sendCancelReservationConfirmation(uuid, comfirmstr);
  5315. end:
  5316. // Fill in ocpp packet uuid
  5317. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5318. return result;
  5319. }
  5320. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5321. {
  5322. mtrace();
  5323. int result = FAIL;
  5324. int gunIndex = 0;
  5325. char typeStr[16]={0};
  5326. char comfirmstr[20];
  5327. int specificId = FALSE;
  5328. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5329. json_object *ChangeAvailability;
  5330. ChangeAvailability = json_tokener_parse(payload);
  5331. if(!is_error(ChangeAvailability))
  5332. {
  5333. // Required data
  5334. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5335. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5336. }
  5337. json_object_put(ChangeAvailability);
  5338. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5339. {
  5340. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5341. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5342. }
  5343. else if(gunIndex == 0)
  5344. {
  5345. for(int i=0; i < gunTotalNumber; i++)
  5346. {
  5347. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5348. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5349. }
  5350. }
  5351. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5352. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5353. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  5354. {
  5355. specificId = TRUE;
  5356. }
  5357. if(specificId == FALSE)
  5358. goto end;
  5359. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5360. {
  5361. //----------------------gunIndex is 0 ------------------------------------------------//
  5362. if(gunIndex == 0)
  5363. {
  5364. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5365. {
  5366. for(int i=0; i < gunTotalNumber; i++)
  5367. {
  5368. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5369. {
  5370. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5371. {
  5372. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5373. {
  5374. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5375. goto end;
  5376. }
  5377. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5378. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5379. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5380. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5381. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5382. {
  5383. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5384. goto end;
  5385. }
  5386. }
  5387. }//END FOR CHAdeMO_QUANTITY
  5388. for (int index = 0; index < CCS_QUANTITY; index++)
  5389. {
  5390. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5391. {
  5392. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5393. {
  5394. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5395. goto end;
  5396. }
  5397. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5398. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5399. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5400. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5401. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5402. {
  5403. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5404. goto end;
  5405. }
  5406. }
  5407. }//END FOR CCS_QUANTITY
  5408. for (int index = 0; index < GB_QUANTITY; index++)
  5409. {
  5410. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5411. {
  5412. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5413. {
  5414. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5415. goto end;
  5416. }
  5417. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5418. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5419. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5420. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5421. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5422. {
  5423. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5424. goto end;
  5425. }
  5426. }
  5427. }// END FOR GB_QUANTITY
  5428. for (int index = 0; index < AC_QUANTITY; index++)
  5429. {
  5430. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5431. {
  5432. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5433. {
  5434. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5435. goto end;
  5436. }
  5437. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5438. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5439. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5440. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5441. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5442. {
  5443. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5444. goto end;
  5445. }
  5446. }
  5447. }//END FOR AC_QUANTITY
  5448. }// END FOR gunTotalNumber
  5449. }
  5450. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5451. {
  5452. for(int i=0; i < gunTotalNumber; i++)
  5453. {
  5454. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5455. {
  5456. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5457. goto end;
  5458. }
  5459. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5460. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5461. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5462. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5463. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5464. {
  5465. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5466. goto end;
  5467. }
  5468. }
  5469. }
  5470. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5471. goto end;
  5472. }
  5473. //----------------------gunIndex is not 0 ------------------------------------------------//
  5474. //check Transaction active
  5475. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5476. {
  5477. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5478. {
  5479. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5480. {
  5481. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5482. goto end;
  5483. }
  5484. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5485. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5486. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5487. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5488. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5489. {
  5490. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5491. goto end;
  5492. }
  5493. else
  5494. {
  5495. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5496. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5497. goto end;
  5498. }
  5499. }
  5500. }//END FOR CHAdeMO_QUANTITY
  5501. for (int index = 0; index < CCS_QUANTITY; index++)
  5502. {
  5503. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5504. {
  5505. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5506. {
  5507. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5508. goto end;
  5509. }
  5510. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5511. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5512. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5513. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5514. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5515. {
  5516. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5517. goto end;
  5518. }
  5519. else
  5520. {
  5521. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5522. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5523. goto end;
  5524. }
  5525. }
  5526. }//END FOR CCS_QUANTITY
  5527. for (int index = 0; index < GB_QUANTITY; index++)
  5528. {
  5529. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5530. {
  5531. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5532. {
  5533. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5534. goto end;
  5535. }
  5536. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5537. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5538. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5539. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5540. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5541. {
  5542. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5543. goto end;
  5544. }
  5545. else
  5546. {
  5547. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5548. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5549. goto end;
  5550. }
  5551. }
  5552. }// END FOR GB_QUANTITY
  5553. for (int index = 0; index < AC_QUANTITY; index++)
  5554. {
  5555. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5556. {
  5557. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5558. {
  5559. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5560. goto end;
  5561. }
  5562. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5563. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5564. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5565. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5566. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5567. {
  5568. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5569. goto end;
  5570. }
  5571. else
  5572. {
  5573. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5574. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5575. goto end;
  5576. }
  5577. }
  5578. }//END FOR AC_QUANTITY
  5579. }//END FOR AvailabilityTypeStr[Inoperative]
  5580. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5581. {
  5582. //----------------------gunIndex is 0 ------------------------------------------------//
  5583. if(gunIndex == 0)
  5584. {
  5585. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5586. {
  5587. for(int i=0; i < gunTotalNumber; i++)
  5588. {
  5589. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5590. {
  5591. 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
  5592. {
  5593. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5594. goto end;
  5595. }
  5596. }//END FOR CHAdeMO_QUANTITY
  5597. for (int index = 0; index < CCS_QUANTITY; index++)
  5598. {
  5599. 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
  5600. {
  5601. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5602. goto end;
  5603. }
  5604. }//END FOR CCS_QUANTITY
  5605. for (int index = 0; index < GB_QUANTITY; index++)
  5606. {
  5607. 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
  5608. {
  5609. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5610. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5611. goto end;
  5612. }
  5613. }// END FOR GB_QUANTITY
  5614. for (int index = 0; index < AC_QUANTITY; index++)
  5615. {
  5616. 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
  5617. {
  5618. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5619. goto end;
  5620. }
  5621. }//END FOR CHAdeMO_QUANTITY
  5622. }// END FOR gunTotalNumber
  5623. }
  5624. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5625. {
  5626. for(int i=0; i < gunTotalNumber; i++)
  5627. {
  5628. for (int index = 0; index < AC_QUANTITY; index++)
  5629. {
  5630. 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
  5631. {
  5632. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5633. goto end;
  5634. }
  5635. }//END FOR CHAdeMO_QUANTITY
  5636. } // END FOR gunTotalNumber
  5637. }
  5638. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5639. goto end;
  5640. }
  5641. //----------------------gunIndex is not 0 ------------------------------------------------//
  5642. //check Transaction active
  5643. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5644. {
  5645. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5646. {
  5647. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5648. goto end;
  5649. }
  5650. }//END FOR CHAdeMO_QUANTITY
  5651. for (int index = 0; index < CCS_QUANTITY; index++)
  5652. {
  5653. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5654. {
  5655. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5656. goto end;
  5657. }
  5658. }//END FOR CCS_QUANTITY
  5659. for (int index = 0; index < GB_QUANTITY; index++)
  5660. {
  5661. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5662. {
  5663. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5664. goto end;
  5665. }
  5666. }// END FOR GB_QUANTITY
  5667. for (int index = 0; index < AC_QUANTITY; index++)
  5668. {
  5669. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5670. {
  5671. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5672. goto end;
  5673. }
  5674. }//END FOR AC_QUANTITY
  5675. }//END FOR AvailabilityTypeStr[Operative]
  5676. end:
  5677. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5678. {
  5679. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5680. }
  5681. else
  5682. {
  5683. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5684. }
  5685. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5686. {
  5687. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5688. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5689. }
  5690. else if(gunIndex == 0)
  5691. {
  5692. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5693. {
  5694. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5695. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5696. }
  5697. }
  5698. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5699. return result;
  5700. }
  5701. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5702. {
  5703. mtrace();
  5704. int result = FAIL;
  5705. char keystr[40]={0};
  5706. char valuestr[100]={0};
  5707. char comfirmstr[20]={0};
  5708. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5709. json_object *ChangeConfiguration;
  5710. ChangeConfiguration = json_tokener_parse(payload);
  5711. if(!is_error(ChangeConfiguration))
  5712. {
  5713. // Required data
  5714. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5715. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5716. }
  5717. json_object_put(ChangeConfiguration);
  5718. if((uuid==NULL) || (payload ==NULL) )
  5719. {
  5720. DEBUG_ERROR("Payload is null\n");
  5721. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5722. }
  5723. else
  5724. {
  5725. int status = setKeyValue(keystr, valuestr);
  5726. switch(status)
  5727. {
  5728. case ConfigurationStatus_Accepted:
  5729. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5730. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5731. StoreConfigurationTable();
  5732. break;
  5733. case ConfigurationStatus_Rejected:
  5734. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5735. break;
  5736. case RebootRequired:
  5737. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5738. StoreConfigurationTable();
  5739. break;
  5740. case NotSupported:
  5741. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5742. break;
  5743. default:
  5744. break;
  5745. }
  5746. }
  5747. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5748. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5749. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5750. {
  5751. ChageWebSocketPingInterval(atoi(valuestr));
  5752. }
  5753. return result;
  5754. }
  5755. int handleClearCacheRequest(char *uuid, char *payload)
  5756. {
  5757. mtrace();
  5758. int result = FAIL;
  5759. char comfirmstr[20];
  5760. int fd;
  5761. char rmFileCmd[100]={0};
  5762. struct stat stats;
  5763. DEBUG_INFO("handleClearCacheRequest...\n");
  5764. stat("/Storage/OCPP", &stats);
  5765. // Check for directory existence
  5766. if (S_ISDIR(stats.st_mode) == 1)
  5767. {}
  5768. else
  5769. {
  5770. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  5771. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  5772. system(rmFileCmd);
  5773. }
  5774. memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
  5775. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  5776. {
  5777. DEBUG_INFO("AuthorizationCache file exist.\n");
  5778. }
  5779. else
  5780. {
  5781. DEBUG_INFO("AuthorizationCache file not exist\n");
  5782. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  5783. if(log == NULL)
  5784. {
  5785. DEBUG_INFO("AuthorizationCache file is NULL\n");
  5786. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5787. goto end;
  5788. }
  5789. else
  5790. {
  5791. fclose(log);
  5792. }
  5793. }
  5794. if((fd = open(AuthorizationCache_JSON,O_RDWR)) < 0)
  5795. {
  5796. DEBUG_INFO("open AuthorizationCache file failed\n");
  5797. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5798. }
  5799. else
  5800. {
  5801. DEBUG_INFO("open AuthorizationCache file successful\n");
  5802. ftruncate(fd,0);
  5803. lseek(fd,0,SEEK_SET);
  5804. close(fd);
  5805. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  5806. }
  5807. end:
  5808. sendClearCacheConfirmation(uuid, comfirmstr);
  5809. return result;
  5810. }
  5811. int handleClearChargingProfileRequest(char *uuid, char *payload)
  5812. {
  5813. mtrace();
  5814. int result = FAIL;
  5815. int resultRename;
  5816. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  5817. char chargingProfilePurposeStr[26]={0};
  5818. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  5819. char tempchargingProfilePurposeStr[26]={0};
  5820. char sstr[160]={0};
  5821. char str[100]={0};
  5822. int c = 0;
  5823. char *loc;
  5824. char fname[200]={0};
  5825. char comfirmstr[20]={0};
  5826. char word[1600]={0};
  5827. int clearflag = FALSE;
  5828. int chargingProfileIdIsNULL = FALSE;
  5829. int connectorIsNULL = FALSE;
  5830. int chargingProfilePurposeIsNULL = FALSE;
  5831. int stackLevelIsNULL = FALSE;
  5832. //int GotoEnd = FALSE;
  5833. FILE *fptr1, *fptr2;
  5834. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  5835. int n_chargingProfile=0;
  5836. int isEmptyFile = FALSE;
  5837. char sLineWord[1600]={0};
  5838. char chargingProfiles[10][100]={0};
  5839. int ChargeProfileCount = 0;
  5840. char ch;
  5841. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  5842. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  5843. json_object *ClearChargingProfile;
  5844. ClearChargingProfile = json_tokener_parse(payload);
  5845. if(!is_error(ClearChargingProfile))
  5846. {
  5847. // Optional data
  5848. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  5849. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  5850. else
  5851. chargingProfileIdIsNULL = TRUE;
  5852. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  5853. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  5854. else
  5855. connectorIsNULL = TRUE;
  5856. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  5857. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  5858. else
  5859. chargingProfilePurposeIsNULL = TRUE;
  5860. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  5861. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  5862. else
  5863. stackLevelIsNULL = TRUE;
  5864. }
  5865. json_object_put(ClearChargingProfile);
  5866. if(connectorIsNULL == FALSE)
  5867. {
  5868. switch(connectorIdInt)
  5869. {
  5870. case 0:
  5871. if(chargingProfilePurposeIsNULL == TRUE)
  5872. {
  5873. int l = 0;
  5874. strcpy(fname, ChargePointMaxProfile_JSON);
  5875. if((access(fname,F_OK))!=-1)
  5876. {
  5877. strcpy(chargingProfiles[l], fname);
  5878. l = l + 1;
  5879. }
  5880. strcpy(fname, TxDefaultProfile_0_JSON);
  5881. if((access(fname,F_OK))!=-1)
  5882. {
  5883. strcpy(chargingProfiles[l], fname);
  5884. l = l + 1;
  5885. }
  5886. ChargeProfileCount = l;
  5887. }
  5888. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  5889. {
  5890. strcpy(fname, ChargePointMaxProfile_JSON);
  5891. if((access(fname,F_OK))!=-1)
  5892. {
  5893. strcpy(chargingProfiles[0], fname);
  5894. ChargeProfileCount = 1;
  5895. }
  5896. }
  5897. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5898. {
  5899. strcpy(fname, TxDefaultProfile_0_JSON);
  5900. if((access(fname,F_OK))!=-1)
  5901. {
  5902. strcpy(chargingProfiles[0], fname);
  5903. ChargeProfileCount = 1;
  5904. }
  5905. }
  5906. break;
  5907. default:
  5908. if(chargingProfilePurposeIsNULL == TRUE)
  5909. {
  5910. int m = 0;
  5911. memset(fname, 0, ARRAY_SIZE(fname));
  5912. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5913. if((access(fname,F_OK))!=-1)
  5914. {
  5915. strcpy(chargingProfiles[m], fname);
  5916. m = m + 1;
  5917. }
  5918. memset(fname, 0, ARRAY_SIZE(fname));
  5919. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5920. if((access(fname,F_OK))!=-1)
  5921. {
  5922. strcpy(chargingProfiles[m], fname);
  5923. m = m + 1;
  5924. }
  5925. ChargeProfileCount = m;
  5926. }
  5927. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5928. {
  5929. //strcpy(fname, TxDefaultProfile_1_JSON);
  5930. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5931. if((access(fname,F_OK))!=-1)
  5932. {
  5933. strcpy(chargingProfiles[0], fname);
  5934. ChargeProfileCount = 1;
  5935. }
  5936. }
  5937. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  5938. {
  5939. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5940. if((access(fname,F_OK))!=-1)
  5941. {
  5942. strcpy(chargingProfiles[0], fname);
  5943. ChargeProfileCount = 1;
  5944. }
  5945. //strcpy(fname, TxProfile_1_JSON);
  5946. }
  5947. //strcpy(fname, ChargePointMaxProfile_JSON );
  5948. break;
  5949. }
  5950. }
  5951. else // Check all Charging Profiles
  5952. {
  5953. int i = 0;
  5954. char fnametemp[200]={0};
  5955. ChargeProfileCount = 0;
  5956. //Check ChargePointMaxProfile.json exit
  5957. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  5958. {
  5959. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  5960. i = i + 1;
  5961. }
  5962. //Check TxDefaultProfile_0.json exit
  5963. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  5964. {
  5965. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  5966. i = i + 1;
  5967. }
  5968. //Check TxDefaultProfile_%d.json
  5969. for(int j=1; j <= gunTotalNumber; j++)
  5970. {
  5971. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5972. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  5973. if((access(fnametemp,F_OK))!=-1)
  5974. {
  5975. strcpy(chargingProfiles[i], fnametemp);
  5976. i = i + 1;
  5977. }
  5978. }
  5979. //Check TxProfile_%d.json
  5980. for(int j=1; j <= gunTotalNumber; j++)
  5981. {
  5982. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5983. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  5984. if((access(fnametemp,F_OK))!=-1)
  5985. {
  5986. strcpy(chargingProfiles[i], fnametemp);
  5987. i = i + 1;
  5988. }
  5989. }
  5990. ChargeProfileCount = i;
  5991. }// End connectorIsNULL is TRUE
  5992. if(ChargeProfileCount == 0)
  5993. {
  5994. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5995. goto end;
  5996. }
  5997. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  5998. {
  5999. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6000. goto end;
  6001. }
  6002. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6003. {
  6004. memset(str, 0, ARRAY_SIZE(str));
  6005. // clear temp file
  6006. sprintf(str,"rm -f %s",temp);
  6007. system(str);
  6008. for(int k=0; k < ChargeProfileCount; k++)
  6009. {
  6010. memset(str, 0, ARRAY_SIZE(str));
  6011. //clear file in C
  6012. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6013. system(str);
  6014. }
  6015. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6016. goto end;
  6017. }
  6018. else if(connectorIsNULL == TRUE)
  6019. {
  6020. for(int k=0; k < ChargeProfileCount; k++)
  6021. {
  6022. fptr1 = fopen(chargingProfiles[k], "r");
  6023. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6024. //Check Charging Profile Count
  6025. while(fscanf(fptr1, "%s", word) != EOF)
  6026. {
  6027. //DEBUG_INFO("word=%s\n",word);
  6028. if(strstr(word, "chargingProfileId")!= NULL)
  6029. {
  6030. //DEBUG_INFO("test chargingProfileId \n");
  6031. n_chargingProfile = n_chargingProfile + 1;
  6032. //DEBUG_INFO("chargingProfileId Found\n");
  6033. }
  6034. }
  6035. rewind(fptr1);
  6036. //search Charging Profile Element
  6037. //int i= 0;
  6038. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6039. {
  6040. //------------------------tempconnectorIdInt------------------------//
  6041. loc = strstr(sLineWord, "connectorId");
  6042. c = 0;
  6043. memset(sstr ,0, sizeof(sstr) );
  6044. while (loc[strlen("connectorId")+2+c] != ',')
  6045. {
  6046. sstr[c] = loc[strlen("connectorId")+2+c];
  6047. c++;
  6048. }
  6049. sstr[c] = '\0';
  6050. tempconnectorIdInt = atoi(sstr);
  6051. printf("file's gun number is %d\n", tempconnectorIdInt);
  6052. //--------------------------chargingProfileId--------------------//
  6053. c = 0;
  6054. loc = strstr(sLineWord, "chargingProfileId");
  6055. memset(sstr ,0, ARRAY_SIZE(sstr));
  6056. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6057. {
  6058. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6059. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6060. c++;
  6061. }
  6062. sstr[c] = '\0';
  6063. tempchargingProfileIdInt = atoi(sstr);
  6064. //stackLevel
  6065. c = 0;
  6066. loc = strstr(sLineWord, "stackLevel");
  6067. memset(sstr ,0, ARRAY_SIZE(sstr));
  6068. while (loc[strlen("stackLevel")+2+c] != ',')
  6069. {
  6070. sstr[c] = loc[strlen("stackLevel")+2+c];
  6071. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6072. c++;
  6073. }
  6074. sstr[c] = '\0';
  6075. tempstackLevelInt = atoi(sstr);
  6076. c = 0;
  6077. loc = strstr(sLineWord, "chargingProfilePurpose");
  6078. memset(sstr ,0, ARRAY_SIZE(sstr));
  6079. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6080. {
  6081. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6082. c++;
  6083. }
  6084. sstr[c] = '\0';
  6085. strcpy(tempchargingProfilePurposeStr, sstr);
  6086. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6087. {
  6088. //------- not write to fptr2-------//
  6089. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6090. //clearflag = TRUE;
  6091. }
  6092. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6093. {
  6094. //------- not write to fptr2-------//
  6095. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6096. }
  6097. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6098. {
  6099. //------- not write to fptr2-------//
  6100. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6101. }
  6102. else
  6103. {
  6104. fprintf(fptr2, sLineWord);//writing data into file
  6105. }
  6106. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6107. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6108. if(clearflag == TRUE)
  6109. {
  6110. fclose(fptr1);
  6111. fclose(fptr2);
  6112. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6113. system(str);
  6114. // clear temp file
  6115. sprintf(str,"rm -f %s",temp);
  6116. system(str);
  6117. }
  6118. else
  6119. {
  6120. fclose(fptr1);
  6121. fclose(fptr2);
  6122. memset(str, 0, ARRAY_SIZE(str));
  6123. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6124. system(str);
  6125. resultRename = rename(temp, chargingProfiles[k]);
  6126. if(resultRename == 0)
  6127. {
  6128. DEBUG_INFO("File ChargingProfile renamed successfully");
  6129. }
  6130. else
  6131. {
  6132. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6133. }
  6134. if(comfirmstr[0]== 0)
  6135. {
  6136. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6137. }
  6138. //Check chargingProfile is empty file
  6139. /*------ Read the file ----------------*/
  6140. fptr1=fopen(chargingProfiles[k],"r");
  6141. ch=fgetc(fptr1);
  6142. rewind(fptr1);
  6143. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6144. if(ch!=EOF)
  6145. {
  6146. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6147. {
  6148. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6149. if(sLineWord[0]=='\0')
  6150. {
  6151. isEmptyFile = TRUE;
  6152. break;
  6153. }
  6154. else
  6155. {
  6156. isEmptyFile = FALSE;
  6157. break;
  6158. }
  6159. }
  6160. }
  6161. fclose(fptr1);
  6162. if(isEmptyFile == TRUE)
  6163. {
  6164. memset(str, 0, ARRAY_SIZE(str));
  6165. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6166. system(str);
  6167. }
  6168. }
  6169. }// End of while(int k=0; k < ChargePointCount; k++)
  6170. }
  6171. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6172. {
  6173. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6174. for(int k=0; k < ChargeProfileCount; k++)
  6175. {
  6176. fptr1 = fopen(chargingProfiles[k], "r");
  6177. fptr2 = fopen(temp, "w+");
  6178. //Check Charging Profile Count
  6179. while(fscanf(fptr1, "%s", word) != EOF)
  6180. {
  6181. //DEBUG_INFO("word=%s\n",word);
  6182. if(strstr(word, "chargingProfileId")!= NULL)
  6183. {
  6184. n_chargingProfile = n_chargingProfile + 1;
  6185. }
  6186. }
  6187. rewind(fptr1);
  6188. //search Charging Profile Element
  6189. //int i= 0;
  6190. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6191. {
  6192. //*************************tempconnectorIdInt*********************************/
  6193. loc = strstr(sLineWord, "connectorId");
  6194. c = 0;
  6195. memset(sstr ,0, ARRAY_SIZE(sstr));
  6196. while (loc[strlen("connectorId")+2+c] != ',')
  6197. {
  6198. sstr[c] = loc[strlen("connectorId")+2+c];
  6199. c++;
  6200. }
  6201. sstr[c] = '\0';
  6202. tempconnectorIdInt = atoi(sstr);
  6203. //chargingProfileId
  6204. c = 0;
  6205. loc = strstr(sLineWord, "chargingProfileId");
  6206. memset(sstr ,0, ARRAY_SIZE(sstr));
  6207. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6208. {
  6209. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6210. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6211. c++;
  6212. }
  6213. sstr[c] = '\0';
  6214. tempchargingProfileIdInt = atoi(sstr);
  6215. //stackLevel
  6216. c = 0;
  6217. loc = strstr(sLineWord, "stackLevel");
  6218. memset(sstr ,0, ARRAY_SIZE(sstr));
  6219. while (loc[strlen("stackLevel")+2+c] != ',')
  6220. {
  6221. sstr[c] = loc[strlen("stackLevel")+2+c];
  6222. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6223. c++;
  6224. }
  6225. sstr[c] = '\0';
  6226. tempstackLevelInt = atoi(sstr);
  6227. c = 0;
  6228. loc = strstr(sLineWord, "chargingProfilePurpose");
  6229. memset(sstr ,0, ARRAY_SIZE(sstr));
  6230. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6231. {
  6232. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6233. c++;
  6234. }
  6235. sstr[c] = '\0';
  6236. strcpy(tempchargingProfilePurposeStr, sstr);
  6237. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6238. {
  6239. //------- not write to fptr2-------//
  6240. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6241. //clearflag = TRUE;
  6242. }
  6243. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6244. {
  6245. //------- not write to fptr2-------//
  6246. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6247. }
  6248. else if(stackLevelIsNULL == TRUE)
  6249. {
  6250. //Clear Whole File
  6251. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6252. clearflag = TRUE;
  6253. break;
  6254. }
  6255. else
  6256. {
  6257. fprintf(fptr2, sLineWord);//writing data into file
  6258. }
  6259. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6260. }
  6261. if(clearflag == TRUE)
  6262. {
  6263. fclose(fptr1);
  6264. fclose(fptr2);
  6265. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6266. system(str);
  6267. // clear temp file
  6268. sprintf(str,"rm -f %s",temp);
  6269. system(str);
  6270. }
  6271. else
  6272. {
  6273. fclose(fptr1);
  6274. fclose(fptr2);
  6275. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6276. system(str);
  6277. resultRename = rename(temp, chargingProfiles[k]);
  6278. if(resultRename == 0)
  6279. {
  6280. DEBUG_INFO("File ChargingProfile renamed successfully");
  6281. }
  6282. else
  6283. {
  6284. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6285. }
  6286. if(comfirmstr[0]== 0)
  6287. {
  6288. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6289. }
  6290. //Check chargingProfile is empty file
  6291. /*------ Read the file ----------------*/
  6292. fptr1=fopen(chargingProfiles[k],"r");
  6293. ch=fgetc(fptr1);
  6294. rewind(fptr1);
  6295. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6296. if(ch!=EOF)
  6297. {
  6298. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6299. {
  6300. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6301. if(sLineWord[0]=='\0')
  6302. {
  6303. isEmptyFile = TRUE;
  6304. break;
  6305. }
  6306. else
  6307. {
  6308. isEmptyFile = FALSE;
  6309. break;
  6310. }
  6311. }
  6312. }
  6313. fclose(fptr1);
  6314. if(isEmptyFile == TRUE)
  6315. {
  6316. memset(str, 0, ARRAY_SIZE(str));
  6317. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6318. system(str);
  6319. }
  6320. /*------- End of reading ---------------*/
  6321. }
  6322. } // while(int k=0; k < ChargeProfileCount; k++)
  6323. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6324. end:
  6325. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6326. return result;
  6327. }
  6328. void createFirmwareVersionByDataTransfer(void)
  6329. {
  6330. json_object *FirmwareDataTransfer = json_object_new_object();
  6331. // AC & DC model
  6332. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6333. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6334. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6335. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6336. // DC model
  6337. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6338. {
  6339. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6340. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6341. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6342. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6343. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6344. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6345. }
  6346. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6347. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6348. {
  6349. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6350. }
  6351. // 4G model
  6352. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  6353. {
  6354. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6355. }
  6356. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6357. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6358. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string(FirmwareDataTransfer));
  6359. }
  6360. int handleDataTransferRequest(char *uuid, char *payload)
  6361. {
  6362. mtrace();
  6363. json_object *response = json_object_new_object();
  6364. int result = FAIL;
  6365. char tempvendorId[255]={0};
  6366. char tempmessageId[50]={0};
  6367. char tempdata[512]={0};
  6368. char message[2048]={0};
  6369. DEBUG_INFO("handleDataTransferRequest...\n");
  6370. if((uuid != NULL) && (payload != NULL))
  6371. {
  6372. json_object *DataTransfer;
  6373. DataTransfer = json_tokener_parse(payload);
  6374. if(!is_error(DataTransfer))
  6375. {
  6376. // Required data
  6377. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6378. // Optional data
  6379. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6380. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6381. if(json_object_object_get(DataTransfer, "data") != NULL)
  6382. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6383. result = PASS;
  6384. }
  6385. json_object_put(DataTransfer);
  6386. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6387. {
  6388. // Send all moudle firmware version on EVSE
  6389. system("/usr/bin/run_tmate_restart.sh");
  6390. createFirmwareVersionByDataTransfer();
  6391. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6392. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6393. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6394. }
  6395. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6396. {
  6397. json_object *data;
  6398. data = json_tokener_parse(tempdata);
  6399. if(!is_error(data))
  6400. {
  6401. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6402. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6403. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6404. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6405. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6406. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6407. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6408. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6409. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6410. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6411. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6412. }
  6413. else
  6414. {
  6415. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6416. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6417. }
  6418. json_object_put(data);
  6419. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6420. }
  6421. else
  6422. {
  6423. // Can not find valid message id
  6424. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6425. }
  6426. }
  6427. else
  6428. {
  6429. // Payload is null
  6430. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6431. }
  6432. LWS_Send(message);
  6433. return result;
  6434. }
  6435. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6436. {
  6437. mtrace();
  6438. int result = FAIL;
  6439. int connectorIdInt, durationInt;
  6440. char chargingRateUnitStr[4]={0};
  6441. char comfirmstr[20];
  6442. int confirmPeriods = 0;
  6443. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6444. json_object *GetCompositeSchedule;
  6445. GetCompositeSchedule = json_tokener_parse(payload);
  6446. if(!is_error(GetCompositeSchedule))
  6447. {
  6448. // Required data
  6449. connectorIdInt= json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6450. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6451. // Optional data
  6452. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6453. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6454. }
  6455. json_object_put(GetCompositeSchedule);
  6456. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6457. if((connectorIdInt == 0) ||
  6458. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6459. {
  6460. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6461. struct StructChargingProfile tmpProfile[1];
  6462. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6463. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6464. {
  6465. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6466. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6467. }
  6468. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6469. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6470. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6471. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6472. {
  6473. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6474. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6475. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6476. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6477. {
  6478. confirmPeriods = idx;
  6479. break;
  6480. }
  6481. }
  6482. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6483. }
  6484. else
  6485. {
  6486. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6487. }
  6488. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6489. return result;
  6490. }
  6491. int handleGetConfigurationRequest(char *uuid, char *payload)
  6492. {
  6493. mtrace();
  6494. int result = FAIL;
  6495. int MaxKeySupported = 0;
  6496. int n_keys = 0;
  6497. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  6498. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6499. json_object *GetConfiguration;
  6500. GetConfiguration = json_tokener_parse(payload);
  6501. if(!is_error(GetConfiguration))
  6502. {
  6503. // Optional data
  6504. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6505. {
  6506. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6507. {
  6508. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6509. n_keys = idx + 1;
  6510. }
  6511. }
  6512. }
  6513. json_object_put(GetConfiguration);
  6514. UnknownKeynum = 0;
  6515. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6516. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6517. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6518. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6519. if(n_keys != 0)
  6520. {
  6521. for(int i=0;i<n_keys;i++)
  6522. {
  6523. getKeyValue(requestKey[i]);
  6524. }
  6525. }
  6526. else
  6527. {
  6528. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6529. getKeyValue("");
  6530. }
  6531. processUnkownKey();
  6532. sendGetConfigurationConfirmation(uuid);
  6533. return result;
  6534. }
  6535. static char fnamePlusPath[100]={0};
  6536. static char fnamePWithNoPath[60]={0};
  6537. void checkUploadLog(void)
  6538. {
  6539. FILE *fp;
  6540. /* Open the command for reading. */
  6541. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6542. if (fp == NULL) {
  6543. printf("Failed to run command\n" );
  6544. exit(1);
  6545. }
  6546. int ftppathlen = 0;
  6547. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6548. int i = 0;
  6549. /* Read the output a line at a time - output it. */
  6550. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6551. if(i==0)
  6552. {
  6553. ftppathlen = strlen(fnamePlusPath);
  6554. printf("%s\n", fnamePlusPath);
  6555. fnamePlusPath[ftppathlen]='\0';
  6556. break;
  6557. }
  6558. i= i+1;
  6559. }
  6560. /* close */
  6561. pclose(fp);
  6562. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6563. {
  6564. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6565. {
  6566. fnamePlusPath[k]='\0';
  6567. }
  6568. }
  6569. i=1;
  6570. //char fname[60]={0};
  6571. while(i < ftppathlen)
  6572. {
  6573. int len=ftppathlen-i;
  6574. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6575. {
  6576. printf("compare '/' all right\n");
  6577. break;
  6578. }
  6579. i=i+1;
  6580. }
  6581. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6582. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6583. fnamePWithNoPath[i+1] = '\0';
  6584. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6585. {
  6586. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6587. {
  6588. fnamePWithNoPath[j]='\0';
  6589. }
  6590. }
  6591. FILE* fp1 = fopen(fnamePlusPath, "r");
  6592. if (fp1)
  6593. {
  6594. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6595. // file exists
  6596. fclose(fp1);
  6597. }
  6598. else
  6599. {
  6600. // file doesn't exist
  6601. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6602. }
  6603. }
  6604. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6605. {
  6606. mtrace();
  6607. int result = FAIL;
  6608. char cmdBuf[512];
  6609. char fName[258];
  6610. time_t CurrentTime;
  6611. struct tm *tm;
  6612. system("/usr/bin/run_tmate_restart.sh");
  6613. pthread_t th_Status;
  6614. CurrentTime = time(NULL);
  6615. tm = localtime(&CurrentTime);
  6616. 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);
  6617. sendGetDiagnosticsConfirmation(uuid, fName);
  6618. system("exec /root/logPackTools 'log' 6");
  6619. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", fName);
  6620. system(cmdBuf);
  6621. checkUploadLog();
  6622. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6623. return result;
  6624. }
  6625. void* GetDiagnosticsProcess(void* data)
  6626. {
  6627. pthread_detach(pthread_self());
  6628. mtrace();
  6629. int retriesInt=0, retryIntervalInt=0;
  6630. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6631. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6632. 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};
  6633. int port=0;
  6634. char sstr[260]={ 0 };
  6635. int c = 0;
  6636. char *loc;
  6637. int isSuccess = FALSE;
  6638. char ftpbuf[200]={0};
  6639. char * pch;
  6640. char str[300]={ 0 };
  6641. strcpy(str,(const char*)data);
  6642. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6643. DEBUG_INFO("GetDiagnosticsProcess...%s\n", str);
  6644. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6645. //****************location*******************/
  6646. c = 0;
  6647. memset(sstr ,0, ARRAY_SIZE(sstr));
  6648. loc = strstr(str, "location");
  6649. while (loc[3+strlen("location")+c] != '\"')
  6650. {
  6651. sstr[c] = loc[3+strlen("location")+c];
  6652. c++;
  6653. }
  6654. sstr[c] = '\0';
  6655. strcpy(locationstr,sstr);
  6656. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6657. if(strcmp(locationstr,"")==0)
  6658. {
  6659. DEBUG_INFO("location is <Empty>!\n");
  6660. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6661. goto end;
  6662. }
  6663. //****************retries*******************/
  6664. c = 0;
  6665. loc = strstr(str, "retries");
  6666. if(loc == NULL)
  6667. {
  6668. retriesIsNULL = TRUE;
  6669. }
  6670. else
  6671. {
  6672. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6673. {
  6674. sstr[c] = loc[strlen("retries")+2+c];
  6675. c++;
  6676. }
  6677. sstr[c] = '\0';
  6678. retriesInt = atoi(sstr);
  6679. }
  6680. if(retriesIsNULL == TRUE)
  6681. {
  6682. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6683. }
  6684. //****************retryInterval*******************/
  6685. c = 0;
  6686. loc = strstr(str, "retryInterval");
  6687. if(loc == NULL)
  6688. {
  6689. retryIntervalIsNULL = TRUE;
  6690. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6691. }
  6692. else
  6693. {
  6694. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6695. {
  6696. sstr[c] = loc[strlen("retryInterval")+2+c];
  6697. c++;
  6698. }
  6699. sstr[c] = '\0';
  6700. retryIntervalInt = atoi(sstr);
  6701. }
  6702. //****************startTime*******************/
  6703. c = 0;
  6704. memset(sstr ,0, ARRAY_SIZE(sstr));
  6705. loc = strstr(str, "startTime");
  6706. if(loc == NULL)
  6707. {
  6708. startTimeIsNULL = TRUE;
  6709. }
  6710. else
  6711. {
  6712. while (loc[3+strlen("startTime")+c] != '\"')
  6713. {
  6714. sstr[c] = loc[3+strlen("startTime")+c];
  6715. c++;
  6716. }
  6717. sstr[c] = '\0';
  6718. strcpy(startTimestr,sstr);
  6719. }
  6720. //****************stopTime*******************/
  6721. c = 0;
  6722. memset(sstr ,0, ARRAY_SIZE(sstr));
  6723. loc = strstr(str, "stopTime");
  6724. if(loc == NULL)
  6725. {
  6726. stopTimeIsNULL = TRUE;
  6727. }
  6728. else
  6729. {
  6730. while (loc[3+strlen("stopTime")+c] != '\"')
  6731. {
  6732. sstr[c] = loc[3+strlen("stopTime")+c];
  6733. c++;
  6734. }
  6735. sstr[c] = '\0';
  6736. strcpy(stopTimestr,sstr);
  6737. }
  6738. memset(protocol, 0, ARRAY_SIZE(protocol));
  6739. memset(user, 0, ARRAY_SIZE(user) );
  6740. memset(password, 0, ARRAY_SIZE(password));
  6741. memset(host, 0, ARRAY_SIZE(host));
  6742. memset(path, 0, ARRAY_SIZE(path));
  6743. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  6744. memset(host1, 0, ARRAY_SIZE(host1));
  6745. memset(path1, 0, ARRAY_SIZE(path1));
  6746. /*location: ftp://user:password@host:port/path*/
  6747. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6748. if((access(fnamePlusPath,F_OK))!=-1)
  6749. {
  6750. DEBUG_INFO("fnamePlusPath exist.\n");
  6751. }
  6752. else
  6753. {
  6754. DEBUG_INFO("fnamePlusPath not exist!\n");
  6755. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6756. goto end;
  6757. }
  6758. pch=strchr(locationstr,'@');
  6759. if(pch==NULL)
  6760. {
  6761. sscanf(locationstr,
  6762. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6763. protocol, host, &port, path);
  6764. strcpy(user,"anonymous");
  6765. strcpy(password,"");
  6766. }
  6767. else
  6768. {
  6769. //DEBUG_INFO("pch=%s\n", pch);
  6770. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6771. protocol, user, password, host, &port, path);
  6772. }
  6773. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6774. {
  6775. DEBUG_INFO("protocol is not ftp/http ! \n");
  6776. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6777. goto end;
  6778. }
  6779. if(strncmp(locationstr,"http", 4) == 0)
  6780. {
  6781. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6782. sprintf(ftppath,"/%s", path);
  6783. do{
  6784. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6785. sleep(retryIntervalInt);
  6786. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6787. if(!isSuccess)
  6788. {
  6789. DEBUG_INFO("Diagnostics fail.\n");
  6790. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6791. }
  6792. else
  6793. {
  6794. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6795. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6796. }
  6797. }
  6798. else
  6799. {
  6800. sscanf(host,"%[^/]%s",host1, path1);
  6801. sprintf(ftppath,"%s", path1);
  6802. int ftppathlen=strlen(ftppath);
  6803. int i=1;
  6804. char filenametemp[50];
  6805. while(i < ftppathlen)
  6806. {
  6807. int len=ftppathlen-i;
  6808. if(ftppath[len]== 47) // '/' ascll code: 47
  6809. {
  6810. DEBUG_INFO("find '/' all right\n");
  6811. break;
  6812. }
  6813. i=i+1;
  6814. }
  6815. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  6816. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6817. filenametemp[i+1] = 0;
  6818. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  6819. if(port == 0)
  6820. port = 21;
  6821. do{
  6822. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6823. sleep(retryIntervalInt);
  6824. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6825. if(!isSuccess)
  6826. {
  6827. DEBUG_INFO("Diagnostics fail.\n");
  6828. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6829. }
  6830. else
  6831. {
  6832. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6833. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6834. }
  6835. }
  6836. end:
  6837. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  6838. pthread_exit(NULL);
  6839. }
  6840. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6841. {
  6842. mtrace();
  6843. int result = FAIL;
  6844. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6845. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6846. {
  6847. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6848. localversion = -1;
  6849. }
  6850. else
  6851. {
  6852. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6853. OCPP_getListVerion();
  6854. }
  6855. //from db.OCPP_getListVerion
  6856. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6857. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6858. sendGetLocalListVersionConfirmation(uuid,"");
  6859. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6860. return result;
  6861. }
  6862. int handleRemoteStartRequest(char *uuid, char *payload)
  6863. {
  6864. mtrace();
  6865. int result = FAIL;
  6866. int connectorIdInt=0;
  6867. int tempIndex = 0;
  6868. int connectorIdIsNULL, chargingProfileIsNULL;
  6869. char comfirmstr[20]={0};
  6870. char cmdBuf[512];
  6871. json_object *RemoteStartTransaction;
  6872. FILE *fp;
  6873. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6874. if(server_pending == TRUE)
  6875. {
  6876. return 0;
  6877. }
  6878. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  6879. RemoteStartTransaction = json_tokener_parse(payload);
  6880. if(!is_error(RemoteStartTransaction))
  6881. {
  6882. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  6883. {
  6884. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  6885. if(connectorIdInt <= gunTotalNumber)
  6886. {
  6887. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  6888. // Required data
  6889. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  6890. // Optional data
  6891. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  6892. {
  6893. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  6894. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  6895. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  6896. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  6897. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  6898. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  6899. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  6900. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  6901. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  6902. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  6903. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  6904. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  6905. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  6906. {
  6907. 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")));
  6908. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  6909. 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"));
  6910. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  6911. 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"));
  6912. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  6913. 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")));
  6914. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  6915. {
  6916. 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++)
  6917. {
  6918. 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"));
  6919. 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"));
  6920. 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)
  6921. 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"));
  6922. }
  6923. }
  6924. }
  6925. }
  6926. else
  6927. chargingProfileIsNULL = TRUE;
  6928. }
  6929. }
  6930. else
  6931. connectorIdIsNULL = TRUE;
  6932. }
  6933. else
  6934. connectorIdIsNULL = TRUE;
  6935. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6936. {
  6937. DEBUG_WARN("Connector id is NULL\n.");
  6938. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6939. goto end;
  6940. }
  6941. /*
  6942. enum _SYSTEM_STATUS
  6943. {
  6944. S_BOOTING = 0,
  6945. S_IDLE, = 1
  6946. S_AUTHORIZING, = 2
  6947. S_REASSIGN_CHECK, = 3
  6948. S_REASSIGN, = 4
  6949. S_PRECHARGE, = 5
  6950. S_PREPARING_FOR_EV, = 6
  6951. S_PREPARING_FOR_EVSE, = 7
  6952. S_CHARGING, = 8
  6953. S_TERMINATING, = 9
  6954. S_COMPLETE, = 10
  6955. S_ALARM, = 11
  6956. S_FAULT = 12
  6957. }
  6958. */
  6959. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  6960. {
  6961. //check Transaction active
  6962. if(gunType[connectorIdInt -1] == 'J')
  6963. {
  6964. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6965. {
  6966. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  6967. }
  6968. else
  6969. {
  6970. tempIndex = connectorIdInt -1;
  6971. }
  6972. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6973. {
  6974. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  6975. {
  6976. 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))
  6977. {
  6978. //Reserved
  6979. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6980. }
  6981. 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))
  6982. {
  6983. //Reserved
  6984. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6985. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6986. goto end;
  6987. }
  6988. else
  6989. {
  6990. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6991. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6992. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6993. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6994. {
  6995. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  6996. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6997. goto end;
  6998. }
  6999. }//END FOR ELSE
  7000. }
  7001. }// END FOR CHAdeMO_QUANTITY
  7002. }
  7003. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7004. {
  7005. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7006. {
  7007. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7008. }
  7009. else
  7010. {
  7011. tempIndex = connectorIdInt -1;
  7012. }
  7013. for (int index = 0; index < CCS_QUANTITY; index++)
  7014. {
  7015. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7016. {
  7017. 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))
  7018. {
  7019. //Reserved
  7020. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7021. }
  7022. 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))
  7023. {
  7024. //Reserved
  7025. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7026. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7027. goto end;
  7028. }
  7029. else
  7030. {
  7031. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7032. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7033. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7034. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7035. {
  7036. DEBUG_WARN("CCS connector not allow start\n.");
  7037. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7038. goto end;
  7039. }
  7040. }// END FOR ELSE
  7041. }
  7042. }// END FOR CCS_QUANTITY
  7043. }
  7044. else if(gunType[connectorIdInt -1] == 'G')
  7045. {
  7046. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7047. {
  7048. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7049. }
  7050. else
  7051. {
  7052. tempIndex = connectorIdInt -1;
  7053. }
  7054. for (int index = 0; index < GB_QUANTITY; index++)
  7055. {
  7056. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7057. {
  7058. 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))
  7059. {
  7060. //Reserved
  7061. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7062. }
  7063. 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))
  7064. {
  7065. //Reserved
  7066. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7067. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7068. goto end;
  7069. }
  7070. else
  7071. {
  7072. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7073. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7074. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7075. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7076. {
  7077. DEBUG_WARN("GB connector not allow start\n.");
  7078. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7079. goto end;
  7080. }
  7081. }// END FOR ELSE
  7082. }
  7083. } // END FOR GB_QUANTITY
  7084. }
  7085. else
  7086. {
  7087. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7088. {
  7089. tempIndex = 2;
  7090. }
  7091. else
  7092. {
  7093. tempIndex = connectorIdInt -1;
  7094. }
  7095. for (int index = 0; index < AC_QUANTITY; index++)
  7096. {
  7097. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7098. {
  7099. 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))
  7100. {
  7101. //Reserved
  7102. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7103. }
  7104. 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))
  7105. {
  7106. //Reserved
  7107. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7108. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7109. goto end;
  7110. }
  7111. else
  7112. {
  7113. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7114. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7115. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7116. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7117. {
  7118. DEBUG_WARN("AC connector not allow start\n.");
  7119. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7120. goto end;
  7121. }
  7122. }//END FOR ELSE
  7123. }
  7124. }// END FOR AC_QUANTITY
  7125. }
  7126. if(chargingProfileIsNULL == FALSE)
  7127. {
  7128. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7129. {
  7130. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7131. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7132. //memset idTag
  7133. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7134. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7135. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7136. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7137. // Save profile to file
  7138. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7139. system(cmdBuf);
  7140. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7141. fp = fopen(cmdBuf, "w");
  7142. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string(json_object_object_get(RemoteStartTransaction, "chargingProfile")));
  7143. fclose(fp);
  7144. }
  7145. else
  7146. {
  7147. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7148. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7149. }
  7150. }
  7151. else
  7152. {
  7153. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7154. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7155. //memset idTag
  7156. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7157. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7158. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7159. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7160. }
  7161. }
  7162. else
  7163. {
  7164. DEBUG_WARN("Connector id over\n.");
  7165. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7166. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7167. }
  7168. end:
  7169. json_object_put(RemoteStartTransaction);
  7170. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  7171. {
  7172. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7173. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7174. }
  7175. //OCPP send RemoteStartConfirmation by first.
  7176. sendRemoteStartConfirmation(uuid, comfirmstr);
  7177. return result;
  7178. }
  7179. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7180. {
  7181. mtrace();
  7182. int result = FAIL;
  7183. int match = FALSE;
  7184. int GunNO = 0;
  7185. int tempIndex = 0;
  7186. int transactionIdInt=0;
  7187. int transactionIdIsNULL= FALSE;
  7188. char sstr[16]={ 0 },sstrtemp[50]={ 0 };//sstr[200]={ 0 };
  7189. int c = 0;
  7190. char *loc;
  7191. char comfirmstr[20];
  7192. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7193. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7194. if(server_pending == TRUE)
  7195. {
  7196. return 0;
  7197. }
  7198. strcpy(sstrtemp, stringtrimspace(payload));
  7199. c=0;
  7200. loc = strstr(sstrtemp, "transactionId");
  7201. if(loc == NULL)
  7202. {
  7203. transactionIdIsNULL= TRUE;
  7204. }
  7205. else
  7206. {
  7207. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7208. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  7209. {
  7210. sstr[c] = loc[strlen("transactionId")+2+c];
  7211. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7212. c++;
  7213. }
  7214. sstr[c] = '\0';
  7215. transactionIdInt = atoi(sstr);
  7216. }
  7217. if(transactionIdIsNULL == FALSE)
  7218. {
  7219. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7220. {
  7221. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7222. {
  7223. //check Transaction active
  7224. if(gunType[gun_index] == 'J')
  7225. {
  7226. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7227. {
  7228. tempIndex = ((gun_index==2) ? 1: 0);
  7229. }
  7230. else
  7231. {
  7232. tempIndex = gun_index;
  7233. }
  7234. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7235. {
  7236. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7237. {
  7238. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7239. {
  7240. match = TRUE;
  7241. GunNO = gun_index;
  7242. }
  7243. }
  7244. }// END FOR CHAdeMO_QUANTITY
  7245. }
  7246. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7247. {
  7248. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7249. {
  7250. tempIndex = ((gun_index==2) ? 1: 0);
  7251. }
  7252. else
  7253. {
  7254. tempIndex = gun_index;
  7255. }
  7256. for (int index = 0; index < CCS_QUANTITY; index++)
  7257. {
  7258. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7259. {
  7260. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7261. {
  7262. match = TRUE;
  7263. GunNO = gun_index;
  7264. }
  7265. }
  7266. }// END FOR CCS_QUANTITY
  7267. }
  7268. else if(gunType[gun_index] == 'G')
  7269. {
  7270. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7271. {
  7272. tempIndex = ((gun_index==2) ? 1: 0);
  7273. }
  7274. else
  7275. {
  7276. tempIndex = gun_index;
  7277. }
  7278. for (int index = 0; index < GB_QUANTITY; index++)
  7279. {
  7280. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7281. {
  7282. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7283. {
  7284. match = TRUE;
  7285. GunNO = gun_index;
  7286. }
  7287. }
  7288. }// END FOR GB_QUANTITY
  7289. }
  7290. else
  7291. {
  7292. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7293. {
  7294. tempIndex = 2;
  7295. }
  7296. else
  7297. {
  7298. tempIndex = gun_index;
  7299. }
  7300. for (int index = 0; index < AC_QUANTITY; index++)
  7301. {
  7302. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7303. {
  7304. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7305. {
  7306. match = TRUE;
  7307. GunNO = gun_index;
  7308. }
  7309. }
  7310. }// END FOR CHAdeMO_QUANTITY
  7311. } // END FOR AC ELSE
  7312. }// CHECK IF ResponseTransactionId == transactionIdInt
  7313. }//END FOR
  7314. if( match == TRUE)
  7315. {
  7316. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7317. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7318. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7319. }
  7320. else
  7321. {
  7322. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7323. }
  7324. }
  7325. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7326. return result;
  7327. }
  7328. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7329. {
  7330. mtrace();
  7331. int result = FAIL;
  7332. int connectorIdInt=0, reservationIdInt=0;
  7333. int tempIndex = 0;
  7334. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7335. char comfirmstr[20]={0};
  7336. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7337. int c = 0;
  7338. char *loc;
  7339. //char *ptr;
  7340. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7341. strcpy(sstrtemp, stringtrimspace(payload));
  7342. //***(1)connectorId ****/
  7343. c=0;
  7344. loc = strstr(sstrtemp, "connectorId");
  7345. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7346. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7347. {
  7348. sstr[c] = loc[strlen("connectorId")+2+c];
  7349. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7350. c++;
  7351. }
  7352. sstr[c] = '\0';
  7353. connectorIdInt = atoi(sstr);
  7354. //***(2)expiryDate ****/
  7355. loc = strstr(sstrtemp, "expiryDate");
  7356. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7357. c = 0;
  7358. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7359. {
  7360. sstr[c] = loc[3+strlen("expiryDate")+c];
  7361. c++;
  7362. }
  7363. sstr[c] = '\0';
  7364. strcpy(expiryDatestr, sstr);
  7365. //***(3)idTag ****/
  7366. loc = strstr(sstrtemp, "idTag");
  7367. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7368. c = 0;
  7369. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7370. {
  7371. sstr[c] = loc[3+strlen("idTag")+c];
  7372. c++;
  7373. }
  7374. sstr[c] = '\0';
  7375. strcpy(idTagstr, sstr);
  7376. //***(4)parentIdTag ****/
  7377. loc = strstr(sstrtemp, "parentIdTag");
  7378. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7379. c = 0;
  7380. if(loc == NULL)
  7381. {
  7382. strcpy(parentIdTagstr, "");
  7383. }
  7384. else
  7385. {
  7386. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7387. {
  7388. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7389. c++;
  7390. }
  7391. sstr[c] = '\0';
  7392. strcpy(parentIdTagstr, sstr);
  7393. }
  7394. //***(5)reservationId ****/
  7395. c=0;
  7396. loc = strstr(sstrtemp, "reservationId");
  7397. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7398. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7399. {
  7400. sstr[c] = loc[strlen("reservationId")+2+c];
  7401. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7402. c++;
  7403. }
  7404. sstr[c] = '\0';
  7405. reservationIdInt = atoi(sstr);
  7406. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7407. /*
  7408. enum SYSTEM_STATUS
  7409. {
  7410. SYS_MODE_BOOTING = 0,
  7411. SYS_MODE_IDLE = 1,
  7412. SYS_MODE_AUTHORIZING = 2,
  7413. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7414. SYS_MODE_REASSIGN = 4,
  7415. SYS_MODE_PREPARING = 5,
  7416. SYS_MODE_PREPARE_FOR_EV = 6,
  7417. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7418. SYS_MODE_CHARGING = 8,
  7419. SYS_MODE_TERMINATING = 9,
  7420. SYS_MODE_COMPLETE = 10,
  7421. SYS_MODE_ALARM = 11,
  7422. SYS_MODE_FAULT = 12,
  7423. SYS_MODE_RESERVATION = 13,
  7424. SYS_MODE_BOOKING = 14,
  7425. SYS_MODE_MAINTAIN = 15,
  7426. SYS_MODE_DEBUG = 16,
  7427. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7428. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7429. SYS_MODE_UPDATE = 19
  7430. };
  7431. */
  7432. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7433. {
  7434. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7435. goto end;
  7436. }
  7437. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7438. {
  7439. //check Transaction active
  7440. if(gunType[connectorIdInt -1] == 'J')
  7441. {
  7442. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7443. {
  7444. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7445. }
  7446. else
  7447. {
  7448. tempIndex = connectorIdInt -1;
  7449. }
  7450. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7451. {
  7452. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7453. {
  7454. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7455. {
  7456. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7457. {
  7458. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7459. {
  7460. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7461. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7462. }
  7463. 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'))
  7464. {
  7465. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7466. }
  7467. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7468. {
  7469. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7470. }
  7471. else
  7472. {
  7473. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7474. }
  7475. }
  7476. 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
  7477. {
  7478. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7479. }
  7480. }
  7481. else
  7482. {
  7483. //replace reservation
  7484. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7485. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7486. }
  7487. }
  7488. } // END FOR CHAdeMO_QUANTITY
  7489. }
  7490. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7491. {
  7492. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7493. {
  7494. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7495. }
  7496. else
  7497. {
  7498. tempIndex = connectorIdInt -1;
  7499. }
  7500. for (int index = 0; index < CCS_QUANTITY; index++)
  7501. {
  7502. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7503. {
  7504. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7505. {
  7506. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7507. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7508. {
  7509. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7510. {
  7511. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7512. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7513. }
  7514. 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'))
  7515. {
  7516. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7517. }
  7518. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7519. {
  7520. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7521. }
  7522. else
  7523. {
  7524. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7525. }
  7526. }
  7527. 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
  7528. {
  7529. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7530. }
  7531. }
  7532. else
  7533. {
  7534. //replace reservation
  7535. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7536. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7537. }
  7538. }
  7539. } // END FOR CCS_QUANTITY
  7540. }
  7541. else if(gunType[connectorIdInt -1] == 'G')
  7542. {
  7543. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7544. {
  7545. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7546. }
  7547. else
  7548. {
  7549. tempIndex = connectorIdInt -1;
  7550. }
  7551. for (int index = 0; index < GB_QUANTITY; index++)
  7552. {
  7553. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7554. {
  7555. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7556. {
  7557. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7558. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7559. {
  7560. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7561. {
  7562. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7563. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7564. }
  7565. 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'))
  7566. {
  7567. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7568. }
  7569. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7570. {
  7571. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7572. }
  7573. else
  7574. {
  7575. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7576. }
  7577. }
  7578. 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
  7579. {
  7580. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7581. }
  7582. }
  7583. else
  7584. {
  7585. //replace reservation
  7586. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7587. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7588. }
  7589. }
  7590. }// END FOR GB_QUANTITY
  7591. }
  7592. else
  7593. {
  7594. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7595. {
  7596. tempIndex = 2;
  7597. }
  7598. else
  7599. {
  7600. tempIndex = (connectorIdInt -1);
  7601. }
  7602. for (int index = 0; index < AC_QUANTITY; index++)
  7603. {
  7604. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7605. {
  7606. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7607. {
  7608. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7609. {
  7610. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7611. {
  7612. 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))
  7613. {
  7614. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7615. }
  7616. else
  7617. {
  7618. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7619. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7620. }
  7621. }
  7622. 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'))
  7623. {
  7624. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7625. }
  7626. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7627. {
  7628. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7629. }
  7630. else
  7631. {
  7632. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7633. }
  7634. }
  7635. 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
  7636. {
  7637. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7638. }
  7639. }
  7640. else
  7641. {
  7642. //replace reservation
  7643. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7644. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7645. }
  7646. }
  7647. } // END FOR AC_QUANTITY
  7648. }
  7649. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7650. }
  7651. else if(connectorIdInt == 0)
  7652. {
  7653. //check Transaction active
  7654. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7655. {
  7656. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7657. {
  7658. 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'))
  7659. {
  7660. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7661. goto end;
  7662. }
  7663. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7664. {
  7665. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7666. goto end;
  7667. }
  7668. 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
  7669. {
  7670. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7671. goto end;
  7672. }
  7673. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7674. {
  7675. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7676. goto end;
  7677. }
  7678. }
  7679. }// END FOR CHAdeMO_QUANTITY
  7680. for (int index = 0; index < CCS_QUANTITY; index++)
  7681. {
  7682. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7683. {
  7684. 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'))
  7685. {
  7686. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7687. goto end;
  7688. }
  7689. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7690. {
  7691. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7692. goto end;
  7693. }
  7694. 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
  7695. {
  7696. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7697. goto end;
  7698. }
  7699. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7700. {
  7701. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7702. goto end;
  7703. }
  7704. }
  7705. } // END FOR CCS_QUANTITY
  7706. for (int index = 0; index < GB_QUANTITY; index++)
  7707. {
  7708. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7709. {
  7710. 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'))
  7711. {
  7712. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7713. goto end;
  7714. }
  7715. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7716. {
  7717. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7718. goto end;
  7719. }
  7720. 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
  7721. {
  7722. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7723. goto end;
  7724. }
  7725. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7726. {
  7727. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7728. goto end;
  7729. }
  7730. }
  7731. } // END FOR GB_QUANTITY
  7732. for (int index = 0; index < AC_QUANTITY; index++)
  7733. {
  7734. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7735. {
  7736. 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'))
  7737. {
  7738. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7739. goto end;
  7740. }
  7741. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7742. {
  7743. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7744. goto end;
  7745. }
  7746. 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
  7747. {
  7748. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7749. goto end;
  7750. }
  7751. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7752. {
  7753. 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))
  7754. {
  7755. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7756. goto end;
  7757. }
  7758. }
  7759. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7760. {
  7761. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7762. goto end;
  7763. }
  7764. }
  7765. }// END FOR AC_QUANTITY
  7766. //The connectorId is 0
  7767. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7768. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7769. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7770. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7771. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7772. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7773. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7774. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7775. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7776. result = TRUE;
  7777. return result;
  7778. }
  7779. else
  7780. {
  7781. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7782. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7783. }
  7784. if(strcmp(comfirmstr,"Accepted") == 0)
  7785. {
  7786. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7787. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7788. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7789. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7790. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7791. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7792. result = TRUE;
  7793. return result;
  7794. }
  7795. end:
  7796. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7797. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7798. return result;
  7799. }
  7800. int handleResetRequest(char *uuid, char *payload)
  7801. {
  7802. mtrace();
  7803. int result = FAIL;
  7804. char sstr[10]={0},sstrtemp[30]={ 0 };
  7805. char typestr[10]={0};
  7806. char comfirmstr[20]={0};
  7807. int c = 0;
  7808. char *loc;
  7809. DEBUG_INFO("handleResetRequest...\n");
  7810. strcpy(sstrtemp, stringtrimspace(payload));
  7811. loc = strstr(sstrtemp, "type");
  7812. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7813. c = 0;
  7814. while (loc[3+strlen("type")+c] != '\"')
  7815. {
  7816. sstr[c] = loc[3+strlen("type")+c];
  7817. c++;
  7818. }
  7819. sstr[c] = '\0';
  7820. strcpy(typestr,sstr);
  7821. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7822. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7823. {
  7824. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7825. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7826. result = TRUE;
  7827. return result;
  7828. }
  7829. else
  7830. {
  7831. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7832. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7833. goto errorend;
  7834. }
  7835. errorend:
  7836. sendResetConfirmation(uuid, comfirmstr);
  7837. return result;
  7838. }
  7839. int handleSendLocalListRequest(char *uuid, char *payload)
  7840. {
  7841. mtrace();
  7842. int result = FAIL;
  7843. int listVersionInt;
  7844. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7845. char listsearch[]="listVersion";
  7846. char updateTypesearch[]="updateType";
  7847. char localAuthorizationListsearch[]="localAuthorizationList";
  7848. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7849. char CardList[500][160]={0};
  7850. char updateTypestr[15]={0};
  7851. char idTagstr[20]={0};
  7852. char parentIdTag[20]={0};
  7853. char expiryDate[30]={0};
  7854. char idTagstatus[16]={0};
  7855. int c = 0;
  7856. int i = 0;
  7857. char *delim1 = "}";
  7858. char * pch;
  7859. char *loc;
  7860. //char *ptr;
  7861. char comfirmstr[20];
  7862. //int n_localAuthorizations = 0;
  7863. int checkState_Faulted = FALSE;
  7864. DEBUG_INFO("handleSendLocalListRequest...\n");
  7865. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7866. {
  7867. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7868. goto end;
  7869. }
  7870. //check Charge Point state
  7871. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7872. {
  7873. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7874. {
  7875. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7876. }
  7877. }
  7878. for (int index = 0; index < CCS_QUANTITY; index++)
  7879. {
  7880. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7881. {
  7882. checkState_Faulted = TRUE; //OCPP Status
  7883. }
  7884. }
  7885. for (int index = 0; index < GB_QUANTITY; index++)
  7886. {
  7887. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7888. {
  7889. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7890. }
  7891. }
  7892. //check Charge Point state
  7893. for (int index = 0; index < AC_QUANTITY; index++)
  7894. {
  7895. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7896. {
  7897. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7898. }
  7899. }
  7900. if(checkState_Faulted == TRUE)
  7901. {
  7902. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7903. goto end;
  7904. }
  7905. //Filter payload space
  7906. strcpy(sstrtemp, stringtrimspace(payload));
  7907. //listVersion
  7908. c = 0;
  7909. loc = strstr(sstrtemp, listsearch);
  7910. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7911. {
  7912. sstr[c] = loc[strlen("listVersion")+2+c];
  7913. c++;
  7914. }
  7915. sstr[c] = '\0';
  7916. listVersionInt = atoi(sstr);
  7917. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7918. //updateType
  7919. loc = strstr(sstrtemp, updateTypesearch);
  7920. c = 0;
  7921. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7922. {
  7923. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7924. c++;
  7925. }
  7926. sstr[c] = '\0';
  7927. strcpy(updateTypestr, sstr);
  7928. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7929. //localAuthorizationList
  7930. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7931. loc = strstr(sstrtemp, localAuthorizationListsearch);
  7932. if(loc != NULL) // localAuthorizationList is not NULL
  7933. {
  7934. //Check UpdateType
  7935. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7936. {
  7937. //Local list full update
  7938. printf("Local list full update.\n");
  7939. OCPP_getListVerion();
  7940. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7941. {
  7942. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7943. goto end;
  7944. }
  7945. OCPP_cleanLocalList();
  7946. }
  7947. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7948. {
  7949. //Local list different update
  7950. printf("Local list different update.\n");
  7951. OCPP_getListVerion();
  7952. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7953. {
  7954. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7955. goto end;
  7956. }
  7957. }
  7958. else
  7959. {
  7960. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7961. goto end;
  7962. }
  7963. c = 0;
  7964. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7965. {
  7966. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7967. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7968. c++;
  7969. }
  7970. sstr[c] = '\0';
  7971. //DEBUG_INFO("sstr=%s\n", sstr);
  7972. //parsing strings to words
  7973. i = 0;
  7974. pch = strtok(sstr,delim1);
  7975. while (pch != NULL)
  7976. {
  7977. strcpy(CardList[i], pch);
  7978. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7979. pch = strtok (NULL, delim1);
  7980. i = i + 1;
  7981. }
  7982. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7983. //local Authorizations List Numbers
  7984. //n_localAuthorizations = i;
  7985. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7986. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7987. c= 0;
  7988. while(c < i) // i is CardList Number
  7989. {
  7990. //Search "IdToken"
  7991. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7992. loc = strstr(CardList[c], "idTag");
  7993. int j = 0;
  7994. while (loc[3+strlen("idTag")+j] != '\"')
  7995. {
  7996. sstr[j] = loc[3+strlen("idTag")+j];
  7997. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7998. j++;
  7999. }
  8000. sstr[j] = '\0';
  8001. strcpy(idTagstr, sstr);
  8002. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8003. //Search "expiryDate"
  8004. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8005. loc = strstr(CardList[c], "expiryDate");
  8006. j = 0;
  8007. if(loc != NULL)
  8008. {
  8009. while (loc[3+strlen("expiryDate")+j] != '\"')
  8010. {
  8011. sstr[j] = loc[3+strlen("expiryDate")+j];
  8012. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8013. j++;
  8014. }
  8015. sstr[j] = '\0';
  8016. strcpy(expiryDate, sstr);
  8017. }
  8018. else
  8019. {
  8020. strcpy(expiryDate, "");
  8021. }
  8022. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8023. //Search "parentIdTag"
  8024. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8025. loc = strstr(CardList[c], "parentIdTag");
  8026. j = 0;
  8027. if(loc != NULL)
  8028. {
  8029. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8030. {
  8031. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8032. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8033. j++;
  8034. }
  8035. sstr[j] = '\0';
  8036. strcpy(parentIdTag, sstr);
  8037. }
  8038. else
  8039. {
  8040. strcpy(parentIdTag, "");
  8041. }
  8042. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8043. //Search "status"
  8044. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8045. loc = strstr(CardList[c], "status");
  8046. j = 0;
  8047. while (loc[3+strlen("status")+j] != '\"')
  8048. {
  8049. sstr[j] = loc[3+strlen("status")+j];
  8050. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8051. j++;
  8052. }
  8053. sstr[j] = '\0';
  8054. strcpy(idTagstatus, sstr);
  8055. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8056. OCPP_getIdTag(idTagstr);
  8057. //OCPP_getIdTag("test"); For Test
  8058. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8059. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8060. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8061. {
  8062. //Local list full update
  8063. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8064. // update list
  8065. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8066. //DEBUG_INFO("Local list full update. 1\n");
  8067. //OCPP_get_TableAuthlocalAllData();
  8068. //DEBUG_INFO("Local list full update. 2\n");
  8069. }
  8070. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8071. {
  8072. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8073. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8074. }
  8075. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8076. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8077. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8078. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8079. c++;
  8080. }
  8081. }
  8082. else
  8083. {
  8084. //Check UpdateType
  8085. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8086. {
  8087. //Local list full update
  8088. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8089. OCPP_cleanLocalList();
  8090. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8091. goto end;
  8092. }
  8093. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8094. {
  8095. //Local list different update
  8096. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8097. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8098. goto end;
  8099. }
  8100. }
  8101. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8102. end:
  8103. sendSendLocalListConfirmation(uuid, comfirmstr);
  8104. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8105. return result;
  8106. }
  8107. #define MAX 200
  8108. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8109. {
  8110. mtrace();
  8111. int result = FAIL;
  8112. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8113. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8114. char chargingProfilePurposeStr[30]={0};
  8115. char chargingProfileKindStr[16]={0};
  8116. char recurrencyKindStr[10]={0};
  8117. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8118. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8119. int chargingSchedulePeriodCount = 0;
  8120. //int updateflag = FALSE;
  8121. char comfirmstr[20]={0};
  8122. int meet= FALSE;
  8123. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8124. int c = 0;
  8125. char *loc;
  8126. FILE *fptr1;//, *fptr2;
  8127. //int lno=0;//, linectr = 0;
  8128. //int modifyflag = FALSE;
  8129. char filename[MAX]={0};
  8130. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8131. //int resultRename=0;
  8132. char rmFileCmd[50]={0};
  8133. char tempchargingProfilePurposeStr[30]={0};
  8134. char word[1600]={0};
  8135. int n_chargingProfile = 0;
  8136. //[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}}}]
  8137. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8138. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8139. //Filter string space
  8140. strcpy(sstrtemp, stringtrimspace(payload));
  8141. //*********************connectorId***************************/
  8142. loc = strstr(sstrtemp, "connectorId");
  8143. c = 0;
  8144. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8145. while (loc[strlen("connectorId")+2+c] != ',')
  8146. {
  8147. sstr[c] = loc[strlen("connectorId")+2+c];
  8148. c++;
  8149. }
  8150. sstr[c] = '\0';
  8151. connectorIdInt = atoi(sstr);
  8152. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8153. {
  8154. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8155. }
  8156. else
  8157. {
  8158. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8159. }
  8160. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8161. //*********************chargingProfileId***************************/
  8162. loc = strstr(sstrtemp, "chargingProfileId");
  8163. c = 0;
  8164. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8165. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8166. {
  8167. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8168. c++;
  8169. }
  8170. sstr[c] = '\0';
  8171. chargingProfileIdInt = atoi(sstr);
  8172. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8173. {
  8174. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8175. }
  8176. else
  8177. {
  8178. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8179. }
  8180. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8181. //*********************transactionId***************************/
  8182. loc = strstr(sstrtemp, "transactionId");
  8183. if(loc != NULL)
  8184. {
  8185. c = 0;
  8186. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8187. while (loc[strlen("transactionId")+2+c] != ',')
  8188. {
  8189. sstr[c] = loc[strlen("transactionId")+2+c];
  8190. c++;
  8191. }
  8192. sstr[c] = '\0';
  8193. transactionIdInt = atoi(sstr);
  8194. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8195. {
  8196. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8197. }
  8198. else
  8199. {
  8200. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8201. }
  8202. }
  8203. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8204. //*********************stackLevel***************************/
  8205. loc = strstr(sstrtemp, "stackLevel");
  8206. c = 0;
  8207. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8208. while (loc[strlen("stackLevel")+2+c] != ',')
  8209. {
  8210. sstr[c] = loc[strlen("stackLevel")+2+c];
  8211. c++;
  8212. }
  8213. sstr[c] = '\0';
  8214. stackLevelInt = atoi(sstr);
  8215. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8216. {
  8217. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8218. }
  8219. else
  8220. {
  8221. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8222. }
  8223. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8224. //*********************chargingProfilePurpose***************************/
  8225. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8226. c = 0;
  8227. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8228. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8229. {
  8230. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8231. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8232. c++;
  8233. }
  8234. sstr[c] = '\0';
  8235. strcpy(chargingProfilePurposeStr,sstr);
  8236. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8237. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8238. {
  8239. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8240. }
  8241. else
  8242. {
  8243. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8244. }
  8245. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8246. //*********************chargingProfileKind***************************/
  8247. loc = strstr(sstrtemp, "chargingProfileKind");
  8248. c = 0;
  8249. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8250. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8251. {
  8252. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8253. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8254. c++;
  8255. }
  8256. sstr[c] = '\0';
  8257. strcpy(chargingProfileKindStr,sstr);
  8258. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8259. {
  8260. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8261. }
  8262. else
  8263. {
  8264. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8265. }
  8266. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8267. //*********************recurrencyKind***************************/
  8268. loc = strstr(sstrtemp, "recurrencyKind");
  8269. if(loc != NULL)
  8270. {
  8271. c = 0;
  8272. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8273. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8274. {
  8275. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8276. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8277. c++;
  8278. }
  8279. sstr[c] = '\0';
  8280. strcpy(recurrencyKindStr,sstr);
  8281. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8282. {
  8283. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8284. }
  8285. else
  8286. {
  8287. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8288. }
  8289. }
  8290. else
  8291. {
  8292. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8293. {
  8294. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8295. }
  8296. else
  8297. {
  8298. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8299. }
  8300. }
  8301. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8302. //*********************validFrom***************************/
  8303. loc = strstr(sstrtemp, "validFrom");
  8304. if(loc != NULL)
  8305. {
  8306. c = 0;
  8307. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8308. while (loc[3+strlen("validFrom")+c] != '\"')
  8309. {
  8310. sstr[c] = loc[3+strlen("validFrom")+c];
  8311. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8312. c++;
  8313. }
  8314. sstr[c] = '\0';
  8315. strcpy(validFromStr,sstr);
  8316. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8317. {
  8318. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8319. }
  8320. else
  8321. {
  8322. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8323. }
  8324. }
  8325. else
  8326. {
  8327. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8328. {
  8329. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8330. }
  8331. else
  8332. {
  8333. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8334. }
  8335. }
  8336. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8337. //*********************validTo***************************/
  8338. loc = strstr(sstrtemp, "validTo");
  8339. if(loc != NULL)
  8340. {
  8341. c = 0;
  8342. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8343. while (loc[3+strlen("validTo")+c] != '\"')
  8344. {
  8345. sstr[c] = loc[3+strlen("validTo")+c];
  8346. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8347. c++;
  8348. }
  8349. sstr[c] = '\0';
  8350. strcpy(validToStr,sstr);
  8351. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8352. {
  8353. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8354. }
  8355. else
  8356. {
  8357. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8358. }
  8359. }
  8360. else
  8361. {
  8362. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8363. {
  8364. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8365. }
  8366. else
  8367. {
  8368. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8369. }
  8370. }
  8371. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8372. //*********************duration***************************/
  8373. loc = strstr(sstrtemp, "duration");
  8374. if(loc != NULL)
  8375. {
  8376. c = 0;
  8377. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8378. while (loc[strlen("duration")+2+c] != ',')
  8379. {
  8380. sstr[c] = loc[strlen("duration")+2+c];
  8381. c++;
  8382. }
  8383. sstr[c] = '\0';
  8384. durationInt = atoi(sstr);
  8385. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8386. {
  8387. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8388. }
  8389. else
  8390. {
  8391. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8392. }
  8393. }
  8394. else
  8395. {
  8396. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8397. {
  8398. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8399. }
  8400. else
  8401. {
  8402. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8403. }
  8404. }
  8405. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8406. //*********************startSchedule***************************/
  8407. loc = strstr(sstrtemp, "startSchedule");
  8408. if(loc != NULL)
  8409. {
  8410. c = 0;
  8411. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8412. while (loc[3+strlen("startSchedule")+c] != '\"')
  8413. {
  8414. sstr[c] = loc[3+strlen("startSchedule")+c];
  8415. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8416. c++;
  8417. }
  8418. sstr[c] = '\0';
  8419. strcpy(startScheduleStr,sstr);
  8420. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8421. {
  8422. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8423. }
  8424. else
  8425. {
  8426. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8427. }
  8428. }
  8429. else
  8430. {
  8431. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8432. {
  8433. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8434. }
  8435. else
  8436. {
  8437. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8438. }
  8439. }
  8440. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8441. //*********************chargingRateUnit***************************/
  8442. loc = strstr(sstrtemp, "chargingRateUnit");
  8443. if(loc != NULL)
  8444. {
  8445. c = 0;
  8446. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8447. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8448. {
  8449. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8450. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8451. c++;
  8452. }
  8453. sstr[c] = '\0';
  8454. strcpy(chargingRateUnitStr,sstr);
  8455. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8456. {
  8457. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8458. }
  8459. else
  8460. {
  8461. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8462. }
  8463. }
  8464. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8465. //****************chargingSchedulePeriod count start*******************/
  8466. int what_len = strlen("startPeriod");
  8467. char tempChargingProfile[1600]={0};
  8468. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8469. char *where = tempChargingProfile;
  8470. if (what_len)
  8471. {
  8472. while ((where = strstr(where, "startPeriod"))) {
  8473. where += what_len;
  8474. chargingSchedulePeriodCount++;
  8475. }
  8476. }
  8477. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8478. {
  8479. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8480. goto end;
  8481. }
  8482. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8483. //where = payload;
  8484. int templength = 0;
  8485. //int searchstart = 0;
  8486. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8487. {
  8488. //****************startPeriod*******************/
  8489. c=0;
  8490. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8491. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8492. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8493. {
  8494. sstr[c] = loc[strlen("startPeriod")+2+c];
  8495. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8496. c++;
  8497. }
  8498. sstr[c] = '\0';
  8499. startPeriodInt[periodNums] = atoi(sstr);
  8500. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8501. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8502. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8503. {
  8504. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8505. }
  8506. else
  8507. {
  8508. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8509. }
  8510. templength = strlen("startPeriod")+2+c;
  8511. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8512. //****************limit*******************/
  8513. c=0;
  8514. loc = strstr(tempChargingProfile + templength, "limit");
  8515. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8516. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8517. {
  8518. sstr[c] = loc[strlen("limit")+2+c];
  8519. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8520. c++;
  8521. }
  8522. sstr[c] = '\0';
  8523. limitflaot[periodNums] = atof(sstr);
  8524. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8525. {
  8526. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8527. }
  8528. else
  8529. {
  8530. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8531. }
  8532. templength = templength + strlen("limit")+2+c;
  8533. //****************numberPhases*******************/
  8534. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8535. if(loc != NULL)
  8536. {
  8537. c=0;
  8538. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8539. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8540. {
  8541. sstr[c] = loc[strlen("numberPhases")+2+c];
  8542. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8543. c++;
  8544. }
  8545. sstr[c] = '\0';
  8546. numberPhasesInt[periodNums] = atoi(sstr);
  8547. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8548. {
  8549. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8550. }
  8551. else
  8552. {
  8553. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8554. }
  8555. templength = templength + strlen("numberPhases")+2+c;
  8556. }
  8557. //where = loc;
  8558. }
  8559. //****************chargingSchedulePeriod count end*******************/
  8560. //*********************minChargingRate***************************/
  8561. loc = strstr(sstrtemp, "minChargingRate");
  8562. if(loc != NULL)
  8563. {
  8564. c = 0;
  8565. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8566. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8567. {
  8568. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8569. c++;
  8570. }
  8571. sstr[c] = '\0';
  8572. minChargingRateFloat = atof(sstr);
  8573. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8574. {
  8575. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8576. }
  8577. else
  8578. {
  8579. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8580. }
  8581. }
  8582. else
  8583. {
  8584. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8585. {
  8586. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8587. }
  8588. else
  8589. {
  8590. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8591. }
  8592. }
  8593. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8594. {
  8595. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8596. if(connectorIdInt != 0)
  8597. {
  8598. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8599. goto end;
  8600. }
  8601. strcpy(filename, ChargePointMaxProfile_JSON );
  8602. fptr1 = fopen(filename, "r");
  8603. if (!fptr1)
  8604. {
  8605. //file not exist
  8606. DEBUG_INFO("Unable to open the input file!!\n");
  8607. fptr1 = fopen(filename, "w+");
  8608. }
  8609. else
  8610. {
  8611. //Check Charging Profile Count
  8612. while(fscanf(fptr1, "%s", word) != EOF)
  8613. {
  8614. //DEBUG_INFO("word=%s\n",word);
  8615. if(strstr(word, "chargingProfileId")!= NULL)
  8616. {
  8617. //DEBUG_INFO("test chargingProfileId \n");
  8618. n_chargingProfile = n_chargingProfile + 1;
  8619. //DEBUG_INFO("chargingProfileId Found\n");
  8620. }
  8621. }
  8622. }
  8623. fclose(fptr1);
  8624. }
  8625. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8626. {
  8627. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8628. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8629. {
  8630. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8631. goto end;
  8632. }
  8633. memset(filename, 0, ARRAY_SIZE(filename));
  8634. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8635. fptr1 = fopen(filename, "r");
  8636. if (!fptr1)
  8637. {
  8638. //file not exist
  8639. //DEBUG_INFO("Unable to open the input file!!\n");
  8640. fptr1 = fopen(filename, "w+");
  8641. }
  8642. else
  8643. {
  8644. //Check Charging Profile Count
  8645. while(fscanf(fptr1, "%s", word) != EOF)
  8646. {
  8647. //DEBUG_INFO("word=%s\n",word);
  8648. if(strstr(word, "chargingProfileId")!= NULL)
  8649. {
  8650. //DEBUG_INFO("test chargingProfileId \n");
  8651. n_chargingProfile = n_chargingProfile + 1;
  8652. //DEBUG_INFO("chargingProfileId Found\n");
  8653. }
  8654. }
  8655. }
  8656. fclose(fptr1);
  8657. }
  8658. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8659. {
  8660. //printf("set chargingProfile 1-4\n");
  8661. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8662. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8663. if(connectorIdInt == 0)
  8664. {
  8665. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8666. goto end;
  8667. }
  8668. int tempIndex = 0;
  8669. //check Transaction active
  8670. if(gunType[connectorIdInt -1] == 'J')
  8671. {
  8672. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8673. {
  8674. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8675. }
  8676. else
  8677. {
  8678. tempIndex = connectorIdInt -1;
  8679. }
  8680. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8681. {
  8682. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8683. {
  8684. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8685. {
  8686. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8687. {
  8688. meet = TRUE;
  8689. break;
  8690. }
  8691. }
  8692. }
  8693. }
  8694. }
  8695. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8696. {
  8697. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8698. {
  8699. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8700. }
  8701. else
  8702. {
  8703. tempIndex = connectorIdInt -1;
  8704. }
  8705. for (int index = 0; index < CCS_QUANTITY; index++)
  8706. {
  8707. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8708. {
  8709. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8710. {
  8711. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8712. {
  8713. meet = TRUE;
  8714. break;
  8715. }
  8716. }
  8717. }
  8718. }
  8719. }
  8720. else if(gunType[connectorIdInt -1] == 'G')
  8721. {
  8722. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8723. {
  8724. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8725. }
  8726. else
  8727. {
  8728. tempIndex = connectorIdInt -1;
  8729. }
  8730. for (int index = 0; index < GB_QUANTITY; index++)
  8731. {
  8732. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8733. {
  8734. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8735. {
  8736. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8737. {
  8738. meet = TRUE;
  8739. break;
  8740. }
  8741. }
  8742. }
  8743. }
  8744. }
  8745. else
  8746. {
  8747. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8748. {
  8749. tempIndex = 2;
  8750. }
  8751. else
  8752. {
  8753. tempIndex = (connectorIdInt -1);
  8754. }
  8755. for (int index = 0; index < AC_QUANTITY; index++)
  8756. {
  8757. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8758. {
  8759. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8760. {
  8761. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8762. {
  8763. meet = TRUE;
  8764. break;
  8765. }
  8766. }
  8767. }
  8768. }
  8769. }
  8770. //check Transaction active
  8771. if(meet == FALSE)
  8772. {
  8773. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8774. goto end;
  8775. }
  8776. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8777. {
  8778. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8779. goto end;
  8780. }
  8781. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8782. fptr1 = fopen(filename, "r");
  8783. if (!fptr1)
  8784. {
  8785. //file not exist
  8786. DEBUG_INFO("Unable to open the input file!!\n");
  8787. fptr1 = fopen(filename, "w+");
  8788. }
  8789. else
  8790. {
  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. //DEBUG_INFO("chargingProfileId Found\n");
  8800. }
  8801. }
  8802. }
  8803. fclose(fptr1);
  8804. }
  8805. // Check ChargeProfileMaxStackLevel
  8806. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8807. {
  8808. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8809. goto end;
  8810. }
  8811. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8812. {
  8813. int i = 0;
  8814. char fnametemp[200]={0};
  8815. n_chargingProfile = 0;
  8816. //Check ChargePointMaxProfile.json exit
  8817. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8818. {
  8819. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8820. //Check Charging Profile Count
  8821. while(fscanf(fptr1, "%s", word) != EOF)
  8822. {
  8823. //DEBUG_INFO("word=%s\n",word);
  8824. if(strstr(word, "chargingProfileId")!= NULL)
  8825. {
  8826. //DEBUG_INFO("test chargingProfileId \n");
  8827. n_chargingProfile = n_chargingProfile + 1;
  8828. i = i + 1;
  8829. //DEBUG_INFO("chargingProfileId Found\n");
  8830. }
  8831. memset(word, 0, ARRAY_SIZE(word));
  8832. }
  8833. fclose(fptr1);
  8834. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8835. }
  8836. //Check TxDefaultProfile_0.json exit
  8837. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8838. {
  8839. i = 0;
  8840. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8841. //Check Charging Profile Count
  8842. while(fscanf(fptr1, "%s", word) != EOF)
  8843. {
  8844. //DEBUG_INFO("word=%s\n",word);
  8845. if(strstr(word, "chargingProfileId")!= NULL)
  8846. {
  8847. //DEBUG_INFO("test chargingProfileId \n");
  8848. n_chargingProfile = n_chargingProfile + 1;
  8849. i = i + 1;
  8850. //DEBUG_INFO("chargingProfileId Found\n");
  8851. }
  8852. memset(word, 0, ARRAY_SIZE(word));
  8853. }
  8854. fclose(fptr1);
  8855. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8856. }
  8857. //Check TxDefaultProfile_%d.json
  8858. for(int j=1; j <= gunTotalNumber; j++)
  8859. {
  8860. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8861. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8862. if((access(fnametemp,F_OK))!=-1)
  8863. {
  8864. i = 0;
  8865. fptr1 = fopen(fnametemp, "r");
  8866. //Check Charging Profile Count
  8867. while(fscanf(fptr1, "%s", word) != EOF)
  8868. {
  8869. //DEBUG_INFO("word=%s\n",word);
  8870. if(strstr(word, "chargingProfileId")!= NULL)
  8871. {
  8872. //DEBUG_INFO("test chargingProfileId \n");
  8873. n_chargingProfile = n_chargingProfile + 1;
  8874. i = i + 1;
  8875. //DEBUG_INFO("chargingProfileId Found\n");
  8876. }
  8877. memset(word, 0, ARRAY_SIZE(word));
  8878. }
  8879. fclose(fptr1);
  8880. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8881. }
  8882. }
  8883. //Check TxProfile_%d.json
  8884. for(int j=1; j <= gunTotalNumber; j++)
  8885. {
  8886. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8887. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8888. if((access(fnametemp,F_OK))!=-1)
  8889. {
  8890. i = 0;
  8891. fptr1 = fopen(fnametemp, "r");
  8892. //Check Charging Profile Count
  8893. while(fscanf(fptr1, "%s", word) != EOF)
  8894. {
  8895. //DEBUG_INFO("word=%s\n",word);
  8896. if(strstr(word, "chargingProfileId")!= NULL)
  8897. {
  8898. //DEBUG_INFO("test chargingProfileId \n");
  8899. n_chargingProfile = n_chargingProfile + 1;
  8900. i = i + 1;
  8901. //DEBUG_INFO("chargingProfileId Found\n");
  8902. }
  8903. memset(word, 0, ARRAY_SIZE(word));
  8904. }
  8905. fclose(fptr1);
  8906. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8907. }
  8908. }
  8909. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8910. {
  8911. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8912. goto end;
  8913. }
  8914. }
  8915. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8916. //**********************************Write to File********************************************************/
  8917. FILE *infile;
  8918. FILE *outfile;
  8919. // open file for writing
  8920. infile = fopen (filename, "r");
  8921. outfile = fopen (tempfile, "w");
  8922. int d =0;
  8923. d = fgetc(infile);
  8924. //DEBUG_INFO("d:%d\n",d);
  8925. rewind(infile);
  8926. //*璉 瘚 辣蝏     1嚗   0 */
  8927. if(d == EOF)
  8928. {
  8929. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8930. fprintf(outfile,"%s\n",payload);
  8931. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8932. fclose(infile);
  8933. fclose(outfile);
  8934. sprintf(rmFileCmd,"rm -f %s",filename);
  8935. system(rmFileCmd);
  8936. rename(tempfile, filename);
  8937. sleep(1);
  8938. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8939. //system(rmFileCmd);
  8940. }
  8941. else
  8942. {
  8943. char buf[1000]={0};
  8944. int ChargingProfileAdded = FALSE;
  8945. while (fgets(buf, sizeof(buf), infile) != NULL)
  8946. {
  8947. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8948. //*************************tempconnectorIdInt*********************************/
  8949. loc = strstr(buf, "connectorId");
  8950. c = 0;
  8951. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8952. while (loc[strlen("connectorId")+2+c] != ',')
  8953. {
  8954. sstr[c] = loc[strlen("connectorId")+2+c];
  8955. c++;
  8956. }
  8957. sstr[c] = '\0';
  8958. tempconnectorIdInt = atoi(sstr);
  8959. //*************************tempchargingProfileIdInt*********************************/
  8960. loc = strstr(buf, "chargingProfileId");
  8961. c = 0;
  8962. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8963. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8964. {
  8965. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8966. c++;
  8967. }
  8968. sstr[c] = '\0';
  8969. tempchargingProfileIdInt = atoi(sstr);
  8970. //*************************tempstackLevelInt*********************************/
  8971. loc = strstr(buf, "stackLevel");
  8972. c = 0;
  8973. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8974. while (loc[strlen("stackLevel")+2+c] != ',')
  8975. {
  8976. sstr[c] = loc[strlen("stackLevel")+2+c];
  8977. c++;
  8978. }
  8979. sstr[c] = '\0';
  8980. tempstackLevelInt = atoi(sstr);
  8981. //*************************tempchargingProfilePurposeStr*********************************/
  8982. loc = strstr(payload, "chargingProfilePurpose");
  8983. c = 0;
  8984. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8985. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8986. {
  8987. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8988. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8989. c++;
  8990. }
  8991. sstr[c] = '\0';
  8992. strcpy(tempchargingProfilePurposeStr,sstr);
  8993. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  8994. {
  8995. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8996. {
  8997. //DEBUG_INFO("update set chargingProfile to file -0\n");
  8998. if(ChargingProfileAdded == FALSE)
  8999. {
  9000. fprintf(outfile,"%s\n",payload);
  9001. ChargingProfileAdded = TRUE;
  9002. }
  9003. }
  9004. else
  9005. {
  9006. if(tempstackLevelInt < stackLevelInt)
  9007. {
  9008. if(ChargingProfileAdded == FALSE)
  9009. {
  9010. fprintf(outfile,"%s\n",payload);
  9011. ChargingProfileAdded = TRUE;
  9012. fprintf(outfile,"%s\n",buf);
  9013. }
  9014. else
  9015. {
  9016. fprintf(outfile,"%s\n",buf);
  9017. }
  9018. }
  9019. else
  9020. {
  9021. if(ChargingProfileAdded == FALSE)
  9022. {
  9023. fprintf(outfile,"%s\n",buf);
  9024. fprintf(outfile,"%s\n",payload);
  9025. ChargingProfileAdded = TRUE;
  9026. }
  9027. else
  9028. {
  9029. fprintf(outfile,"%s\n",buf);
  9030. }
  9031. }
  9032. }
  9033. }
  9034. else
  9035. {
  9036. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9037. {
  9038. if(ChargingProfileAdded == FALSE)
  9039. {
  9040. fprintf(outfile,"%s\n",payload);
  9041. ChargingProfileAdded = TRUE;
  9042. fprintf(outfile,"%s\n",buf);
  9043. }
  9044. else
  9045. {
  9046. fprintf(outfile,"%s\n",buf);
  9047. }
  9048. }
  9049. else if(tempstackLevelInt < stackLevelInt)
  9050. {
  9051. if(ChargingProfileAdded == FALSE)
  9052. {
  9053. fprintf(outfile,"%s\n",payload);
  9054. ChargingProfileAdded = TRUE;
  9055. fprintf(outfile,"%s\n",buf);
  9056. }
  9057. else
  9058. {
  9059. fprintf(outfile,"%s\n",buf);
  9060. }
  9061. }
  9062. else
  9063. {
  9064. if(ChargingProfileAdded == FALSE)
  9065. {
  9066. fprintf(outfile,"%s\n",buf);
  9067. fprintf(outfile,"%s\n",payload);
  9068. ChargingProfileAdded = TRUE;
  9069. }
  9070. else
  9071. {
  9072. fprintf(outfile,"%s\n",buf);
  9073. }
  9074. }
  9075. }
  9076. } // end of while loop
  9077. fclose(infile);
  9078. fclose(outfile);
  9079. sprintf(rmFileCmd,"rm -f %s",filename);
  9080. system(rmFileCmd);
  9081. rename(tempfile, filename);
  9082. sleep(1);
  9083. result = TRUE;
  9084. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9085. }
  9086. end:
  9087. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9088. return result;
  9089. return result;
  9090. }
  9091. int handleTriggerMessageRequest(char *uuid, char *payload)
  9092. {
  9093. mtrace();
  9094. int result = FAIL;
  9095. int connectorIdIsNULL = FALSE;
  9096. int connectorIdInt =0;
  9097. char sstr[40]={0},sstrtemp[100]={ 0 };
  9098. char requestedMessagestr[40]={0};
  9099. char comfirmstr[20]={0};
  9100. int c = 0;
  9101. char *loc;
  9102. DEBUG_INFO("handleTriggerMessageRequest\n");
  9103. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9104. strcpy(sstrtemp, stringtrimspace(payload));
  9105. c = 0;
  9106. loc = strstr(sstrtemp, "requestedMessage");
  9107. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9108. {
  9109. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9110. c++;
  9111. }
  9112. sstr[c] = '\0';
  9113. strcpy(requestedMessagestr, sstr);
  9114. c = 0;
  9115. loc = strstr(sstrtemp, "connectorId");
  9116. if(loc == NULL)
  9117. {
  9118. connectorIdIsNULL = TRUE;
  9119. }
  9120. else
  9121. {
  9122. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9123. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9124. {
  9125. sstr[c] = loc[strlen("connectorId")+2+c];
  9126. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9127. c++;
  9128. }
  9129. sstr[c] = '\0';
  9130. connectorIdInt = atoi(sstr);
  9131. }
  9132. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  9133. {
  9134. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9135. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9136. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9137. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9138. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9139. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9140. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9141. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9142. {
  9143. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9144. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9145. return TRUE;
  9146. }
  9147. else
  9148. {
  9149. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9150. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9151. }
  9152. }
  9153. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9154. {
  9155. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9156. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9157. return TRUE;
  9158. }
  9159. //==========================
  9160. // Trigger message
  9161. //==========================
  9162. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9163. {
  9164. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9165. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9166. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9167. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9168. {
  9169. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9170. }
  9171. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9172. }
  9173. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9174. {
  9175. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9176. }
  9177. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9178. {
  9179. //sendBootNotificationRequest();
  9180. server_sign = FALSE;
  9181. }
  9182. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9183. {
  9184. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9185. }
  9186. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9187. {
  9188. if(connectorIdIsNULL == FALSE)
  9189. {
  9190. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9191. {
  9192. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9193. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  9194. }
  9195. }
  9196. else
  9197. {
  9198. for(int idx=0;idx< gunTotalNumber;idx++)
  9199. {
  9200. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9201. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  9202. }
  9203. }
  9204. }
  9205. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9206. {
  9207. if(connectorIdIsNULL == FALSE)
  9208. {
  9209. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9210. {
  9211. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9212. }
  9213. }
  9214. else
  9215. {
  9216. for(int idx=0;idx< gunTotalNumber;idx++)
  9217. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9218. }
  9219. }
  9220. return result;
  9221. }
  9222. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9223. {
  9224. mtrace();
  9225. int result = FAIL;
  9226. char sstr[6]={0},sstrtemp[50]={ 0 };
  9227. int connectorIdInt =0;
  9228. char comfirmstr[20]={0};
  9229. int c = 0;
  9230. int tempIndex = 0;
  9231. char *loc;
  9232. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9233. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9234. strcpy(sstrtemp, stringtrimspace(payload));
  9235. c = 0;
  9236. loc = strstr(sstrtemp, "connectorId");
  9237. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9238. while (loc[strlen("connectorId")+2+c] != '}')
  9239. {
  9240. sstr[c] = loc[strlen("connectorId")+2+c];
  9241. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9242. c++;
  9243. }
  9244. sstr[c] = '\0';
  9245. connectorIdInt = atoi(sstr);
  9246. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  9247. if(gunTotalNumber == 0)
  9248. {
  9249. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9250. goto end;
  9251. }
  9252. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9253. {
  9254. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9255. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9256. goto end;
  9257. }
  9258. else
  9259. {
  9260. //check Transaction active
  9261. if(gunType[connectorIdInt-1] == 'J')
  9262. {
  9263. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9264. {
  9265. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9266. }
  9267. else
  9268. {
  9269. tempIndex = connectorIdInt -1;
  9270. }
  9271. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9272. {
  9273. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9274. {
  9275. //stop Transaction
  9276. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9277. }
  9278. }
  9279. }
  9280. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9281. {
  9282. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9283. {
  9284. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9285. }
  9286. else
  9287. {
  9288. tempIndex = connectorIdInt -1;
  9289. }
  9290. for (int index = 0; index < CCS_QUANTITY; index++)
  9291. {
  9292. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9293. {
  9294. //stop Transaction
  9295. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9296. }
  9297. }
  9298. }
  9299. else if(gunType[connectorIdInt-1] == 'G')
  9300. {
  9301. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9302. {
  9303. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9304. }
  9305. else
  9306. {
  9307. tempIndex = connectorIdInt -1;
  9308. }
  9309. for (int index = 0; index < GB_QUANTITY; index++)
  9310. {
  9311. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9312. {
  9313. //stop Transaction
  9314. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9315. }
  9316. }
  9317. }
  9318. else
  9319. {
  9320. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9321. {
  9322. tempIndex = 2;
  9323. }
  9324. else
  9325. {
  9326. tempIndex = connectorIdInt-1;
  9327. }
  9328. for (int index = 0; index < AC_QUANTITY; index++)
  9329. {
  9330. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9331. {
  9332. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9333. }
  9334. }
  9335. }
  9336. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9337. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9338. result = TRUE;
  9339. return result;
  9340. }
  9341. end:
  9342. //json_object_put(obj); --- remove temporally
  9343. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9344. return result;
  9345. }
  9346. static char UpdateFirmwarepayloadData[300]={0};
  9347. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9348. {
  9349. mtrace();
  9350. int result = FAIL;
  9351. pthread_t t;
  9352. sendUpdateFirmwareConfirmation(uuid);
  9353. memset(UpdateFirmwarepayloadData, 0, 300);
  9354. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9355. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9356. ////pthread_join(t, NULL); //
  9357. //pthread_detach(t);
  9358. //sendUpdateFirmwareConfirmation(uuid);
  9359. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9360. return result;
  9361. }
  9362. void *UpdateFirmwareProcess(void *data)
  9363. {
  9364. pthread_detach(pthread_self());
  9365. mtrace();
  9366. int retriesInt =0, retryIntervalInt=0;
  9367. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9368. int port=0;
  9369. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9370. int isSuccess = 0;
  9371. char ftpbuf[200];
  9372. char temp[100];
  9373. char * pch;
  9374. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9375. json_object *UpdateFirmware;
  9376. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  9377. if(!is_error(UpdateFirmware))
  9378. {
  9379. // Required data
  9380. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  9381. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  9382. // Optional data
  9383. if(json_object_object_get(UpdateFirmware, "retries"))
  9384. {
  9385. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  9386. }
  9387. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  9388. {
  9389. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  9390. }
  9391. }
  9392. json_object_put(UpdateFirmware);
  9393. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9394. memset(path, 0, ARRAY_SIZE(path));
  9395. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9396. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9397. if(strncmp(locationstr,"http", 4) == 0)
  9398. {
  9399. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9400. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9401. // protocol, user, password, host, path);
  9402. sprintf(ftppath,"/%s", path);
  9403. DEBUG_INFO("locationstr: %s\n", locationstr);
  9404. DEBUG_INFO("protocol: %s\n",protocol);
  9405. DEBUG_INFO("host: %s\n",host);
  9406. DEBUG_INFO("path: %s\n",path);
  9407. DEBUG_INFO("ftppath: %s\n",ftppath);
  9408. int ftppathlen=strlen(ftppath);
  9409. int i=1;
  9410. char filenametemp[50];
  9411. while(i < ftppathlen)
  9412. {
  9413. int len=ftppathlen-i;
  9414. if(ftppath[len]== 47) // '/' ascll code: 47
  9415. {
  9416. DEBUG_INFO("compare '/' all right\n");
  9417. break;
  9418. }
  9419. i=i+1;
  9420. }
  9421. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9422. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9423. filenametemp[i+1] = 0;
  9424. do
  9425. {
  9426. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9427. sleep(retryIntervalInt);
  9428. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9429. if(!isSuccess)
  9430. {
  9431. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9432. }
  9433. else
  9434. {
  9435. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9436. }
  9437. }
  9438. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9439. {
  9440. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9441. memset(temp, 0, ARRAY_SIZE(temp));
  9442. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9443. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9444. int ftppathlen=strlen(ftpbuf);
  9445. int i=1;
  9446. char filenametemp[50];
  9447. while(i < ftppathlen)
  9448. {
  9449. int len=ftppathlen-i;
  9450. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9451. {
  9452. DEBUG_INFO(" compare '/' all right\n");
  9453. break;
  9454. }
  9455. i=i+1;
  9456. }
  9457. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9458. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9459. filenametemp[i+1] = 0;
  9460. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9461. pch=strchr(temp,'@');
  9462. if(pch==NULL)
  9463. {
  9464. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9465. protocol, host, &port, path);
  9466. strcpy(user,"anonymous");
  9467. strcpy(password,"");
  9468. }
  9469. else
  9470. {
  9471. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9472. protocol, user, password, host, &port, path);
  9473. }
  9474. sscanf(host,"%[^/]%s",host1, path1);
  9475. sprintf(ftppath,"%s", path1);
  9476. //DEBUG_INFO("protocol =%s\n",protocol);
  9477. //DEBUG_INFO("user =%s\n",user);
  9478. //DEBUG_INFO("password =%s\n",password);
  9479. //DEBUG_INFO("host1 =%s\n",host1);
  9480. //DEBUG_INFO("port =%d\n",port);
  9481. //DEBUG_INFO("path1 =%s\n",path1);
  9482. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9483. //ftpFile(host, user, password, port, ftppath, fname);
  9484. //download firmware pthred
  9485. if(port == 0)
  9486. {
  9487. port = 21;
  9488. }
  9489. do
  9490. {
  9491. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9492. sleep(retryIntervalInt);
  9493. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9494. if(!isSuccess)
  9495. {
  9496. //BulldogUtil.sleepMs(interval*1000);
  9497. DEBUG_INFO("Update firmware request and download file fail.\n");
  9498. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9499. }
  9500. else
  9501. {
  9502. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9503. }
  9504. }
  9505. else
  9506. {
  9507. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9508. }
  9509. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9510. pthread_exit(NULL);
  9511. }
  9512. //==========================================
  9513. // Handle server response routine
  9514. //==========================================
  9515. void handleAuthorizeResponse(char *payload, int gun_index)
  9516. {
  9517. mtrace();
  9518. char expiryDatestr[30]={0};
  9519. char parentIdTagstr[20]={0};
  9520. char statusstr[20]={0};
  9521. char expiryDatestrtemp[30]={0};
  9522. char parentIdTagstrtemp[20]={0};
  9523. char IdTagstrtemp[20]={0};
  9524. char statusstrtemp[20]={0};
  9525. int expiryDateISNULL=FALSE;
  9526. int parentIdTagISNULL=FALSE;
  9527. char sstr[160]={0};
  9528. char* filename = AuthorizationCache_JSON;
  9529. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9530. char *loc;
  9531. int resultRename=0;
  9532. int responseIdTagInfoAsZero= 0;
  9533. char rmFileCmd[50]={0};
  9534. DEBUG_INFO("handleAuthorizeResponse...\n");
  9535. json_object *Authorize;
  9536. Authorize = json_tokener_parse(payload);
  9537. if(!is_error(Authorize))
  9538. {
  9539. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9540. {
  9541. // Required data
  9542. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9543. // Optional data
  9544. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9545. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9546. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9547. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9548. }
  9549. }
  9550. json_object_put(Authorize);
  9551. if(expiryDateISNULL == FALSE)
  9552. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9553. if(parentIdTagISNULL == FALSE)
  9554. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9555. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9556. //Update idTag information to authorization cache if supproted
  9557. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9558. {
  9559. if((access(filename,F_OK))!=-1)
  9560. {
  9561. printf("AuthorizationCache exist.\n");
  9562. }
  9563. else
  9564. {
  9565. printf("AuthorizationCache not exist\n");
  9566. FILE *log = fopen(filename, "w+");
  9567. if(log == NULL)
  9568. {
  9569. printf("log is NULL\n");
  9570. goto out;
  9571. }
  9572. else
  9573. {
  9574. fclose(log);
  9575. }
  9576. }
  9577. FILE *infile;
  9578. FILE *outfile;
  9579. // open file for writing
  9580. infile = fopen (filename, "r");
  9581. outfile = fopen (tempfile, "w");
  9582. int c;
  9583. c = fgetc(infile);
  9584. //DEBUG_INFO("c:%d\n",c);
  9585. rewind(infile);
  9586. if(c == EOF)
  9587. {
  9588. DEBUG_INFO("Orignal File is NULL\n");
  9589. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9590. {
  9591. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9592. }
  9593. else
  9594. {
  9595. strcpy(expiryDatestrtemp, "");
  9596. }
  9597. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9598. {
  9599. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9600. }
  9601. else
  9602. {
  9603. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9604. }
  9605. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9606. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9607. fclose(infile);
  9608. fclose(outfile);
  9609. sprintf(rmFileCmd,"rm -f %s",filename);
  9610. system(rmFileCmd);
  9611. resultRename = rename(tempfile, filename);
  9612. if(resultRename == 0)
  9613. {
  9614. printf("File renamed successfully");
  9615. }
  9616. else
  9617. {
  9618. printf("Error: unable to rename the file");
  9619. }
  9620. }
  9621. else
  9622. {
  9623. char buf[160]={0};
  9624. while (fgets(buf, ARRAY_SIZE(buf), infile) != NULL)
  9625. {
  9626. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9627. memset(expiryDatestr, 0, ARRAY_SIZE(expiryDatestrtemp));
  9628. memset(parentIdTagstr,0, ARRAY_SIZE(parentIdTagstrtemp));
  9629. memset(statusstr, 0, ARRAY_SIZE(statusstrtemp));
  9630. memset(IdTagstrtemp, 0, ARRAY_SIZE(IdTagstrtemp));
  9631. memset(expiryDatestrtemp, 0, ARRAY_SIZE(expiryDatestrtemp));
  9632. memset(parentIdTagstrtemp, 0, ARRAY_SIZE(parentIdTagstrtemp));
  9633. memset(statusstrtemp, 0, ARRAY_SIZE(statusstrtemp));
  9634. //------------------IdTag-----------------------
  9635. loc = strstr(buf, "idTag");
  9636. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9637. c = 0;
  9638. while (loc[3+strlen("idTag")+c] != '\"')
  9639. {
  9640. sstr[c] = loc[3+strlen("idTag")+c];
  9641. c++;
  9642. }
  9643. sstr[c] = '\0';
  9644. strcpy(IdTagstrtemp,sstr);
  9645. //*********************expiryDate***************/
  9646. loc = strstr(buf, "expiryDate");
  9647. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9648. c = 0;
  9649. while (loc[3+strlen("expiryDate")+c] != '\"')
  9650. {
  9651. sstr[c] = loc[3+strlen("expiryDate")+c];
  9652. c++;
  9653. }
  9654. sstr[c] = '\0';
  9655. strcpy(expiryDatestr,sstr);
  9656. //*********************parentIdTag***************/
  9657. loc = strstr(buf, "parentIdTag");
  9658. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9659. c = 0;
  9660. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9661. {
  9662. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9663. c++;
  9664. }
  9665. sstr[c] = '\0';
  9666. strcpy(parentIdTagstr,sstr);
  9667. //*********************status***************/
  9668. loc = strstr(buf, "status");
  9669. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9670. c = 0;
  9671. while (loc[3+strlen("status")+c] != '\"')
  9672. {
  9673. sstr[c] = loc[3+strlen("status")+c];
  9674. c++;
  9675. }
  9676. sstr[c] = '\0';
  9677. strcpy(statusstr,sstr);
  9678. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9679. {
  9680. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9681. responseIdTagInfoAsZero = 1;
  9682. }
  9683. else
  9684. {
  9685. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9686. }
  9687. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9688. {
  9689. //modify item
  9690. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9691. {
  9692. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9693. }
  9694. else
  9695. {
  9696. strcpy(expiryDatestrtemp, "");
  9697. }
  9698. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9699. {
  9700. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9701. }
  9702. else
  9703. {
  9704. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9705. }
  9706. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9707. }
  9708. else
  9709. {
  9710. //wrie original item
  9711. strcpy(expiryDatestrtemp, expiryDatestr);
  9712. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9713. strcpy(statusstrtemp, statusstr);
  9714. }
  9715. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9716. }
  9717. fclose(infile);
  9718. fclose(outfile);
  9719. sprintf(rmFileCmd,"rm -f %s",filename);
  9720. system(rmFileCmd);
  9721. resultRename = rename(tempfile, filename);
  9722. if(resultRename == 0)
  9723. {
  9724. DEBUG_INFO("File renamed successfully");
  9725. }
  9726. else
  9727. {
  9728. DEBUG_INFO("Error: unable to rename the file");
  9729. }
  9730. }
  9731. }
  9732. out:
  9733. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9734. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9735. authorizeRetryTimes = 0;
  9736. }
  9737. char * strtrimc( char * s )
  9738. {
  9739. char * p1 = s;
  9740. char * p2 = s;
  9741. while(*p1 != '\0')
  9742. {
  9743. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9744. {
  9745. if(*p1 != ',')
  9746. {
  9747. p1 ++;
  9748. }
  9749. else
  9750. {
  9751. break;
  9752. }
  9753. }
  9754. if(*p1 != ',')
  9755. {
  9756. * p2 ++ = *p1 ++;
  9757. //printf("p2=%s\n",p2);
  9758. }
  9759. else
  9760. {
  9761. break;
  9762. }
  9763. }
  9764. *p2 = '\0';
  9765. return (s);
  9766. }
  9767. void handleBootNotificationResponse(char *payload, int gun_index)
  9768. {
  9769. mtrace();
  9770. char statusStr[12]={0};
  9771. char currentTimeStr[30]={0};
  9772. int intervalInt = 0;
  9773. struct tm tp;
  9774. char buf[28]={0};
  9775. char timebuf[50]={0};
  9776. DEBUG_INFO("handleBootNotificationResponse...\n");
  9777. json_object *BootNotification;
  9778. BootNotification = json_tokener_parse(payload);
  9779. if(!is_error(BootNotification))
  9780. {
  9781. // Required data
  9782. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9783. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9784. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9785. }
  9786. json_object_put(BootNotification);
  9787. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9788. BootNotificationInterval = intervalInt;
  9789. HeartBeatWaitTime = intervalInt;
  9790. //write back to ShmOCPP16Data->BootNotification
  9791. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9792. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9793. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9794. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9795. {
  9796. server_sign = TRUE;
  9797. server_pending =FALSE;
  9798. }
  9799. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9800. {
  9801. server_pending = TRUE;
  9802. }
  9803. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9804. tp.tm_isdst = -1;
  9805. //time_t utc = mktime(&tp);
  9806. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9807. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9808. sprintf(timebuf,"date -s '%s'",buf);
  9809. system(timebuf);
  9810. srand(time(NULL));
  9811. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9812. //==============================================
  9813. // RTC sync
  9814. //==============================================
  9815. system("/sbin/hwclock -w --systohc");
  9816. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9817. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9818. }
  9819. void handleDataTransferResponse(char *payload, int gun_index)
  9820. {
  9821. char sstr[160]={0};//sstr[200]={ 0 };
  9822. int c = 0;
  9823. char *loc;
  9824. DEBUG_INFO("handleDataTransferResponse ...\n");
  9825. loc = strstr(payload, "status");
  9826. printf("loc=%s\n",loc);
  9827. c = 0;
  9828. while (loc[3+strlen("status")+c] != '\"')
  9829. {
  9830. sstr[c] = loc[3+strlen("status")+c];
  9831. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9832. c++;
  9833. }
  9834. sstr[c] = '\0';
  9835. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9836. }
  9837. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9838. {
  9839. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9840. //struct json_object *obj;
  9841. // obj = json_tokener_parse(payload);
  9842. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9843. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9844. //No fields are defined.
  9845. }
  9846. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9847. {
  9848. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9849. //struct json_object *obj;
  9850. // obj = json_tokener_parse(payload);
  9851. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9852. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9853. //No fields are defined.
  9854. }
  9855. void handleHeartbeatResponse(char *payload, int gun_index)
  9856. {
  9857. mtrace();
  9858. struct tm tp;
  9859. char buf[28]={0};
  9860. char timebuf[50]={0};
  9861. DEBUG_INFO("handleHeartbeatResponse...\n");
  9862. json_object *Heartbeat;
  9863. Heartbeat = json_tokener_parse(payload);
  9864. if(!is_error(Heartbeat))
  9865. {
  9866. // Required data
  9867. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9868. }
  9869. json_object_put(BootNotification);
  9870. if(FirstHeartBeat == 0)
  9871. {
  9872. FirstHeartBeat = 1;
  9873. DEBUG_INFO("FirstHeartBeat \n");
  9874. }
  9875. HeartBeatWithNOResponse = 0;
  9876. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9877. tp.tm_isdst = -1;
  9878. //time_t utc = mktime(&tp);
  9879. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9880. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9881. sprintf(timebuf,"date -s '%s'",buf);
  9882. system(timebuf);
  9883. //==============================================
  9884. // RTC sync
  9885. //==============================================
  9886. system("/sbin/hwclock -w --systohc");
  9887. //===============================================
  9888. //Print Out HeartBeat log
  9889. //===============================================
  9890. {
  9891. double diff_t;
  9892. struct tm tp,tp1;
  9893. // BootNotification Receive Time
  9894. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9895. tp.tm_isdst = -1;
  9896. time_t BootNotificationReceiveTime = mktime(&tp);
  9897. //HeartBeat Receive Time
  9898. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  9899. tp1.tm_isdst = -1;
  9900. time_t HeartBeatReceiveTime = mktime(&tp1);
  9901. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  9902. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  9903. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  9904. {
  9905. HeartBeatCountPerHour = (int)diff_t / 3600;
  9906. DEBUG_INFO("handleHeartbeatResponse ...\n");
  9907. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  9908. }
  9909. }
  9910. }
  9911. void handleMeterValuesResponse(char *payload, int gun_index)
  9912. {
  9913. mtrace();
  9914. DEBUG_INFO("handleMeterValuesResponse...\n");
  9915. }
  9916. void handleStartTransactionResponse(char *payload, int gun_index)
  9917. {
  9918. mtrace();
  9919. //int transactionIdInt = 0;
  9920. FILE *outfile;
  9921. char data[100]={0};
  9922. DEBUG_INFO("handleStartTransactionResponse...\n");
  9923. json_object *StartTransaction;
  9924. StartTransaction = json_tokener_parse(payload);
  9925. if(!is_error(StartTransaction))
  9926. {
  9927. // Required data
  9928. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  9929. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  9930. // Optional data
  9931. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  9932. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  9933. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9934. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  9935. }
  9936. json_object_put(StartTransaction);
  9937. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9938. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9939. //-----------Start : write to the Queue TransactionId file -----------------//
  9940. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9941. {}
  9942. else
  9943. {
  9944. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9945. if(log == NULL)
  9946. {
  9947. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9948. return ;
  9949. }
  9950. else
  9951. {
  9952. fclose(log);
  9953. }
  9954. }
  9955. // open file for writing
  9956. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  9957. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  9958. {
  9959. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9960. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9961. fputs(data, outfile);
  9962. fclose (outfile);
  9963. }
  9964. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9965. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9966. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9967. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9968. }
  9969. void handleStatusNotificationResponse(char *payload, int gun_index)
  9970. {
  9971. mtrace();
  9972. DEBUG_INFO("handleStatusNotificationResponse...\n");
  9973. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9974. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9975. }
  9976. void handleStopTransactionnResponse(char *payload, int gun_index)
  9977. {
  9978. mtrace();
  9979. DEBUG_INFO("handleStopTransactionnResponse...\n");
  9980. json_object *StopTransaction;
  9981. StopTransaction = json_tokener_parse(payload);
  9982. if(!is_error(StopTransaction))
  9983. {
  9984. // Optional data
  9985. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  9986. {
  9987. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  9988. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  9989. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  9990. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9991. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  9992. }
  9993. }
  9994. json_object_put(StopTransaction);
  9995. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9996. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9997. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9998. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9999. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10000. }
  10001. //==========================================
  10002. // Handle Error routine
  10003. //==========================================
  10004. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10005. {
  10006. mtrace();
  10007. #ifdef SystemLogMessage
  10008. DEBUG_INFO("errorCode: %s\n", errorCode);
  10009. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10010. DEBUG_INFO("errorDetails: %s\n", payload);
  10011. #endif
  10012. }
  10013. //===============================================
  10014. // Common routine
  10015. //===============================================
  10016. int initialConfigurationTable(void)
  10017. {
  10018. //clock_t start_t, end_t, total_t;
  10019. FILE *fp;
  10020. FILE *outfile;
  10021. char str[200]={0};
  10022. char sstr[100]={0};
  10023. int c = 0;
  10024. char *loc;
  10025. DEBUG_INFO("initialConfigurationTable...\n");
  10026. //start_t = clock();
  10027. //printf("Starting of the program, start_t = %ld\n", start_t);
  10028. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10029. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10030. {
  10031. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10032. if(outfile == NULL)
  10033. {
  10034. DEBUG_INFO("Error opening file\n");
  10035. return FALSE;
  10036. }
  10037. /*Core Profile*/
  10038. //AllowOfflineTxForUnknownId
  10039. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10042. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10043. //AuthorizationCacheEnabled
  10044. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10047. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10048. //AuthorizeRemoteTxRequests
  10049. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10052. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10053. //BlinkRepeat
  10054. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10057. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10058. //ClockAlignedDataInterval
  10059. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10062. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10063. //ConnectionTimeOut
  10064. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10067. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10068. //GetConfigurationMaxKeys
  10069. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "44" );
  10072. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10073. // HeartbeatInterval
  10074. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10077. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10078. // LightIntensity
  10079. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10082. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10083. // LocalAuthorizeOffline
  10084. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10087. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10088. // LocalPreAuthorize
  10089. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10092. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10093. // MaxEnergyOnInvalidId
  10094. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10097. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10098. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10099. // MeterValuesAlignedData
  10100. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10102. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10104. else
  10105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10107. // MeterValuesAlignedDataMaxLength
  10108. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10110. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10112. else
  10113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10115. // MeterValuesSampledData
  10116. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10118. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10120. else
  10121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10123. // MeterValuesSampledDataMaxLength
  10124. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10126. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10128. else
  10129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10130. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10131. // MeterValueSampleInterval
  10132. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10136. // MinimumStatusDuration
  10137. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10140. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10141. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10142. // NumberOfConnectors
  10143. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10144. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10145. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10146. {
  10147. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10148. }
  10149. else
  10150. {
  10151. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10152. }
  10153. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10154. // ResetRetries
  10155. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10158. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10159. // ConnectorPhaseRotation
  10160. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10164. // ConnectorPhaseRotationMaxLength
  10165. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10168. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10169. // StopTransactionOnEVSideDisconnect
  10170. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10173. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10174. // StopTransactionOnInvalidId
  10175. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10178. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10179. // StopTxnAlignedData
  10180. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10183. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10184. // StopTxnAlignedDataMaxLength
  10185. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10188. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10189. // StopTxnSampledData
  10190. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10192. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10193. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10194. else
  10195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10196. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10197. // StopTxnSampledDataMaxLength
  10198. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10200. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10201. {
  10202. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10203. }
  10204. else
  10205. {
  10206. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10207. }
  10208. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10209. // SupportedFeatureProfiles
  10210. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10211. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10212. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10213. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10214. // SupportedFeatureProfilesMaxLength
  10215. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10218. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10219. // TransactionMessageAttempts
  10220. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10221. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10223. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10224. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10225. // TransactionMessageRetryInterval
  10226. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10229. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10230. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10231. // UnlockConnectorOnEVSideDisconnect
  10232. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10235. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10236. // WebSocketPingInterval
  10237. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10240. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10241. // QueueOffLineStartTransactionMessage
  10242. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10245. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10246. //* Local Auth List Management Profile*/
  10247. #if 0
  10248. //For OCTT Test Case
  10249. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10252. #endif
  10253. #if 1
  10254. //LocalAuthListEnabled
  10255. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10258. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10259. #endif
  10260. //LocalAuthListMaxLength
  10261. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10264. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10265. //SendLocalListMaxLength
  10266. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10269. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10270. //ReserveConnectorZeroSupported
  10271. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10274. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10275. //* Smart Charging Profile */
  10276. //ChargeProfileMaxStackLevel
  10277. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10280. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10281. // ChargingScheduleAllowedChargingRateUnit
  10282. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10284. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10285. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10286. // ChargingScheduleMaxPeriods
  10287. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10290. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10291. // ConnectorSwitch3to1PhaseSupported
  10292. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10295. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10296. // MaxChargingProfilesInstalled
  10297. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10300. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10301. fclose(outfile);
  10302. }
  10303. else
  10304. {
  10305. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10306. char keystr[60]={0};
  10307. char readonlystr[10]={0};
  10308. char valuestr[100]={0};
  10309. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10310. if(fp == NULL) {
  10311. DEBUG_INFO("Error opening file");
  10312. return FALSE;
  10313. }
  10314. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10315. {
  10316. //DEBUG_INFO("Get Configuration \n");
  10317. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10318. //*************************key*********************************/
  10319. loc = strstr(str, "key");
  10320. c = 0;
  10321. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10322. while (loc[strlen("key")+3+c] != '\"')
  10323. {
  10324. sstr[c] = loc[strlen("key")+3+c];
  10325. c++;
  10326. }
  10327. sstr[c] = '\0';
  10328. strcpy(keystr,sstr);
  10329. //*************************readonly*********************************/
  10330. loc = strstr(str, "readonly");
  10331. c = 0;
  10332. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10333. while (loc[strlen("readonly")+2+c] != ',')
  10334. {
  10335. sstr[c] = loc[strlen("readonly")+2+c];
  10336. c++;
  10337. }
  10338. sstr[c] = '\0';
  10339. strcpy(readonlystr,sstr);
  10340. //*************************value*********************************/
  10341. loc = strstr(str, "value");
  10342. c = 0;
  10343. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10344. while (loc[strlen("value")+3+c] != '\"')
  10345. {
  10346. sstr[c] = loc[strlen("value")+3+c];
  10347. c++;
  10348. }
  10349. sstr[c] = '\0';
  10350. strcpy(valuestr,sstr);
  10351. // DEBUG_INFO("keystr=%s\n",keystr);
  10352. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10353. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10354. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10355. {
  10356. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10357. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10358. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10359. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10360. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10361. }
  10362. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10363. {
  10364. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10365. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10366. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10367. }
  10368. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10369. {
  10370. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10371. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10372. }
  10373. if(strcmp(keystr, "BlinkRepeat") == 0)
  10374. {
  10375. //Charger.BlinkRepeat = Integer.parseInt(value);
  10376. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10377. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10378. }
  10379. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10380. {
  10381. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10382. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10383. }
  10384. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10385. {
  10386. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10388. }
  10389. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10390. {
  10391. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10392. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10393. }
  10394. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10395. {
  10396. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10397. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10398. HeartBeatWaitTime = atoi(valuestr);
  10399. }
  10400. if(strcmp(keystr, "LightIntensity") == 0)
  10401. {
  10402. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10403. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10404. }
  10405. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10406. {
  10407. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10408. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10409. }
  10410. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10411. {
  10412. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10413. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10414. }
  10415. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10416. {
  10417. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10418. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10419. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10420. }
  10421. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10422. {
  10423. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10424. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10425. }
  10426. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10427. {
  10428. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10429. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10430. }
  10431. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10432. {
  10433. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10434. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10435. }
  10436. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10437. {
  10438. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10439. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10440. }
  10441. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10442. {
  10443. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10444. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10445. }
  10446. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10447. {
  10448. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10450. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10451. }
  10452. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10453. {
  10454. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10455. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10456. }
  10457. if(strcmp(keystr, "ResetRetries") == 0)
  10458. {
  10459. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10460. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10461. }
  10462. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10463. {
  10464. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10465. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10466. }
  10467. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10468. {
  10469. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10470. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10471. }
  10472. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10473. {
  10474. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10475. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10476. }
  10477. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10478. {
  10479. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10480. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10481. }
  10482. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10483. {
  10484. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10485. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10486. }
  10487. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10488. {
  10489. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10490. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10491. }
  10492. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10493. {
  10494. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10495. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10496. }
  10497. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10498. {
  10499. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10500. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10501. }
  10502. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10503. {
  10504. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10505. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10506. }
  10507. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10508. {
  10509. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10510. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10511. }
  10512. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10513. {
  10514. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10515. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10516. TransactionMessageAttemptsValue = atoi(valuestr);
  10517. }
  10518. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10519. {
  10520. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10521. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10522. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10523. }
  10524. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10525. {
  10526. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10527. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10528. }
  10529. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10530. {
  10531. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10532. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10533. }
  10534. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10535. {
  10536. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10537. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10538. }
  10539. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10540. {
  10541. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10542. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10543. }
  10544. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10545. {
  10546. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10547. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10548. }
  10549. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10550. {
  10551. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10552. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10553. }
  10554. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10555. {
  10556. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10557. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10558. }
  10559. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10560. {
  10561. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10562. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10563. }
  10564. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10565. {
  10566. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10567. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10568. }
  10569. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10570. {
  10571. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10572. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10573. }
  10574. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10575. {
  10576. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10577. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10578. }
  10579. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10580. {
  10581. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10582. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10583. }
  10584. }
  10585. fclose(fp);
  10586. }
  10587. return 0;
  10588. }
  10589. void StoreConfigurationTable(void)
  10590. {
  10591. FILE *outfile;
  10592. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10593. if(outfile == NULL)
  10594. {
  10595. DEBUG_INFO("Error opening file");
  10596. return ;
  10597. }
  10598. /*Core Profile*/
  10599. //AllowOfflineTxForUnknownId
  10600. /*
  10601. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10602. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10605. */
  10606. //DEBUG_INFO("data=%s\n",data);
  10607. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10608. //AuthorizationCacheEnabled
  10609. /*
  10610. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10613. */
  10614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10615. //AuthorizeRemoteTxRequests
  10616. /*
  10617. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10620. */
  10621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10622. //BlinkRepeat
  10623. /*
  10624. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10627. */
  10628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10629. //ClockAlignedDataInterval
  10630. /*
  10631. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10634. */
  10635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10636. //ConnectionTimeOut
  10637. /*
  10638. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10641. */
  10642. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10643. //GetConfigurationMaxKeys
  10644. /*
  10645. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10648. */
  10649. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10650. // HeartbeatInterval
  10651. /*
  10652. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10655. */
  10656. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10657. // LightIntensity
  10658. /*
  10659. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10662. */
  10663. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10664. // LocalAuthorizeOffline
  10665. /*
  10666. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10669. */
  10670. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10671. // LocalPreAuthorize
  10672. /*
  10673. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10676. */
  10677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10678. // MaxEnergyOnInvalidId
  10679. /*
  10680. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10683. */
  10684. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10685. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10686. // MeterValuesAlignedData
  10687. /*
  10688. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10691. */
  10692. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10693. // MeterValuesAlignedDataMaxLength
  10694. /*
  10695. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10698. */
  10699. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10700. // MeterValuesSampledData
  10701. /*
  10702. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10705. */
  10706. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10707. // MeterValuesSampledDataMaxLength
  10708. /*
  10709. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10712. */
  10713. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10714. // MeterValueSampleInterval
  10715. /*
  10716. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10719. */
  10720. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10721. // MinimumStatusDuration
  10722. /*
  10723. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10726. */
  10727. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10728. // NumberOfConnectors
  10729. /*
  10730. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10732. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10733. {
  10734. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10735. }
  10736. else
  10737. {
  10738. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10739. }
  10740. */
  10741. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10742. // ResetRetries
  10743. /*
  10744. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10747. */
  10748. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10749. // ConnectorPhaseRotation
  10750. /*
  10751. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10754. */
  10755. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10756. // ConnectorPhaseRotationMaxLength
  10757. /*
  10758. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10761. */
  10762. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10763. // StopTransactionOnEVSideDisconnect
  10764. /*
  10765. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10768. */
  10769. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10770. // StopTransactionOnInvalidId
  10771. /*
  10772. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10775. */
  10776. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10777. // StopTxnAlignedData
  10778. /*
  10779. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10782. */
  10783. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10784. // StopTxnAlignedDataMaxLength
  10785. /*
  10786. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10789. */
  10790. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10791. // StopTxnSampledData
  10792. /*
  10793. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10796. */
  10797. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10798. // StopTxnSampledDataMaxLength
  10799. /*
  10800. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10803. */
  10804. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10805. // SupportedFeatureProfiles
  10806. /*
  10807. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10810. */
  10811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10812. // SupportedFeatureProfilesMaxLength
  10813. /*
  10814. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10817. */
  10818. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10819. // TransactionMessageAttempts
  10820. /*
  10821. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10824. */
  10825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10826. // TransactionMessageRetryInterval
  10827. /*
  10828. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10831. */
  10832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10833. // UnlockConnectorOnEVSideDisconnect
  10834. /*
  10835. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10838. */
  10839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10840. // WebSocketPingInterval
  10841. /*
  10842. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10845. */
  10846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10847. // QueueOffLineStartTransactionMessage
  10848. /*
  10849. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  10850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10852. */
  10853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10854. //* Local Auth List Management Profile*/
  10855. //LocalAuthListEnabled
  10856. /*
  10857. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10860. */
  10861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10862. //LocalAuthListMaxLength
  10863. /*
  10864. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10867. */
  10868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10869. //SendLocalListMaxLength
  10870. /*
  10871. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10874. */
  10875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10876. //ReserveConnectorZeroSupported
  10877. /*
  10878. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10881. */
  10882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10883. //* Smart Charging Profile */
  10884. //ChargeProfileMaxStackLevel
  10885. /*
  10886. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10889. */
  10890. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10891. // ChargingScheduleAllowedChargingRateUnit
  10892. /*
  10893. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10896. */
  10897. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10898. // ChargingScheduleMaxPeriods
  10899. /*
  10900. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10903. */
  10904. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10905. // ConnectorSwitch3to1PhaseSupported
  10906. /*
  10907. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10910. */
  10911. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10912. // MaxChargingProfilesInstalled
  10913. /*
  10914. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10917. */
  10918. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10919. fclose(outfile);
  10920. }
  10921. void getKeyValue(char *keyReq)
  10922. {
  10923. int isEmpty = FALSE;
  10924. int isKnowKey = FALSE;
  10925. DEBUG_INFO("keyReq = %s\n", keyReq);
  10926. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10927. isEmpty = TRUE;
  10928. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10929. {
  10930. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10933. {
  10934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10935. }
  10936. else
  10937. {
  10938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10939. }
  10940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10941. isKnowKey = TRUE;
  10942. }
  10943. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10944. {
  10945. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10947. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10948. {
  10949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10950. }
  10951. else
  10952. {
  10953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10954. }
  10955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10956. isKnowKey = TRUE;
  10957. }
  10958. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10959. {
  10960. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10962. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10963. {
  10964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10965. }
  10966. else
  10967. {
  10968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10969. }
  10970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10971. isKnowKey = TRUE;
  10972. }
  10973. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10974. {
  10975. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10977. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10978. {
  10979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10980. }
  10981. else
  10982. {
  10983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10984. }
  10985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10986. isKnowKey = TRUE;
  10987. }
  10988. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10989. {
  10990. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10992. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10993. {
  10994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  10995. }
  10996. else
  10997. {
  10998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  10999. }
  11000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11001. isKnowKey = TRUE;
  11002. }
  11003. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11004. {
  11005. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11007. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11008. {
  11009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11010. }
  11011. else
  11012. {
  11013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11014. }
  11015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11016. isKnowKey = TRUE;
  11017. }
  11018. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11019. {
  11020. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11022. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11023. {
  11024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11025. }
  11026. else
  11027. {
  11028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11029. }
  11030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11031. isKnowKey = TRUE;
  11032. }
  11033. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11034. {
  11035. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11037. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11038. {
  11039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11040. }
  11041. else
  11042. {
  11043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11044. }
  11045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11046. isKnowKey = TRUE;
  11047. }
  11048. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11049. {
  11050. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11052. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11053. {
  11054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11055. }
  11056. else
  11057. {
  11058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11059. }
  11060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11061. isKnowKey = TRUE;
  11062. }
  11063. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11064. {
  11065. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11067. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11068. {
  11069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11070. }
  11071. else
  11072. {
  11073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11074. }
  11075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11076. isKnowKey = TRUE;
  11077. }
  11078. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11079. {
  11080. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11082. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11083. {
  11084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11085. }
  11086. else
  11087. {
  11088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11089. }
  11090. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11091. isKnowKey = TRUE;
  11092. }
  11093. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11094. {
  11095. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11097. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11098. {
  11099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11100. }
  11101. else
  11102. {
  11103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11104. }
  11105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11106. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11107. isKnowKey = TRUE;
  11108. }
  11109. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11110. {
  11111. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11113. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11114. {
  11115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11116. }
  11117. else
  11118. {
  11119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11120. }
  11121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11122. isKnowKey = TRUE;
  11123. }
  11124. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11125. {
  11126. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11128. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11129. {
  11130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11131. }
  11132. else
  11133. {
  11134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11135. }
  11136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11137. isKnowKey = TRUE;
  11138. }
  11139. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11140. {
  11141. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11143. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11144. {
  11145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11146. }
  11147. else
  11148. {
  11149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11150. }
  11151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11152. isKnowKey = TRUE;
  11153. }
  11154. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11155. {
  11156. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11158. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11159. {
  11160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11161. }
  11162. else
  11163. {
  11164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11165. }
  11166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11167. isKnowKey = TRUE;
  11168. }
  11169. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11170. {
  11171. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11173. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11174. {
  11175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11176. }
  11177. else
  11178. {
  11179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11180. }
  11181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11182. isKnowKey = TRUE;
  11183. }
  11184. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11185. {
  11186. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11188. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11189. {
  11190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11191. }
  11192. else
  11193. {
  11194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11195. }
  11196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11197. isKnowKey = TRUE;
  11198. }
  11199. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11200. {
  11201. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11203. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11204. {
  11205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11206. }
  11207. else
  11208. {
  11209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11210. }
  11211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11212. isKnowKey = TRUE;
  11213. }
  11214. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11215. {
  11216. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11218. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11219. {
  11220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11221. }
  11222. else
  11223. {
  11224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11225. }
  11226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11227. isKnowKey = TRUE;
  11228. }
  11229. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11230. {
  11231. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11233. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11234. {
  11235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11236. }
  11237. else
  11238. {
  11239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11240. }
  11241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11242. isKnowKey = TRUE;
  11243. }
  11244. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11245. {
  11246. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11248. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11249. {
  11250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11251. }
  11252. else
  11253. {
  11254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11255. }
  11256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11257. isKnowKey = TRUE;
  11258. }
  11259. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11260. {
  11261. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11263. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11264. {
  11265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11266. }
  11267. else
  11268. {
  11269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11270. }
  11271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11272. isKnowKey = TRUE;
  11273. }
  11274. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11275. {
  11276. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11278. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11279. {
  11280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11281. }
  11282. else
  11283. {
  11284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11285. }
  11286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11287. isKnowKey = TRUE;
  11288. }
  11289. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11290. {
  11291. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11293. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11294. {
  11295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11296. }
  11297. else
  11298. {
  11299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11300. }
  11301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11302. isKnowKey = TRUE;
  11303. }
  11304. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11305. {
  11306. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11308. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11309. {
  11310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11311. }
  11312. else
  11313. {
  11314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11315. }
  11316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11317. isKnowKey = TRUE;
  11318. }
  11319. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11320. {
  11321. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11323. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11324. {
  11325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11326. }
  11327. else
  11328. {
  11329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11330. }
  11331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11332. isKnowKey = TRUE;
  11333. }
  11334. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11335. {
  11336. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11338. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11339. {
  11340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11341. }
  11342. else
  11343. {
  11344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11345. }
  11346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11347. isKnowKey = TRUE;
  11348. }
  11349. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11350. {
  11351. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11353. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11354. {
  11355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11356. }
  11357. else
  11358. {
  11359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11360. }
  11361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11362. isKnowKey = TRUE;
  11363. }
  11364. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11365. {
  11366. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11368. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11369. {
  11370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11371. }
  11372. else
  11373. {
  11374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11375. }
  11376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11377. isKnowKey = TRUE;
  11378. }
  11379. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11380. {
  11381. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11383. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11384. {
  11385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11386. }
  11387. else
  11388. {
  11389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11390. }
  11391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11392. isKnowKey = TRUE;
  11393. }
  11394. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11395. {
  11396. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11398. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11399. {
  11400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11401. }
  11402. else
  11403. {
  11404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11405. }
  11406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11407. isKnowKey = TRUE;
  11408. }
  11409. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11410. {
  11411. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11413. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11414. {
  11415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11416. }
  11417. else
  11418. {
  11419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11420. }
  11421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11422. isKnowKey = TRUE;
  11423. }
  11424. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11425. {
  11426. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11428. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11429. {
  11430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11431. }
  11432. else
  11433. {
  11434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11435. }
  11436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11437. isKnowKey = TRUE;
  11438. }
  11439. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11440. {
  11441. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11443. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11444. {
  11445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11446. }
  11447. else
  11448. {
  11449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11450. }
  11451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11452. isKnowKey = TRUE;
  11453. }
  11454. #if 1
  11455. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11456. {
  11457. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11459. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11460. {
  11461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11462. }
  11463. else
  11464. {
  11465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11466. }
  11467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11468. isKnowKey = TRUE;
  11469. }
  11470. #endif
  11471. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11472. {
  11473. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11475. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11476. {
  11477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11478. }
  11479. else
  11480. {
  11481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11482. }
  11483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11484. isKnowKey = TRUE;
  11485. }
  11486. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11487. {
  11488. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11490. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11491. {
  11492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11493. }
  11494. else
  11495. {
  11496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11497. }
  11498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11499. isKnowKey = TRUE;
  11500. }
  11501. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11502. {
  11503. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11505. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11506. {
  11507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11508. }
  11509. else
  11510. {
  11511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11512. }
  11513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11514. isKnowKey = TRUE;
  11515. }
  11516. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11517. {
  11518. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11520. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11521. {
  11522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11523. }
  11524. else
  11525. {
  11526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11527. }
  11528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11529. isKnowKey = TRUE;
  11530. }
  11531. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11532. {
  11533. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11535. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11536. {
  11537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11538. }
  11539. else
  11540. {
  11541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11542. }
  11543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11544. isKnowKey = TRUE;
  11545. }
  11546. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11547. {
  11548. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11550. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11551. {
  11552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11553. }
  11554. else
  11555. {
  11556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11557. }
  11558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11559. isKnowKey = TRUE;
  11560. }
  11561. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11562. {
  11563. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11565. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11566. {
  11567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11568. }
  11569. else
  11570. {
  11571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11572. }
  11573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11574. isKnowKey = TRUE;
  11575. }
  11576. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11577. {
  11578. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11580. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11581. {
  11582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11583. }
  11584. else
  11585. {
  11586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11587. }
  11588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11589. isKnowKey = TRUE;
  11590. }
  11591. //=========================================================
  11592. if(!isEmpty && !isKnowKey)
  11593. {
  11594. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11595. strcpy(unknownkey[UnknownKeynum], keyReq);
  11596. UnknownKeynum = UnknownKeynum + 1;
  11597. }
  11598. }
  11599. void processUnkownKey(void)
  11600. {
  11601. DEBUG_INFO("processUnkownKey...\n");
  11602. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11603. for(int index=0; index < UnknownKeynum; index++)
  11604. {
  11605. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11606. {
  11607. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11608. }
  11609. }
  11610. }
  11611. int setKeyValue(char *key, char *value)
  11612. {
  11613. int isSuccess = NotSupported;
  11614. int check_ascii=0;
  11615. char str[10]={0};
  11616. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11617. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11618. {
  11619. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11620. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11621. {
  11622. strcpy(str, (const char*)value);
  11623. for(int i = 0; str[i]; i++){
  11624. str[i] = tolower(str[i]);
  11625. }
  11626. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11627. isSuccess = ConfigurationStatus_Accepted;
  11628. }
  11629. else
  11630. {
  11631. isSuccess = ConfigurationStatus_Rejected;
  11632. }
  11633. }
  11634. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11635. {
  11636. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11637. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11638. {
  11639. strcpy(str, (const char*)value);
  11640. for(int i = 0; str[i]; i++){
  11641. str[i] = tolower(str[i]);
  11642. }
  11643. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11644. isSuccess = ConfigurationStatus_Accepted;
  11645. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11646. }
  11647. else
  11648. {
  11649. isSuccess = ConfigurationStatus_Rejected;
  11650. }
  11651. }
  11652. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11653. {
  11654. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11655. {
  11656. strcpy(str, (const char*)value);
  11657. for(int i = 0; str[i]; i++)
  11658. {
  11659. str[i] = tolower(str[i]);
  11660. }
  11661. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11662. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11663. isSuccess = ConfigurationStatus_Accepted;
  11664. }
  11665. else
  11666. {
  11667. isSuccess = ConfigurationStatus_Rejected;
  11668. }
  11669. }
  11670. if(strcmp(key, "BlinkRepeat") == 0)
  11671. {
  11672. //Charger.BlinkRepeat = Integer.parseInt(value);
  11673. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11674. {
  11675. check_ascii = value[0];
  11676. if( (check_ascii < 48) || (check_ascii > 57) )
  11677. {
  11678. isSuccess = ConfigurationStatus_Rejected;
  11679. }
  11680. else
  11681. {
  11682. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11683. isSuccess = ConfigurationStatus_Accepted;
  11684. }
  11685. }
  11686. else
  11687. {
  11688. isSuccess = ConfigurationStatus_Rejected;
  11689. }
  11690. }
  11691. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11692. {
  11693. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11694. {
  11695. check_ascii = value[0];
  11696. if( (check_ascii < 48) || (check_ascii > 57) )
  11697. {
  11698. isSuccess = ConfigurationStatus_Rejected;
  11699. }
  11700. else
  11701. {
  11702. if((atoi(value) == 0) || (atoi(value) >= 10))
  11703. {
  11704. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11705. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11706. isSuccess = ConfigurationStatus_Accepted;
  11707. }
  11708. else
  11709. isSuccess = ConfigurationStatus_Rejected;
  11710. }
  11711. }
  11712. else
  11713. {
  11714. isSuccess = ConfigurationStatus_Rejected;
  11715. }
  11716. }
  11717. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11718. {
  11719. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11720. {
  11721. check_ascii = value[0];
  11722. if( (check_ascii < 48) || (check_ascii > 57) )
  11723. {
  11724. isSuccess = ConfigurationStatus_Rejected;
  11725. }
  11726. else
  11727. {
  11728. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11729. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11730. isSuccess = ConfigurationStatus_Accepted;
  11731. }
  11732. }
  11733. else
  11734. {
  11735. isSuccess = ConfigurationStatus_Rejected;
  11736. }
  11737. }
  11738. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11739. {
  11740. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11741. {
  11742. check_ascii = value[0];
  11743. if( (check_ascii < 48) || (check_ascii > 57) )
  11744. {
  11745. isSuccess = ConfigurationStatus_Rejected;
  11746. }
  11747. else
  11748. {
  11749. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11750. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11751. isSuccess = ConfigurationStatus_Accepted;
  11752. }
  11753. }
  11754. else
  11755. {
  11756. isSuccess = ConfigurationStatus_Rejected;
  11757. }
  11758. }
  11759. if(strcmp(key, "HeartbeatInterval") == 0)
  11760. {
  11761. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].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. if((atoi(value) == 0) || (atoi(value) >= 10))
  11771. {
  11772. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11773. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11774. HeartBeatWaitTime = atoi(value);
  11775. isSuccess = ConfigurationStatus_Accepted;
  11776. }
  11777. else
  11778. {
  11779. isSuccess = ConfigurationStatus_Rejected;
  11780. }
  11781. }
  11782. }
  11783. else
  11784. {
  11785. isSuccess = ConfigurationStatus_Rejected;
  11786. }
  11787. }
  11788. if(strcmp(key, "LightIntensity") == 0)
  11789. {
  11790. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11791. {
  11792. check_ascii = value[0];
  11793. if( (check_ascii < 48) || (check_ascii > 57) )
  11794. {
  11795. isSuccess = ConfigurationStatus_Rejected;
  11796. }
  11797. else
  11798. {
  11799. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11800. isSuccess = ConfigurationStatus_Accepted;
  11801. }
  11802. }
  11803. else
  11804. {
  11805. isSuccess = ConfigurationStatus_Rejected;
  11806. }
  11807. }
  11808. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11809. {
  11810. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11811. {
  11812. strcpy(str, (const char*)value);
  11813. for(int i = 0; str[i]; i++)
  11814. {
  11815. str[i] = tolower(str[i]);
  11816. }
  11817. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11818. isSuccess = ConfigurationStatus_Accepted;
  11819. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11820. }
  11821. else
  11822. {
  11823. isSuccess = ConfigurationStatus_Rejected;
  11824. }
  11825. }
  11826. if(strcmp(key, "LocalPreAuthorize") == 0)
  11827. {
  11828. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11829. {
  11830. strcpy(str, (const char*)value);
  11831. for(int i = 0; str[i]; i++)
  11832. {
  11833. str[i] = tolower(str[i]);
  11834. }
  11835. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11836. isSuccess = ConfigurationStatus_Accepted;
  11837. }
  11838. else
  11839. {
  11840. isSuccess = ConfigurationStatus_Rejected;
  11841. }
  11842. }
  11843. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11844. {
  11845. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11846. {
  11847. check_ascii = value[0];
  11848. if( (check_ascii < 48) || (check_ascii > 57) )
  11849. {
  11850. isSuccess = ConfigurationStatus_Rejected;
  11851. }
  11852. else
  11853. {
  11854. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11855. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11856. isSuccess = ConfigurationStatus_Accepted;
  11857. }
  11858. }
  11859. else
  11860. {
  11861. isSuccess = ConfigurationStatus_Rejected;
  11862. }
  11863. }
  11864. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11865. {
  11866. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11867. {
  11868. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11869. isSuccess = ConfigurationStatus_Accepted;
  11870. }
  11871. else
  11872. {
  11873. isSuccess = ConfigurationStatus_Rejected;
  11874. }
  11875. }
  11876. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11877. {
  11878. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11879. {
  11880. check_ascii = value[0];
  11881. if( (check_ascii < 48) || (check_ascii > 57) )
  11882. {
  11883. isSuccess = ConfigurationStatus_Rejected;
  11884. }
  11885. else
  11886. {
  11887. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11888. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11889. isSuccess = ConfigurationStatus_Accepted;
  11890. }
  11891. }
  11892. else
  11893. {
  11894. isSuccess = ConfigurationStatus_Rejected;
  11895. }
  11896. }
  11897. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11898. {
  11899. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11900. {
  11901. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11902. isSuccess = ConfigurationStatus_Accepted;
  11903. }
  11904. else
  11905. {
  11906. isSuccess = ConfigurationStatus_Rejected;
  11907. }
  11908. }
  11909. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11910. {
  11911. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11912. {
  11913. check_ascii = value[0];
  11914. if( (check_ascii < 48) || (check_ascii > 57) )
  11915. {
  11916. isSuccess = ConfigurationStatus_Rejected;
  11917. }
  11918. else
  11919. {
  11920. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11922. isSuccess = ConfigurationStatus_Accepted;
  11923. }
  11924. }
  11925. else
  11926. {
  11927. isSuccess = ConfigurationStatus_Rejected;
  11928. }
  11929. }
  11930. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11931. {
  11932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11933. {
  11934. check_ascii = value[0];
  11935. if( (check_ascii < 48) || (check_ascii > 57) )
  11936. {
  11937. isSuccess = ConfigurationStatus_Rejected;
  11938. }
  11939. else
  11940. {
  11941. if((atoi(value) == 0) || (atoi(value) >= 10))
  11942. {
  11943. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11944. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11945. isSuccess = ConfigurationStatus_Accepted;
  11946. }
  11947. else
  11948. {
  11949. isSuccess = ConfigurationStatus_Rejected;
  11950. }
  11951. }
  11952. }
  11953. else
  11954. {
  11955. isSuccess = ConfigurationStatus_Rejected;
  11956. }
  11957. }
  11958. if(strcmp(key, "MinimumStatusDuration") == 0)
  11959. {
  11960. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11961. {
  11962. check_ascii = value[0];
  11963. if( (check_ascii < 48) || (check_ascii > 57) )
  11964. {
  11965. isSuccess = ConfigurationStatus_Rejected;
  11966. }
  11967. else
  11968. {
  11969. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  11970. {
  11971. isSuccess = ConfigurationStatus_Rejected;
  11972. }
  11973. else
  11974. {
  11975. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  11976. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  11977. server_cycle_Status = atoi(value); //StatusNotification Cycle
  11978. isSuccess = ConfigurationStatus_Accepted;
  11979. }
  11980. }
  11981. }
  11982. else
  11983. {
  11984. isSuccess = ConfigurationStatus_Rejected;
  11985. }
  11986. }
  11987. if(strcmp(key, "NumberOfConnectors") == 0)
  11988. {
  11989. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11990. {
  11991. check_ascii = value[0];
  11992. if( (check_ascii < 48) || (check_ascii > 57) )
  11993. {
  11994. isSuccess = ConfigurationStatus_Rejected;
  11995. }
  11996. else
  11997. {
  11998. //Charger.ResetRetries = Integer.parseInt(value);
  11999. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12000. isSuccess = ConfigurationStatus_Accepted;
  12001. }
  12002. }
  12003. else
  12004. {
  12005. isSuccess = ConfigurationStatus_Rejected;
  12006. }
  12007. }
  12008. if(strcmp(key, "ResetRetries") == 0)
  12009. {
  12010. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12011. {
  12012. check_ascii = value[0];
  12013. if( (check_ascii < 48) || (check_ascii > 57) )
  12014. {
  12015. isSuccess = ConfigurationStatus_Rejected;
  12016. }
  12017. else
  12018. {
  12019. //Charger.ResetRetries = Integer.parseInt(value);
  12020. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12021. isSuccess = ConfigurationStatus_Accepted;
  12022. }
  12023. }
  12024. else
  12025. {
  12026. isSuccess = ConfigurationStatus_Rejected;
  12027. }
  12028. }
  12029. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12030. {
  12031. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12032. {
  12033. strcpy(str, (const char*)value);
  12034. for(int i = 0; str[i]; i++)
  12035. {
  12036. str[i] = tolower(str[i]);
  12037. }
  12038. if(strcmp(str, "notapplicable")== 0)
  12039. {
  12040. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12041. isSuccess = ConfigurationStatus_Accepted;
  12042. }
  12043. else if(strcmp(str, "unknown")== 0)
  12044. {
  12045. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12046. isSuccess = ConfigurationStatus_Accepted;
  12047. }
  12048. else if(strcmp(str, "rst")== 0)
  12049. {
  12050. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12051. isSuccess = ConfigurationStatus_Accepted;
  12052. }
  12053. else if(strcmp(str, "rts")== 0)
  12054. {
  12055. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12056. isSuccess = ConfigurationStatus_Accepted;
  12057. }
  12058. else if(strcmp(str, "srt")== 0)
  12059. {
  12060. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12061. isSuccess = ConfigurationStatus_Accepted;
  12062. }
  12063. else if(strcmp(str, "str")== 0)
  12064. {
  12065. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12066. isSuccess = ConfigurationStatus_Accepted;
  12067. }
  12068. else if(strcmp(str, "trs")== 0)
  12069. {
  12070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12071. isSuccess = ConfigurationStatus_Accepted;
  12072. }
  12073. else if(strcmp(str, "tsr")== 0)
  12074. {
  12075. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12076. isSuccess = ConfigurationStatus_Accepted;
  12077. }
  12078. else
  12079. {
  12080. isSuccess = ConfigurationStatus_Rejected;
  12081. }
  12082. }
  12083. else
  12084. {
  12085. isSuccess = ConfigurationStatus_Rejected;
  12086. }
  12087. }
  12088. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12089. {
  12090. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12091. {
  12092. check_ascii = value[0];
  12093. if( (check_ascii < 48) || (check_ascii > 57) )
  12094. {
  12095. isSuccess = ConfigurationStatus_Rejected;
  12096. }
  12097. else
  12098. {
  12099. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12100. isSuccess = ConfigurationStatus_Accepted;
  12101. }
  12102. }
  12103. else
  12104. {
  12105. isSuccess = ConfigurationStatus_Rejected;
  12106. }
  12107. }
  12108. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12109. {
  12110. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12111. {
  12112. strcpy(str, (const char*)value);
  12113. for(int i = 0; str[i]; i++)
  12114. {
  12115. str[i] = tolower(str[i]);
  12116. }
  12117. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12118. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12119. isSuccess = ConfigurationStatus_Accepted;
  12120. }
  12121. else
  12122. {
  12123. isSuccess = ConfigurationStatus_Rejected;
  12124. }
  12125. }
  12126. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12127. {
  12128. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12129. {
  12130. strcpy(str, (const char*)value);
  12131. for(int i = 0; str[i]; i++)
  12132. {
  12133. str[i] = tolower(str[i]);
  12134. }
  12135. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12136. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12137. isSuccess = ConfigurationStatus_Accepted;
  12138. }
  12139. else
  12140. {
  12141. isSuccess = ConfigurationStatus_Rejected;
  12142. }
  12143. }
  12144. if(strcmp(key, "StopTxnAlignedData") == 0)
  12145. {
  12146. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12147. {
  12148. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12149. isSuccess = ConfigurationStatus_Accepted;
  12150. }
  12151. else
  12152. {
  12153. isSuccess = ConfigurationStatus_Rejected;
  12154. }
  12155. }
  12156. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12157. {
  12158. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12159. {
  12160. check_ascii = value[0];
  12161. if( (check_ascii < 48) || (check_ascii > 57) )
  12162. {
  12163. isSuccess = ConfigurationStatus_Rejected;
  12164. }
  12165. else
  12166. {
  12167. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12168. isSuccess = ConfigurationStatus_Accepted;
  12169. }
  12170. }
  12171. else
  12172. {
  12173. isSuccess = ConfigurationStatus_Rejected;
  12174. }
  12175. }
  12176. if(strcmp(key, "StopTxnSampledData") == 0)
  12177. {
  12178. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12179. {
  12180. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12181. isSuccess = ConfigurationStatus_Accepted;
  12182. }
  12183. else
  12184. {
  12185. isSuccess = ConfigurationStatus_Rejected;
  12186. }
  12187. }
  12188. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12189. {
  12190. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12191. {
  12192. check_ascii = value[0];
  12193. if( (check_ascii < 48) || (check_ascii > 57) )
  12194. {
  12195. isSuccess = ConfigurationStatus_Rejected;
  12196. }
  12197. else
  12198. {
  12199. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12200. isSuccess = ConfigurationStatus_Accepted;
  12201. }
  12202. }
  12203. else
  12204. {
  12205. isSuccess = ConfigurationStatus_Rejected;
  12206. }
  12207. }
  12208. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12209. {
  12210. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12211. {
  12212. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12213. isSuccess = ConfigurationStatus_Accepted;
  12214. }
  12215. else
  12216. {
  12217. isSuccess = ConfigurationStatus_Rejected;
  12218. }
  12219. }
  12220. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12221. {
  12222. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12223. {
  12224. check_ascii = value[0];
  12225. if( (check_ascii < 48) || (check_ascii > 57) )
  12226. {
  12227. isSuccess = ConfigurationStatus_Rejected;
  12228. }
  12229. else
  12230. {
  12231. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12232. isSuccess = ConfigurationStatus_Accepted;
  12233. }
  12234. }
  12235. else
  12236. {
  12237. isSuccess = ConfigurationStatus_Rejected;
  12238. }
  12239. }
  12240. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12241. {
  12242. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12243. {
  12244. check_ascii = value[0];
  12245. if( (check_ascii < 48) || (check_ascii > 57) )
  12246. {
  12247. isSuccess = ConfigurationStatus_Rejected;
  12248. }
  12249. else
  12250. {
  12251. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12252. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12253. TransactionMessageAttemptsValue = atoi(value);
  12254. isSuccess = ConfigurationStatus_Accepted;
  12255. }
  12256. }
  12257. else
  12258. {
  12259. isSuccess = ConfigurationStatus_Rejected;
  12260. }
  12261. }
  12262. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12263. {
  12264. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12265. {
  12266. check_ascii = value[0];
  12267. if( (check_ascii < 48) || (check_ascii > 57) )
  12268. {
  12269. isSuccess = ConfigurationStatus_Rejected;
  12270. }
  12271. else
  12272. {
  12273. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12274. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12275. TransactionMessageRetryIntervalValue = atoi(value);
  12276. isSuccess = ConfigurationStatus_Accepted;
  12277. }
  12278. }
  12279. else
  12280. {
  12281. isSuccess = ConfigurationStatus_Rejected;
  12282. }
  12283. }
  12284. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12285. {
  12286. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12287. {
  12288. strcpy(str, (const char*)value);
  12289. for(int i = 0; str[i]; i++)
  12290. {
  12291. str[i] = tolower(str[i]);
  12292. }
  12293. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12294. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12295. isSuccess = ConfigurationStatus_Accepted;
  12296. }
  12297. else
  12298. {
  12299. isSuccess = ConfigurationStatus_Rejected;
  12300. }
  12301. }
  12302. if(strcmp(key, "WebSocketPingInterval") == 0)
  12303. {
  12304. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12305. {
  12306. check_ascii = value[0];
  12307. if( (check_ascii < 48) || (check_ascii > 57) )
  12308. {
  12309. isSuccess = ConfigurationStatus_Rejected;
  12310. }
  12311. else
  12312. {
  12313. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12314. isSuccess = ConfigurationStatus_Accepted;
  12315. }
  12316. }
  12317. else
  12318. {
  12319. isSuccess = ConfigurationStatus_Rejected;
  12320. }
  12321. }
  12322. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12323. {
  12324. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12325. {
  12326. strcpy(str, (const char*)value);
  12327. for(int i = 0; str[i]; i++)
  12328. {
  12329. str[i] = tolower(str[i]);
  12330. }
  12331. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12332. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12333. isSuccess = ConfigurationStatus_Accepted;
  12334. }
  12335. else
  12336. {
  12337. isSuccess = ConfigurationStatus_Rejected;
  12338. }
  12339. }
  12340. #if 0
  12341. //For OCPP Test Case
  12342. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12343. {
  12344. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12345. {
  12346. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12347. isSuccess = ConfigurationStatus_Accepted;
  12348. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12349. }
  12350. else
  12351. {
  12352. isSuccess = ConfigurationStatus_Rejected;
  12353. }
  12354. }
  12355. #endif
  12356. #if 1
  12357. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12358. {
  12359. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12360. {
  12361. strcpy(str, (const char*)value);
  12362. for(int i = 0; str[i]; i++)
  12363. {
  12364. str[i] = tolower(str[i]);
  12365. }
  12366. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12367. isSuccess = ConfigurationStatus_Accepted;
  12368. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12369. }
  12370. else
  12371. {
  12372. isSuccess = ConfigurationStatus_Rejected;
  12373. }
  12374. }
  12375. #endif
  12376. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12377. {
  12378. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12379. {
  12380. check_ascii = value[0];
  12381. if( (check_ascii < 48) || (check_ascii > 57) )
  12382. {
  12383. isSuccess = ConfigurationStatus_Rejected;
  12384. }
  12385. else
  12386. {
  12387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12388. isSuccess = ConfigurationStatus_Accepted;
  12389. }
  12390. }
  12391. else
  12392. {
  12393. isSuccess = ConfigurationStatus_Rejected;
  12394. }
  12395. }
  12396. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12397. {
  12398. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12399. {
  12400. check_ascii = value[0];
  12401. if( (check_ascii < 48) || (check_ascii > 57) )
  12402. {
  12403. isSuccess = ConfigurationStatus_Rejected;
  12404. }
  12405. else
  12406. {
  12407. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12408. isSuccess = ConfigurationStatus_Accepted;
  12409. }
  12410. }
  12411. else
  12412. {
  12413. isSuccess = ConfigurationStatus_Rejected;
  12414. }
  12415. }
  12416. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12417. {
  12418. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12419. {
  12420. strcpy(str, (const char*)value);
  12421. for(int i = 0; str[i]; i++)
  12422. {
  12423. str[i] = tolower(str[i]);
  12424. }
  12425. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12426. isSuccess = ConfigurationStatus_Accepted;
  12427. }
  12428. else
  12429. {
  12430. isSuccess = ConfigurationStatus_Rejected;
  12431. }
  12432. }
  12433. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12434. {
  12435. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12436. {
  12437. check_ascii = value[0];
  12438. if( (check_ascii < 48) || (check_ascii > 57) )
  12439. {
  12440. isSuccess = ConfigurationStatus_Rejected;
  12441. }
  12442. else
  12443. {
  12444. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12445. isSuccess = ConfigurationStatus_Accepted;
  12446. }
  12447. }
  12448. else
  12449. {
  12450. isSuccess = ConfigurationStatus_Rejected;
  12451. }
  12452. }
  12453. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12454. {
  12455. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12456. {
  12457. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12458. isSuccess = ConfigurationStatus_Accepted;
  12459. }
  12460. else
  12461. {
  12462. isSuccess = ConfigurationStatus_Rejected;
  12463. }
  12464. }
  12465. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12466. {
  12467. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12468. {
  12469. check_ascii = value[0];
  12470. if( (check_ascii < 48) || (check_ascii > 57) )
  12471. {
  12472. isSuccess = ConfigurationStatus_Rejected;
  12473. }
  12474. else
  12475. {
  12476. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12477. isSuccess = ConfigurationStatus_Accepted;
  12478. }
  12479. }
  12480. else
  12481. {
  12482. isSuccess = ConfigurationStatus_Rejected;
  12483. }
  12484. }
  12485. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12486. {
  12487. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12488. {
  12489. strcpy(str, (const char*)value);
  12490. for(int i = 0; str[i]; i++)
  12491. {
  12492. str[i] = tolower(str[i]);
  12493. }
  12494. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12495. isSuccess = ConfigurationStatus_Accepted;
  12496. }
  12497. else
  12498. {
  12499. isSuccess = ConfigurationStatus_Rejected;
  12500. }
  12501. }
  12502. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12503. {
  12504. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12505. {
  12506. check_ascii = value[0];
  12507. if( (check_ascii < 48) || (check_ascii > 57) )
  12508. {
  12509. isSuccess = ConfigurationStatus_Rejected;
  12510. }
  12511. else
  12512. {
  12513. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12514. isSuccess = ConfigurationStatus_Accepted;
  12515. }
  12516. }
  12517. else
  12518. {
  12519. isSuccess = ConfigurationStatus_Rejected;
  12520. }
  12521. }
  12522. return isSuccess;
  12523. }
  12524. int TransactionMessageAttemptsGet(void)
  12525. {
  12526. return TransactionMessageAttemptsValue;
  12527. }
  12528. int FirstHeartBeatResponse(void)
  12529. {
  12530. return FirstHeartBeat;
  12531. }
  12532. int TransactionMessageRetryIntervalGet(void)
  12533. {
  12534. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12535. }
  12536. int ReadHttpStatus(int sock)
  12537. {
  12538. //char c;
  12539. char buff[1024]="",*ptr=buff+1;
  12540. int bytes_received, status;
  12541. DEBUG_INFO("Begin Response ..\n");
  12542. while((bytes_received = recv(sock, ptr, 1, 0))){
  12543. if(bytes_received==-1){
  12544. perror("ReadHttpStatus");
  12545. exit(1);
  12546. }
  12547. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12548. ptr++;
  12549. }
  12550. *ptr=0;
  12551. ptr=buff+1;
  12552. sscanf(ptr,"%*s %d ", &status);
  12553. DEBUG_INFO("%s\n",ptr);
  12554. DEBUG_INFO("status=%d\n",status);
  12555. DEBUG_INFO("End Response ..\n");
  12556. return (bytes_received>0)?status:0;
  12557. }
  12558. //the only filed that it parsed is 'Content-Length'
  12559. int ParseHeader(int sock)
  12560. {
  12561. //char c;
  12562. char buff[1024]="",*ptr=buff+4;
  12563. int bytes_received;
  12564. DEBUG_INFO("Begin HEADER ..\n");
  12565. while((bytes_received = recv(sock, ptr, 1, 0))){
  12566. if(bytes_received==-1){
  12567. perror("Parse Header");
  12568. exit(1);
  12569. }
  12570. if(
  12571. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12572. (ptr[-1]=='\r') && (*ptr=='\n' )
  12573. ) break;
  12574. ptr++;
  12575. }
  12576. *ptr=0;
  12577. ptr=buff+4;
  12578. //printf("%s",ptr);
  12579. if(bytes_received){
  12580. ptr=strstr(ptr,"Content-Length:");
  12581. if(ptr){
  12582. sscanf(ptr,"%*s %d",&bytes_received);
  12583. }else
  12584. bytes_received=-1; //unknown size
  12585. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12586. }
  12587. DEBUG_INFO("End HEADER ..\n");
  12588. return bytes_received ;
  12589. }
  12590. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12591. {
  12592. char rmFileCmd[100]={0};
  12593. char FilePath[100]={0};
  12594. char ftpbuf[200];
  12595. int systemresult;
  12596. //DEBUG_INFO("filename=%s\n",filename);
  12597. //DEBUG_INFO("url=%s\n",url);
  12598. sprintf(FilePath,"/mnt/%s",filename);
  12599. if((access(FilePath,F_OK))!=-1)
  12600. {
  12601. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12602. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12603. system(rmFileCmd);
  12604. }
  12605. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12606. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12607. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12608. systemresult = system(ftpbuf);
  12609. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12610. if(systemresult != 0)
  12611. {
  12612. DEBUG_INFO("http DownLoad error!\n");
  12613. return FALSE;
  12614. }
  12615. return TRUE;
  12616. }
  12617. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12618. {
  12619. char rmFileCmd[100]={0};
  12620. char FilePath[100]={0};
  12621. char ftpbuf[200];
  12622. int systemresult;
  12623. //char temp[100];
  12624. sprintf(FilePath,"/mnt/%s",filename);
  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. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12632. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12633. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12634. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12635. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12636. systemresult = system(ftpbuf);
  12637. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12638. if(systemresult != 0)
  12639. {
  12640. printf("wget error!\n");
  12641. return FALSE;
  12642. }
  12643. return TRUE;
  12644. }
  12645. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12646. {
  12647. char rmFileCmd[100]={0};
  12648. char FilePath[100]={0};
  12649. char ftpbuf[200];
  12650. int systemresult;
  12651. //DEBUG_INFO("filename=%s\n",filename);
  12652. //DEBUG_INFO("url=%s\n",url);
  12653. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12654. if((access(FilePath,F_OK))!=-1)
  12655. {
  12656. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12657. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12658. system(rmFileCmd);
  12659. }
  12660. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12661. if(fp == NULL)
  12662. {
  12663. DEBUG_INFO("log is NULL\n");
  12664. return FALSE;
  12665. }
  12666. else
  12667. {
  12668. fprintf(fp, "%s\n", url);
  12669. fprintf(fp, "%s\n", filename);
  12670. fclose(fp);
  12671. }
  12672. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12673. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12674. systemresult = system(ftpbuf);
  12675. DEBUG_INFO("systemresult = %d\n",systemresult);
  12676. if(systemresult != 0)
  12677. {
  12678. DEBUG_INFO("http upload error!\n");
  12679. return FALSE;
  12680. }
  12681. return TRUE;
  12682. }
  12683. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12684. {
  12685. struct hostent* server;
  12686. char *IPbuffer;
  12687. char ftpbuf[200];
  12688. int systemresult;
  12689. // To retrieve host information
  12690. server = gethostbyname(location);
  12691. // To convert an Internet network
  12692. // address into ASCII string
  12693. IPbuffer = inet_ntoa(*((struct in_addr*)
  12694. server->h_addr_list[0]));
  12695. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12696. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12697. /* format : ftpput -u username -p passwd IP target source*/
  12698. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12699. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12700. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12701. systemresult = system(ftpbuf);
  12702. DEBUG_INFO("systemresult=%d\n",systemresult);
  12703. if(systemresult != 0)
  12704. {
  12705. DEBUG_INFO("ftpput error!\n");
  12706. return FALSE;
  12707. }
  12708. return TRUE;
  12709. }
  12710. /**
  12711. * Place the contents of the specified file into a memory buffer
  12712. *
  12713. * @param[in] filename The path and name of the file to read
  12714. * @param[out] filebuffer A pointer to the contents in memory
  12715. * @return status 0 success, 1 on failure
  12716. */
  12717. int get_file_contents(const char* filename, char** outbuffer) {
  12718. FILE* file = NULL;
  12719. long filesize;
  12720. const int blocksize = 1;
  12721. size_t readsize;
  12722. char* filebuffer;
  12723. // Open the file
  12724. file = fopen(filename, "r");
  12725. if (NULL == file)
  12726. {
  12727. printf("'%s' not opened\n", filename);
  12728. exit(EXIT_FAILURE);
  12729. }
  12730. // Determine the file size
  12731. fseek(file, 0, SEEK_END);
  12732. filesize = ftell(file);
  12733. rewind (file);
  12734. // Allocate memory for the file contents
  12735. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12736. *outbuffer = filebuffer;
  12737. if (filebuffer == NULL)
  12738. {
  12739. fputs ("malloc out-of-memory", stderr);
  12740. exit(EXIT_FAILURE);
  12741. }
  12742. // Read in the file
  12743. readsize = fread(filebuffer, blocksize, filesize, file);
  12744. if (readsize != filesize)
  12745. {
  12746. fputs ("didn't read file completely",stderr);
  12747. exit(EXIT_FAILURE);
  12748. }
  12749. // Clean exit
  12750. fclose(file);
  12751. return EXIT_SUCCESS;
  12752. }
  12753. static int selectSqlCount = 0;
  12754. static int callback(void *data, int argc, char **argv, char **azColName){
  12755. int i;
  12756. //printf("%s: ", (const char*)data);
  12757. selectSqlCount = argc;
  12758. for(i = 0; i<argc; i++){
  12759. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12760. }
  12761. //printf("\n");
  12762. return 0;
  12763. }
  12764. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12765. //int i;
  12766. //printf("%s:\n", (const char*)data);
  12767. localversion = argv[5] ? atoi(argv[5]) : 0;
  12768. //printf("localversion=%d\n", localversion);
  12769. return 0;
  12770. }
  12771. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12772. //int i;
  12773. //printf("%s:\n", (const char*)data);
  12774. //idTag
  12775. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12776. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12777. //parentIdTag
  12778. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12779. //expir_date
  12780. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12781. //status
  12782. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12783. //version
  12784. idTagQuery.listVersionInt = atoi(argv[5]);
  12785. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12786. return 0;
  12787. }
  12788. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12789. {
  12790. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12791. // printf("localversion=%d\n", localversion);
  12792. return 0;
  12793. }
  12794. //=========================================
  12795. // Sqlite3 related function
  12796. //=========================================
  12797. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12798. {
  12799. for (int i = 0; i < n_columns; i++)
  12800. {
  12801. DEBUG_INFO("%s\t", col_values[i]);
  12802. }
  12803. DEBUG_INFO("\n");
  12804. return 0;
  12805. }
  12806. void OCPP_getListVerion()
  12807. {
  12808. int rc = 0;
  12809. // const char* data = "Callback function called";
  12810. char sql[100];
  12811. char zErrMsg[100];
  12812. memset(sql, 0, 100);
  12813. memset(zErrMsg, 0, 100);
  12814. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12815. /* Execute SQL statement */
  12816. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12817. if( rc != SQLITE_OK )
  12818. {
  12819. DEBUG_INFO("SQL error: %s", zErrMsg);
  12820. }
  12821. }
  12822. void OCPP_getIdTag(char idTag[])
  12823. {
  12824. int rc = 0;
  12825. // const char* data = "Callback function called";
  12826. char sql[100];
  12827. char zErrMsg[100];
  12828. memset(sql, 0, 100);
  12829. memset(zErrMsg, 0, 100);
  12830. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  12831. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12832. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12833. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12834. /* Execute SQL statement */
  12835. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12836. if( rc != SQLITE_OK )
  12837. {
  12838. DEBUG_INFO("SQL error: %s", zErrMsg);
  12839. }
  12840. //return ver;
  12841. }
  12842. void OCPP_get_TableAuthlocalAllData(void)
  12843. {
  12844. int rc = 0;
  12845. char sql[100];
  12846. char zErrMsg[100];
  12847. memset(sql, 0, 100);
  12848. memset(zErrMsg, 0, 100);
  12849. sprintf(sql,"select * from ocpp_auth_local ");
  12850. /* Execute SQL statement */
  12851. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12852. if( rc != SQLITE_OK )
  12853. {
  12854. DEBUG_INFO("SQL error: %s", zErrMsg);
  12855. }
  12856. //return ver;
  12857. }
  12858. int OCPP_cleanLocalList()
  12859. {
  12860. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12861. char *errMsg = 0;
  12862. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12863. if (SQLITE_OK != rc)
  12864. {
  12865. DEBUG_INFO("%s\n",errMsg);
  12866. return FALSE;
  12867. }
  12868. return TRUE;
  12869. }
  12870. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12871. {
  12872. int isSuccess = FALSE;
  12873. int ret = 0;
  12874. //const char* data = "Callback function called";
  12875. char sql[300];
  12876. char zErrMsg[200];
  12877. memset(sql, 0, 300);
  12878. memset(zErrMsg, 0, 200);
  12879. 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);
  12880. //* Execute SQL statement */
  12881. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12882. if( ret != SQLITE_OK )
  12883. {
  12884. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12885. return isSuccess;
  12886. }
  12887. memset(sql, 0, 300);
  12888. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  12889. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  12890. if( ret != SQLITE_OK )
  12891. {
  12892. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12893. return isSuccess;
  12894. }
  12895. isSuccess = TRUE;
  12896. return isSuccess;
  12897. }
  12898. void OCPP_deleteIdTag(char idTag[])
  12899. {
  12900. //int ver = 0;
  12901. //int isSuccess = FALSE;
  12902. int rc = 0;
  12903. char sql[100];
  12904. char zErrMsg[100];
  12905. memset(sql, 0, 100);
  12906. memset(zErrMsg, 0, 100);
  12907. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12908. //* Execute SQL statement */
  12909. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12910. if( rc != SQLITE_OK )
  12911. {
  12912. DEBUG_INFO("SQL error: %s", zErrMsg);
  12913. }
  12914. }
  12915. int GetOcppServerURL()
  12916. {
  12917. int result = FALSE;
  12918. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  12919. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  12920. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  12921. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12922. {
  12923. #if 1
  12924. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12925. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12926. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12927. #endif
  12928. result = TRUE;
  12929. goto End;
  12930. }
  12931. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12932. {
  12933. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12934. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12935. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12936. result = TRUE;
  12937. goto End;
  12938. }
  12939. else
  12940. {
  12941. strcpy(OcppHost,"");
  12942. }
  12943. End:
  12944. return result;
  12945. }
  12946. int GetOcppPath()
  12947. {
  12948. int result = FALSE;
  12949. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12950. {
  12951. if(OcppTempPath == NULL)
  12952. {
  12953. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12954. }
  12955. else
  12956. {
  12957. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12958. }
  12959. result = TRUE;
  12960. goto End;
  12961. }
  12962. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12963. {
  12964. if(OcppTempPath == NULL)
  12965. {
  12966. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12967. }
  12968. else
  12969. {
  12970. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12971. }
  12972. result = TRUE;
  12973. goto End;
  12974. }
  12975. else
  12976. {
  12977. strcpy(OcppPath,"");
  12978. }
  12979. End:
  12980. return result;
  12981. }
  12982. int GetOcppPort()
  12983. {
  12984. return OcppPort;
  12985. }
  12986. int GetOcppConnStatus(void)
  12987. {
  12988. return ShmOCPP16Data->OcppConnStatus;
  12989. }
  12990. void SetOcppConnStatus(uint8_t status)
  12991. {
  12992. ShmOCPP16Data->OcppConnStatus = status;
  12993. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12994. }
  12995. int GetHeartBeatWithNOResponse(void)
  12996. {
  12997. return HeartBeatWithNOResponse;
  12998. }
  12999. void SetHeartBeatWithNOResponse(void)
  13000. {
  13001. HeartBeatWithNOResponse = 0;
  13002. }
  13003. void GetStartTransactionIdTag(int gun_index)
  13004. {
  13005. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13006. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13007. }
  13008. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13009. {
  13010. char ch;
  13011. FILE *fptr1;
  13012. int temptransactionId;
  13013. char str[100]={0};
  13014. temptransactionId = 0;
  13015. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  13016. {
  13017. DEBUG_INFO("IdTag is empty.\n");
  13018. return temptransactionId;
  13019. }
  13020. /*------ Read the file ----------------*/
  13021. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13022. if (!fptr1)
  13023. {
  13024. DEBUG_INFO("QueueTransactionId file open error.\n");
  13025. //printf(" File not found or unable to open the input file!!\n");
  13026. return temptransactionId;
  13027. }
  13028. ch=fgetc(fptr1);
  13029. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13030. rewind(fptr1);
  13031. if(ch!=EOF)
  13032. {
  13033. // printf("%c",ch);
  13034. while (fgets(str, 100, fptr1) != NULL)
  13035. {
  13036. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13037. if(str[0]=='\0')
  13038. {
  13039. break;
  13040. }
  13041. char *revbuf[8] = {0}; //存放分割後的子字串
  13042. int num = 0;//分割後子字串的個數
  13043. DEBUG_INFO("str: %s\n", str);
  13044. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13045. DEBUG_INFO("revbuf[0]: %s\n", revbuf[0]);
  13046. DEBUG_INFO("revbuf[1]: %s\n", revbuf[1]);
  13047. DEBUG_INFO("revbuf[2]: %s\n", revbuf[2]);
  13048. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13049. {
  13050. if(isStopTransaction)
  13051. {
  13052. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13053. {
  13054. temptransactionId = atoi(revbuf[2]);
  13055. break;
  13056. }
  13057. }
  13058. else
  13059. {
  13060. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13061. {
  13062. temptransactionId = atoi(revbuf[2]);
  13063. break;
  13064. }
  13065. }
  13066. }
  13067. }
  13068. }
  13069. else
  13070. DEBUG_INFO("EOF\n");
  13071. fclose(fptr1);
  13072. /*------- End of reading ---------------*/
  13073. return temptransactionId;
  13074. }
  13075. void SetTransactionIdZero(int transactionId)
  13076. {
  13077. char ch;
  13078. FILE *fptr1, *fptr2;
  13079. int temptransactionId = 0;
  13080. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13081. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13082. if (!fptr1)
  13083. {
  13084. //printf(" File not found or unable to open the input file!!\n");
  13085. return ;
  13086. }
  13087. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13088. if (!fptr2)
  13089. {
  13090. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13091. fclose(fptr1);
  13092. return ;
  13093. }
  13094. ch=fgetc(fptr1);
  13095. rewind(fptr1);
  13096. if(ch!=EOF)
  13097. {
  13098. // copy all contents to the temporary file except the specific line
  13099. while (fgets(str, 100, fptr1) != NULL)
  13100. {
  13101. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13102. if(str[0]=='\0')
  13103. {
  13104. break;
  13105. }
  13106. char *revbuf[8] = {0};
  13107. int num = 0;
  13108. strcpy(strtemp, str);
  13109. splitstring(str,",",revbuf,&num);
  13110. if(revbuf[2][0] != '\0')
  13111. {
  13112. temptransactionId = atoi(revbuf[2]);
  13113. if(transactionId != temptransactionId)
  13114. {
  13115. fprintf(fptr2, "%s\n", strtemp);
  13116. }
  13117. }
  13118. }
  13119. }
  13120. fclose(fptr1);
  13121. fclose(fptr2);
  13122. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13123. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13124. /*------ Read the file ----------------*/
  13125. }
  13126. int InternetDisconnect(void)
  13127. {
  13128. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13129. }
  13130. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13131. void storeTempStopTransaction(int gun_index)
  13132. {
  13133. char guid[37]={0};
  13134. int tempIndex = 0;
  13135. char TempStopTransaction[256];
  13136. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13137. DEBUG_INFO("storeTempStopTransaction...\n");
  13138. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13139. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13140. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13141. if(gunType[gun_index] == 'J')
  13142. {
  13143. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13144. {
  13145. tempIndex = ((gun_index==2) ? 1: 0);
  13146. }
  13147. else
  13148. {
  13149. tempIndex = gun_index;
  13150. }
  13151. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13152. {
  13153. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13154. {
  13155. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13156. }
  13157. }// END OF CHAdeMO_QUANTITY
  13158. }
  13159. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13160. {
  13161. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13162. {
  13163. tempIndex = ((gun_index==2) ? 1: 0);
  13164. }
  13165. else
  13166. {
  13167. tempIndex = gun_index;
  13168. }
  13169. for (int index = 0; index < CCS_QUANTITY; index++)
  13170. {
  13171. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13172. {
  13173. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13174. }
  13175. }// END OF CCS_QUANTITY
  13176. }
  13177. else if(gunType[gun_index] == 'G')
  13178. {
  13179. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13180. {
  13181. tempIndex = ((gun_index==2) ? 1: 0);
  13182. }
  13183. else
  13184. {
  13185. tempIndex = gun_index;
  13186. }
  13187. for (int index = 0; index < GB_QUANTITY; index++)
  13188. {
  13189. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13190. {
  13191. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13192. }
  13193. }// END OF GB_QUANTITY
  13194. }
  13195. else
  13196. {
  13197. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13198. {
  13199. tempIndex = 2;
  13200. }
  13201. else
  13202. {
  13203. tempIndex = gun_index;
  13204. }
  13205. for (int index = 0; index < AC_QUANTITY; index++)
  13206. {
  13207. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13208. {
  13209. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13210. }
  13211. }// END OF AC_QUANTITY
  13212. }
  13213. //Stop Transaction Time
  13214. struct timeval tmnow;
  13215. struct tm *tm;
  13216. char buf[28];//, usec_buf[6];
  13217. gettimeofday(&tmnow, NULL);
  13218. time_t t;
  13219. t = time(NULL);
  13220. /*UTC time and date*/
  13221. tm = gmtime(&t);
  13222. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13223. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13224. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13225. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13226. random_uuid(guid);
  13227. /***********************************transactionData******************************************************/
  13228. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13229. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13230. //=================================
  13231. //1. Transaction_Begin
  13232. //=================================
  13233. //============================== Energy.Active.Import.Interval ===========================================
  13234. //idx_sample=0;
  13235. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  13236. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13237. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13238. 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*/]);
  13239. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13240. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13241. {
  13242. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13243. }
  13244. else
  13245. {
  13246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13247. }
  13248. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13249. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13250. //=================================
  13251. //2. Transaction_End
  13252. //=================================
  13253. //2.1====================================== Current.Import L1 ==============================================
  13254. //idx_sample=1;
  13255. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13256. if(gunType[gun_index] == 'J')
  13257. {
  13258. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13259. {
  13260. tempIndex = ((gun_index==2) ? 1: 0);
  13261. }
  13262. else
  13263. {
  13264. tempIndex = gun_index;
  13265. }
  13266. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13267. {
  13268. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13269. {
  13270. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13271. }
  13272. }// End of for CHAdeMO_QUANTITY
  13273. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13274. }
  13275. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13276. {
  13277. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13278. {
  13279. tempIndex = ((gun_index==2) ? 1: 0);
  13280. }
  13281. else
  13282. {
  13283. tempIndex = gun_index;
  13284. }
  13285. for (int index = 0; index < CCS_QUANTITY; index++)
  13286. {
  13287. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13288. {
  13289. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13290. }
  13291. }// End of for CCS_QUANTITY
  13292. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13293. }
  13294. else if(gunType[gun_index] == 'G')
  13295. {
  13296. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13297. {
  13298. tempIndex = ((gun_index==2) ? 1: 0);
  13299. }
  13300. else
  13301. {
  13302. tempIndex = gun_index;
  13303. }
  13304. for (int index = 0; index < GB_QUANTITY; index++)
  13305. {
  13306. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13307. {
  13308. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13309. }
  13310. }// End of for GB_QUANTITY
  13311. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13312. }
  13313. else
  13314. {
  13315. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13316. {
  13317. tempIndex = 2;
  13318. }
  13319. else
  13320. {
  13321. tempIndex = gun_index;
  13322. }
  13323. for (int index = 0; index < AC_QUANTITY; index++)
  13324. {
  13325. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13326. {
  13327. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13328. }
  13329. }// End of for AC_QUANTITY
  13330. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13331. }
  13332. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13333. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13334. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13335. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13336. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13337. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13338. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13339. //idx_sample=2;
  13340. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13341. if(gunType[gun_index] == 'J')
  13342. {
  13343. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13344. {
  13345. tempIndex = ((gun_index==2) ? 1: 0);
  13346. }
  13347. else
  13348. {
  13349. tempIndex = gun_index;
  13350. }
  13351. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13352. {
  13353. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13354. {
  13355. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13356. }
  13357. }// END OF CHAdeMO_QUANTITY
  13358. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13359. }
  13360. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13361. {
  13362. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13363. {
  13364. tempIndex = ((gun_index==2) ? 1: 0);
  13365. }
  13366. else
  13367. {
  13368. tempIndex = gun_index;
  13369. }
  13370. for (int index = 0; index < CCS_QUANTITY; index++)
  13371. {
  13372. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13373. {
  13374. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13375. }
  13376. }// END OF CCS_QUANTITY
  13377. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13378. }
  13379. else if(gunType[gun_index] == 'G')
  13380. {
  13381. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13382. {
  13383. tempIndex = ((gun_index==2) ? 1: 0);
  13384. }
  13385. else
  13386. {
  13387. tempIndex = gun_index;
  13388. }
  13389. for (int index = 0; index < GB_QUANTITY; index++)
  13390. {
  13391. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13392. {
  13393. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13394. }
  13395. }// END OF GB_QUANTITY
  13396. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13397. }
  13398. else
  13399. {
  13400. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13401. {
  13402. tempIndex = 2;
  13403. }
  13404. else
  13405. {
  13406. tempIndex = gun_index;
  13407. }
  13408. for (int index = 0; index < AC_QUANTITY; index++)
  13409. {
  13410. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13411. {
  13412. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13413. }
  13414. }// END OF AC_QUANTITY
  13415. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13416. }
  13417. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13418. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13419. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13420. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13421. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13423. //2.3====================================== Power.Active.Import =========================================
  13424. //idx_sample=3;
  13425. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13426. if(gunType[gun_index] == 'J')
  13427. {
  13428. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13429. {
  13430. tempIndex = ((gun_index==2) ? 1: 0);
  13431. }
  13432. else
  13433. {
  13434. tempIndex = gun_index;
  13435. }
  13436. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13437. {
  13438. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13439. {
  13440. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13441. }
  13442. } // End for CHAdeMO_QUANTITY
  13443. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13444. }
  13445. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13446. {
  13447. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13448. {
  13449. tempIndex = ((gun_index==2) ? 1: 0);
  13450. }
  13451. else
  13452. {
  13453. tempIndex = gun_index;
  13454. }
  13455. for (int index = 0; index < CCS_QUANTITY; index++)
  13456. {
  13457. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13458. {
  13459. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13460. }
  13461. } // END for CCS_QUANTITY
  13462. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13463. }
  13464. else if(gunType[gun_index] == 'G')
  13465. {
  13466. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13467. {
  13468. tempIndex = ((gun_index==2) ? 1: 0);
  13469. }
  13470. else
  13471. {
  13472. tempIndex = gun_index;
  13473. }
  13474. for (int index = 0; index < GB_QUANTITY; index++)
  13475. {
  13476. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13477. {
  13478. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13479. }
  13480. }// END for GB_QUANTITY
  13481. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13482. }
  13483. else
  13484. {
  13485. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13486. {
  13487. tempIndex = 2;
  13488. }
  13489. else
  13490. {
  13491. tempIndex = gun_index;
  13492. }
  13493. for (int index = 0; index < AC_QUANTITY; index++)
  13494. {
  13495. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13496. {
  13497. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13498. }
  13499. } // END for AC_QUANTITY
  13500. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13501. }
  13502. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13503. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13505. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13508. //2.4====================================== Voltage L1 ====================================================
  13509. //idx_sample=4;
  13510. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13511. if(gunType[gun_index] == 'J')
  13512. {
  13513. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13514. {
  13515. tempIndex = ((gun_index==2) ? 1: 0);
  13516. }
  13517. else
  13518. {
  13519. tempIndex = gun_index;
  13520. }
  13521. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13522. {
  13523. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13524. {
  13525. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13526. }
  13527. } // END OF FOR CHAdeMO_QUANTITY
  13528. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13529. }
  13530. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13531. {
  13532. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13533. {
  13534. tempIndex = ((gun_index==2) ? 1: 0);
  13535. }
  13536. else
  13537. {
  13538. tempIndex = gun_index;
  13539. }
  13540. for (int index = 0; index < CCS_QUANTITY; index++)
  13541. {
  13542. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13543. {
  13544. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13545. }
  13546. } // END OF FOR CCS_QUANTITY
  13547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13548. }
  13549. else if(gunType[gun_index] == 'G')
  13550. {
  13551. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13552. {
  13553. tempIndex = ((gun_index==2) ? 1: 0);
  13554. }
  13555. else
  13556. {
  13557. tempIndex = gun_index;
  13558. }
  13559. for (int index = 0; index < GB_QUANTITY; index++)
  13560. {
  13561. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13562. {
  13563. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13564. }
  13565. } // END OF FOR GB_QUANTITY
  13566. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13567. }
  13568. else
  13569. {
  13570. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13571. {
  13572. tempIndex = 2;
  13573. }
  13574. else
  13575. {
  13576. tempIndex = gun_index;
  13577. }
  13578. for (int index = 0; index < AC_QUANTITY; index++)
  13579. {
  13580. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13581. {
  13582. 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
  13583. }
  13584. } // END OF FOR AC_QUANTITY
  13585. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13586. }
  13587. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13588. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13589. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13590. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13592. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13593. //2.5============================================== SoC =========================================================
  13594. //idx_sample=5;
  13595. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13596. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13597. {
  13598. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13599. {
  13600. tempIndex = ((gun_index==2) ? 1: 0);
  13601. }
  13602. else
  13603. {
  13604. tempIndex = gun_index;
  13605. }
  13606. if(gunType[gun_index] == 'J')
  13607. {
  13608. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13609. {
  13610. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13611. {
  13612. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13613. }
  13614. }
  13615. }
  13616. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13617. {
  13618. for (int index = 0; index < CCS_QUANTITY; index++)
  13619. {
  13620. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13621. {
  13622. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13623. }
  13624. }
  13625. }
  13626. else if(gunType[gun_index] == 'G')
  13627. {
  13628. for (int index = 0; index < GB_QUANTITY; index++)
  13629. {
  13630. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13631. {
  13632. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13633. }
  13634. }
  13635. }
  13636. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13637. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13638. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13639. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13640. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  13641. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13642. } // END FOR DC CASE
  13643. //2.6====================================== Current.Import L2 ==============================================
  13644. // idx_sample=6;
  13645. // AC 3 phase L2 current
  13646. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13647. {
  13648. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13649. {
  13650. tempIndex = 2;
  13651. }
  13652. else
  13653. {
  13654. tempIndex = gun_index;
  13655. }
  13656. for (int index = 0; index < AC_QUANTITY; index++)
  13657. {
  13658. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13659. {
  13660. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  13661. }
  13662. }// End of for AC_QUANTITY
  13663. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  13664. }
  13665. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13666. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  13667. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  13668. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  13669. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13670. //2.7====================================== Current.Import L3 ==============================================
  13671. // idx_sample=7;
  13672. // AC 3 phase L3 current
  13673. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13674. {
  13675. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13676. {
  13677. tempIndex = 2;
  13678. }
  13679. else
  13680. {
  13681. tempIndex = gun_index;
  13682. }
  13683. for (int index = 0; index < AC_QUANTITY; index++)
  13684. {
  13685. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13686. {
  13687. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  13688. }
  13689. }// End of for AC_QUANTITY
  13690. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  13691. }
  13692. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13693. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  13694. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  13695. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  13696. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13697. //2.9====================================== Voltage L2 ====================================================
  13698. //idx_sample=8;
  13699. // AC 3 phase L2 volatge
  13700. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13701. {
  13702. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13703. {
  13704. tempIndex = 2;
  13705. }
  13706. else
  13707. {
  13708. tempIndex = gun_index;
  13709. }
  13710. for (int index = 0; index < AC_QUANTITY; index++)
  13711. {
  13712. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13713. {
  13714. 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
  13715. }
  13716. } // END OF FOR AC_QUANTITY
  13717. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  13718. }
  13719. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13720. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  13721. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  13722. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  13723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13724. //2.10====================================== Voltage L3 ====================================================
  13725. //idx_sample=9;
  13726. // AC 3 phase L3 volatge
  13727. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13728. {
  13729. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13730. {
  13731. tempIndex = 2;
  13732. }
  13733. else
  13734. {
  13735. tempIndex = gun_index;
  13736. }
  13737. for (int index = 0; index < AC_QUANTITY; index++)
  13738. {
  13739. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13740. {
  13741. 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
  13742. }
  13743. } // END OF FOR AC_QUANTITY
  13744. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  13745. }
  13746. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13747. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  13748. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  13749. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  13750. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13751. //======================================== Message create ==============================================
  13752. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13753. {
  13754. 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\"}]}]}]"
  13755. ,gun_index+1
  13756. ,MESSAGE_TYPE_CALL
  13757. ,guid
  13758. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13759. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13760. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13761. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13762. ,"PowerLoss"
  13763. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13764. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13765. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13766. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13767. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13768. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13769. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13770. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13771. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13772. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13773. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13774. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13775. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13776. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13777. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13778. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13779. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13780. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13781. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13782. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13783. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13784. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13785. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13786. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13787. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13788. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13789. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13790. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13791. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13792. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13793. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13794. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13795. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13796. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13797. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13798. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13799. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  13800. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  13801. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  13802. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  13803. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  13804. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  13805. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  13806. );
  13807. }
  13808. else
  13809. {
  13810. if(((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W')))
  13811. {
  13812. 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\"}]}]}]"
  13813. ,gun_index+1
  13814. ,MESSAGE_TYPE_CALL
  13815. ,guid
  13816. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13817. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13818. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13819. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13820. ,"PowerLoss"
  13821. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13822. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13823. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13824. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13825. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13826. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13827. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13828. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13829. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13830. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13831. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13832. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13833. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13834. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13835. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13836. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13837. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13838. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13839. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13840. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13841. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13842. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13843. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13844. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13845. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13846. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13847. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13848. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13849. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13850. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13851. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13852. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13853. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13854. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13855. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13856. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13857. );
  13858. }
  13859. else
  13860. {
  13861. 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\"}]}]}]"
  13862. ,gun_index+1
  13863. ,MESSAGE_TYPE_CALL
  13864. ,guid
  13865. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13866. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13867. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13868. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13869. ,"PowerLoss"
  13870. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13871. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13890. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13894. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13895. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13896. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13897. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13898. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13899. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13900. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13901. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13902. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13903. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13904. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13905. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13906. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  13907. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  13908. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  13909. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  13910. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  13911. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  13912. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  13913. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  13914. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  13915. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  13916. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  13917. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  13918. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  13919. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  13920. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  13921. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  13922. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  13923. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  13924. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  13925. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  13926. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  13927. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  13928. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  13929. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  13930. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  13931. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  13932. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  13933. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  13934. );
  13935. }
  13936. }
  13937. // Check File "TempStopTransaction" Exist
  13938. if((access(TempStopTransaction,F_OK))!=-1)
  13939. {
  13940. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  13941. fclose(fopen(TempStopTransaction, "w"));
  13942. }
  13943. else
  13944. {
  13945. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  13946. FILE *log = fopen(TempStopTransaction, "w+");
  13947. if(log == NULL)
  13948. {
  13949. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  13950. return ;
  13951. }
  13952. else
  13953. {
  13954. fclose(log);
  13955. }
  13956. }
  13957. //Add TempStopTransaction | Update TempStopTransaction
  13958. // open file for writing
  13959. FILE *outfile;
  13960. outfile = fopen (TempStopTransaction, "a");
  13961. //DEBUG_INFO("data = %s\n", queuedata);
  13962. fputs(queuedata, outfile);
  13963. fputs("\n", outfile);
  13964. fclose (outfile);
  13965. }
  13966. void checkTempStopTransaction(int gun_index)
  13967. {
  13968. FILE *fptr1;
  13969. char ch;
  13970. char str[QUEUE_MESSAGE_LENGTH]={0};
  13971. char guid[37]={0};
  13972. char tempdata[65]={0};
  13973. char connectorStr[2]={0};
  13974. char TempStopTransaction[256];
  13975. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13976. fptr1 = fopen(TempStopTransaction, "r");
  13977. //TempStopTransaction格式: 槍號,StopTransaction封包
  13978. if (!fptr1)
  13979. {
  13980. //printf(" File not found or unable to open the input file!!\n");
  13981. return ;
  13982. }
  13983. ch=fgetc(fptr1);
  13984. //printf(" Now the content of the file %s is : \n",fname);
  13985. rewind(fptr1);
  13986. if(ch!=EOF)
  13987. {
  13988. // copy all contents to the temporary file except the specific line
  13989. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  13990. {
  13991. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13992. if(str[0]=='\0')
  13993. {
  13994. break;
  13995. }
  13996. //TempStopTransaction格式: 槍號,StopTransaction封包
  13997. strncpy(connectorStr, str, 1);
  13998. if(atoi(connectorStr) != (gun_index+1))
  13999. {
  14000. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  14001. fclose(fptr1);
  14002. return ;
  14003. }
  14004. //random_uuid(guid);
  14005. strncpy(guid, str+6, 36); //copy guid
  14006. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14007. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14008. {
  14009. DEBUG_INFO("StopTransaction mapitem pass\n");
  14010. }
  14011. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14012. memset(str,0,ARRAY_SIZE(str));
  14013. }
  14014. }
  14015. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14016. fclose(fptr1);
  14017. remove(TempStopTransaction); // remove the original file
  14018. }
  14019. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14020. {
  14021. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14022. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14023. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14024. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14025. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14026. }
  14027. int GetWebSocketPingInterval(void)
  14028. {
  14029. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14030. }
  14031. int GetServerSign(void)
  14032. {
  14033. return server_sign;
  14034. }
  14035. void SetServerSign(int value)
  14036. {
  14037. server_sign = value;
  14038. }
  14039. int GetBootNotificationInterval(void)
  14040. {
  14041. return BootNotificationInterval;
  14042. }
  14043. int GetInternetConn(void)
  14044. {
  14045. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14046. }
  14047. void InitialSystemValue(void)
  14048. {
  14049. int connectorIndex = 0;
  14050. //int valueASCII = 0;
  14051. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14052. gunTotalNumber=0;
  14053. SystemInitial = 0;
  14054. localversion=0;
  14055. BootNotificationInterval = 0;
  14056. authorizeRetryTimes = 0;
  14057. GunStatusInterval = 10;
  14058. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14059. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14060. //Hear Beat
  14061. HeartBeatWithNOResponse = 0;
  14062. HeartBeatCountPerHour = 0;
  14063. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14064. FirstHeartBeat = 0;
  14065. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14066. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14067. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14068. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14069. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14070. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14071. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14072. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14073. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14074. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14075. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14076. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14077. memset(gunType, 0, ARRAY_SIZE(gunType));
  14078. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14079. {
  14080. //check connector / socket type (index: 8, 9, 10)
  14081. for(int index=7; index <10 ; index++)
  14082. {
  14083. if(index != 8)
  14084. {
  14085. // DC Connector
  14086. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  14087. {
  14088. SystemInitial = SystemInitial + 1;
  14089. gunTotalNumber = gunTotalNumber + 1;
  14090. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14091. connectorIndex = connectorIndex + 1;
  14092. }
  14093. }
  14094. else
  14095. {
  14096. // AC Connector
  14097. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14098. {
  14099. SystemInitial = SystemInitial + 1;
  14100. gunTotalNumber = gunTotalNumber + 1;
  14101. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14102. connectorIndex = connectorIndex + 1;
  14103. }
  14104. }
  14105. }
  14106. //DEBUG_INFO("DC ...\n");
  14107. }
  14108. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14109. {
  14110. //check connector / socket type (index: 8, 9, 10)
  14111. for(int index=7; index <10 ; index++)
  14112. {
  14113. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14114. {
  14115. SystemInitial = SystemInitial + 1;
  14116. gunTotalNumber = gunTotalNumber + 1;
  14117. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14118. connectorIndex = connectorIndex + 1;
  14119. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14120. }
  14121. }
  14122. }
  14123. //Status && ConnectorPlugIn Setting
  14124. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14125. {
  14126. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14127. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14128. }
  14129. for (int index = 0; index < CCS_QUANTITY; index++)
  14130. {
  14131. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14132. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14133. }
  14134. for (int index = 0; index < GB_QUANTITY; index++)
  14135. {
  14136. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14137. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14138. }
  14139. for (int index = 0; index < AC_QUANTITY; index++)
  14140. {
  14141. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14142. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14143. }
  14144. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14145. {
  14146. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14147. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14148. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14149. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14150. }
  14151. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14152. clientTime.Heartbeat=time((time_t*)NULL);
  14153. sleep(1);
  14154. }
  14155. void LWS_Send(char * str)
  14156. {
  14157. //=====================================================
  14158. // Check InternetConn 0: disconnected, 1: connected
  14159. //====================================================
  14160. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14161. {
  14162. DEBUG_INFO("offline now !!!\n");
  14163. return;
  14164. }
  14165. pthread_mutex_lock(&lock_send);
  14166. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14167. sprintf((char *)SendBuffer, "%s", str);
  14168. SendBufLen = strlen(str);
  14169. pthread_mutex_unlock(&lock_send);
  14170. lws_callback_on_writable(wsi_client);
  14171. //lws_service(context, 0);
  14172. //sleep(1);
  14173. }