MessageHandler.c 671 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. #define TxDefaultProfile_1_JSON "/Storage/OCPP/TxDefaultProfile_1.json"
  8. #define TxDefaultProfile_2_JSON "/Storage/OCPP/TxDefaultProfile_2.json"
  9. //TxProfile
  10. #define TxProfile_1_JSON "/Storage/OCPP/TxProfile_1.json"
  11. #define TxProfile_2_JSON "/Storage/OCPP/TxProfile_2.json"
  12. #define ChargingProfile_0_JSON "/Storage/OCPP/chargingprofile_0.json"
  13. #define ChargingProfile_1_JSON "/Storage/OCPP/chargingprofile_1.json"
  14. #define ChargingProfile_2_JSON "/Storage/OCPP/chargingprofile_2.json"
  15. #define AuthorizationCache_JSON "/Storage/OCPP/AuthorizationCache.json"
  16. #define LocalAuthorizationList_JSON "/Storage/OCPP/LocalAuthorizationList.json"
  17. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  18. struct StatusCodeData *ShmStatusCodeData;
  19. struct PsuData *ShmPsuData ;
  20. struct OCPP16Data *ShmOCPP16Data;
  21. //ConfigurationMaxKeys
  22. #define GetConfigurationMaxKeysNUM 44
  23. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  24. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  25. //=================================
  26. // StatusNotification cycle
  27. //=================================
  28. static int server_cycle_Status = 120;
  29. //===============================
  30. // Configuration: unknownkey
  31. //===============================
  32. static char unknownkey[10][20] = {0};
  33. static int UnknownKeynum = 0;
  34. //===============================
  35. // Gun Total Numbers
  36. //===============================
  37. static int gunTotalNumber = 0;
  38. static uint8_t gunType[4] = {0};
  39. //===============================
  40. // Local List Version
  41. //===============================
  42. static int localversion=0;
  43. static char idTagAuthorization[32] = {0};
  44. //===============================
  45. // OCPP sign variable
  46. //===============================
  47. static int server_sign = FALSE;
  48. int server_pending = FALSE;
  49. static int BootNotificationInterval = 0;
  50. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  51. //===============================
  52. // OCPP auth variable
  53. //===============================
  54. static int authorizeRetryTimes = 0; //number of Retry times
  55. //===============================
  56. // OCPP other variables
  57. //===============================
  58. static int HeartBeatWaitTime = 10;
  59. static int FirstHeartBeat = 0;
  60. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  61. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  62. static char CurrentChargingProfileScheduleStr[30] = {0};
  63. //========================================
  64. // OCPP status/previous related variables
  65. //========================================
  66. static int GunStatusInterval = 10;
  67. static uint8_t statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  68. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  69. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  70. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  71. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  72. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  73. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  74. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  75. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  76. static int TransactionMessageAttemptsValue = 0;
  77. static int TransactionMessageRetryIntervalValue = 0;
  78. static int TempMeterValueInterval = 0;
  79. static struct OCPPAuthLocalElemet
  80. {
  81. int listVersionInt;
  82. char idTagstr[20];
  83. char parentIdTag[20];
  84. char expiryDate[30];
  85. char idTagstatus[16];
  86. }idTagQuery;
  87. //=============================================
  88. // OCPP HeartBeat Response Not Receive Counts
  89. //============================================
  90. static int HeartBeatWithNOResponse = 0;
  91. static int HeartBeatCountPerHour = 0;
  92. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  93. extern int GetTransactionQueueNum(void);
  94. extern struct Charger_Info Charger;
  95. extern sqlite3 *db;
  96. int TransactionMessageAttemptsGet(void);
  97. int TransactionMessageRetryIntervalGet(void);
  98. int GetOcppConnStatus(void);
  99. void SetOcppConnStatus(uint8_t status);
  100. int setKeyValue(char *key, char *value);
  101. void OCPP_get_TableAuthlocalAllData(void);
  102. void processUnkownKey(void);
  103. struct StructOCPPMeterValue
  104. {
  105. unsigned char TimeStamp[28];
  106. struct StructSampledValue SampledValue[10];
  107. };
  108. struct ClientTime
  109. {
  110. unsigned int Heartbeat;
  111. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  112. unsigned int StartTransaction;
  113. unsigned int StopTransaction;
  114. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  115. }clientTime;
  116. typedef union
  117. {
  118. //Operations Initiated by Central System
  119. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  120. struct
  121. {
  122. //CsMsgValue[0]
  123. unsigned char StatusNotificationReq :1; //bit 0,
  124. unsigned char StatusNotificationConf :1; //bit 0,
  125. unsigned char :6; //bit 2~7
  126. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  127. }CpinitiateMsg;
  128. CpinitiateMsg cpinitateMsg;
  129. //GetConfiguration Array
  130. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  131. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  132. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  133. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  134. #if 0
  135. static char *ChargePointErrorCodeStr[] = {
  136. MACROSTR(ConnectorLockFailure),
  137. MACROSTR(EVCommunicationError),
  138. MACROSTR(GroundFailure),
  139. MACROSTR(HighTemperature),
  140. MACROSTR(InternalError),
  141. MACROSTR(LocalListConflict),
  142. MACROSTR(NoError),
  143. MACROSTR(OtherError),
  144. MACROSTR(OverCurrentFailure),
  145. MACROSTR(OverVoltage),
  146. MACROSTR(PowerMeterFailure),
  147. MACROSTR(PowerSwitchFailure),
  148. MACROSTR(ReaderFailure),
  149. MACROSTR(ResetFailure),
  150. MACROSTR(UnderVoltage),
  151. MACROSTR(WeakSignal)
  152. };
  153. #endif
  154. static char * ChargePointStatusStr[] = {
  155. MACROSTR(Available),
  156. MACROSTR(Preparing),
  157. MACROSTR(Charging),
  158. MACROSTR(SuspendedEVSE),
  159. MACROSTR(SuspendedEV),
  160. MACROSTR(Finishing),
  161. MACROSTR(Reserved),
  162. MACROSTR(Unavailable),
  163. MACROSTR(Faulted)
  164. };
  165. static char *RegistrationStatusStr[] = {
  166. MACROSTR(Accepted),
  167. MACROSTR(Pending),
  168. MACROSTR(Rejected)
  169. };
  170. static char *AvailabilityTypeStr[] = {
  171. MACROSTR(Inoperative),
  172. MACROSTR(Operative)
  173. };
  174. static char *AvailabilityStatusStr[] = {
  175. MACROSTR(Accepted),
  176. MACROSTR(Rejected),
  177. MACROSTR(Scheduled)
  178. };
  179. static char *ConfigurationStatusStr[] = {
  180. MACROSTR(Accepted),
  181. MACROSTR(Rejected),
  182. MACROSTR(RebootRequired),
  183. MACROSTR(NotSupported)
  184. };
  185. static char *ClearCacheStatusStr[] = {
  186. MACROSTR(Accepted),
  187. MACROSTR(Rejected)
  188. };
  189. static char *ChargingProfilePurposeTypeStr[] = {
  190. MACROSTR(ChargePointMaxProfile),
  191. MACROSTR(TxDefaultProfile),
  192. MACROSTR(TxProfile)
  193. };
  194. static char *ChargingProfileStatusStr[] = {
  195. MACROSTR(Accepted),
  196. MACROSTR(Rejected),
  197. MACROSTR(NotSupported)
  198. };
  199. static char *ClearChargingProfileStatusStr[] = {
  200. MACROSTR(Accepted),
  201. MACROSTR(Unknown)
  202. };
  203. static char *GetCompositeScheduleStatusStr[] = {
  204. MACROSTR(Accepted),
  205. MACROSTR(Rejected)
  206. };
  207. static char *UpdateTypeStr[] = {
  208. MACROSTR(Differential),
  209. MACROSTR(Full)
  210. };
  211. static char *UpdateStatusStr[] = {
  212. MACROSTR(Accepted),
  213. MACROSTR(Failed),
  214. MACROSTR(NotSupported),
  215. MACROSTR(VersionMismatch)
  216. };
  217. static char *RemoteStartStopStatusStr[] = {
  218. MACROSTR(Accepted),
  219. MACROSTR(Rejected)
  220. };
  221. static char *ReservationStatusStr[] = {
  222. MACROSTR(Accepted),
  223. MACROSTR(Faulted),
  224. MACROSTR(Occupied),
  225. MACROSTR(Rejected),
  226. MACROSTR(Unavailable)
  227. };
  228. static char *ResetTypeStr[] = {
  229. MACROSTR(Hard),
  230. MACROSTR(Soft)
  231. };
  232. static char *ResetStatusStr[] = {
  233. MACROSTR(Accepted),
  234. MACROSTR(Rejected)
  235. };
  236. static char * DiagnosticsStatusStr[] = {
  237. MACROSTR(Idle),
  238. MACROSTR(Uploaded),
  239. MACROSTR(UploadFailed),
  240. MACROSTR(Uploading)
  241. };
  242. static char * FirmwareStatusStr[] = {
  243. MACROSTR(Downloaded),
  244. MACROSTR(DownloadFailed),
  245. MACROSTR(Downloading),
  246. MACROSTR(Idle),
  247. MACROSTR(InstallationFailed),
  248. MACROSTR(Installing),
  249. MACROSTR(Installed)
  250. };
  251. static char * MessageTriggerStr[] = {
  252. MACROSTR(BootNotification),
  253. MACROSTR(DiagnosticsStatusNotification),
  254. MACROSTR(FirmwareStatusNotification),
  255. MACROSTR(Heartbeat),
  256. MACROSTR(MeterValues),
  257. MACROSTR(StatusNotification)
  258. };
  259. static char * TriggerMessageStatusStr[] = {
  260. MACROSTR(Accepted),
  261. MACROSTR(Rejected),
  262. MACROSTR(NotImplemented)
  263. };
  264. static char * UnlockStatusStr[] = {
  265. MACROSTR(Unlocked),
  266. MACROSTR(UnlockFailed),
  267. MACROSTR(NotSupported)
  268. };
  269. #if 0
  270. static char * StopTransactionReasonStr[] = {
  271. MACROSTR(EmergencyStop),
  272. MACROSTR(EVDisconnected),
  273. MACROSTR(HardReset),
  274. MACROSTR(Local),
  275. MACROSTR(Other),
  276. MACROSTR(PowerLoss),
  277. MACROSTR(Reboot),
  278. MACROSTR(Remote),
  279. MACROSTR(SoftReset),
  280. MACROSTR(UnlockCommand),
  281. MACROSTR(DeAuthorized)
  282. };
  283. #endif
  284. static char * CancelReservationStatusStr[] = {
  285. MACROSTR(Accepted),
  286. MACROSTR(Rejected)
  287. };
  288. static char * ReadingContextStr[] = {
  289. MACROSTR(Interruption.Begin),
  290. MACROSTR(Interruption.End),
  291. MACROSTR(Other),
  292. MACROSTR(Sample.Clock),
  293. MACROSTR(Sample.Periodic),
  294. MACROSTR(Transaction.Begin),
  295. MACROSTR(Transaction.End),
  296. MACROSTR(Trigger)
  297. };
  298. static char * ValueFormatStr[] = {
  299. MACROSTR(Raw),
  300. MACROSTR(SignedData)
  301. };
  302. static char * MeasurandStr[] = {
  303. MACROSTR(Current.Export),
  304. MACROSTR(Current.Import),
  305. MACROSTR(Current.Offered),
  306. MACROSTR(Energy.Active.Export.Register),
  307. MACROSTR(Energy.Active.Import.Register),
  308. MACROSTR(Energy.Reactive.Export.Register),
  309. MACROSTR(Energy.Reactive.Import.Register),
  310. MACROSTR(Energy.Active.Export.Interval),
  311. MACROSTR(Energy.Active.Import.Interval),
  312. MACROSTR(Energy.Reactive.Export.Interval),
  313. MACROSTR(Energy.Reactive.Import.Interval),
  314. MACROSTR(Frequency),
  315. MACROSTR(Power.Active.Export),
  316. MACROSTR(Power.Active.Import),
  317. MACROSTR(Power.Factor),
  318. MACROSTR(Power.Offered),
  319. MACROSTR(Power.Reactive.ExportMACROSTR),
  320. MACROSTR(Power.Reactive.Import),
  321. MACROSTR(RPM),
  322. MACROSTR(SoC),
  323. MACROSTR(Temperature),
  324. MACROSTR(Voltage)
  325. };
  326. static char * LocationStr[] = {
  327. MACROSTR(Body),
  328. MACROSTR(Cable),
  329. MACROSTR(EV),
  330. MACROSTR(Inlet),
  331. MACROSTR(Outlet)
  332. };
  333. static char * PhaseStr[] = {
  334. MACROSTR(L1),
  335. MACROSTR(L2),
  336. MACROSTR(L3),
  337. MACROSTR(N),
  338. MACROSTR(L1-N),
  339. MACROSTR(L2-N),
  340. MACROSTR(L3-N),
  341. MACROSTR(L1-L2),
  342. MACROSTR(L2-L3),
  343. MACROSTR(L3-L1)
  344. };
  345. static char * UnitOfMeasureStr[] = {
  346. MACROSTR(Wh),
  347. MACROSTR(kWh),
  348. MACROSTR(varh),
  349. MACROSTR(kvarh),
  350. MACROSTR(W),
  351. MACROSTR(kW),
  352. MACROSTR(VA),
  353. MACROSTR(kVA),
  354. MACROSTR(var),
  355. MACROSTR(kvar),
  356. MACROSTR(A),
  357. MACROSTR(V),
  358. MACROSTR(Celsius),
  359. MACROSTR(Fahrenheit),
  360. MACROSTR(K),
  361. MACROSTR(Percent)
  362. };
  363. //==========================================
  364. // Check time passed since today
  365. //==========================================
  366. long long DiffTimebWithNow(struct timeb ST)
  367. {
  368. //return milli-second
  369. struct timeb ET;
  370. long long StartTime,StopTime;
  371. ftime(&ET);
  372. StartTime=(long long)ST.time;
  373. StopTime=(long long)ET.time;
  374. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  375. }
  376. int getTimePassSinceToday()
  377. {
  378. int result = -1;
  379. time_t t;
  380. struct tm *tmStartToday;
  381. struct timeb tbStartToday;
  382. t=time(NULL);
  383. tmStartToday=localtime(&t);
  384. tmStartToday->tm_hour = 0;
  385. tmStartToday->tm_min = 0;
  386. tmStartToday->tm_sec = 0;
  387. tbStartToday.time = mktime(tmStartToday);
  388. tbStartToday.millitm = 0;
  389. result = DiffTimebWithNow(tbStartToday)/1000;
  390. return result;
  391. }
  392. //==========================================
  393. // GetCompositeSchedule logic related function
  394. //==========================================
  395. int DiffTimebSec(struct timeb ST, struct timeb ET)
  396. {
  397. //return milli-second
  398. unsigned int StartTime,StopTime;
  399. StartTime=(unsigned int)ST.time;
  400. StopTime=(unsigned int)ET.time;
  401. return (StopTime-StartTime);
  402. }
  403. int DiffTimebWithNowSec(struct timeb ST)
  404. {
  405. //return milli-second
  406. struct timeb ET;
  407. unsigned int StartTime,StopTime;
  408. ftime(&ET);
  409. StartTime=(unsigned int)ST.time;
  410. StopTime=(unsigned int)ET.time;
  411. return (StopTime-StartTime);
  412. }
  413. int getStartStop(uint8_t *start, uint8_t *stop)
  414. {
  415. int result = -1;
  416. struct tm tmStart;
  417. struct timeb tbStart;
  418. struct tm tmStop;
  419. struct timeb tbStop;
  420. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  421. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  422. {
  423. tmStart.tm_year -= 1900;
  424. tmStart.tm_mon -= 1;
  425. tbStart.time = mktime(&tmStart);
  426. tbStart.millitm = 0;
  427. tmStop.tm_year -= 1900;
  428. tmStop.tm_mon -= 1;
  429. tbStop.time = mktime(&tmStop);
  430. tbStop.millitm = 0;
  431. result = DiffTimebSec(tbStart, tbStop);
  432. }
  433. else
  434. {
  435. DEBUG_WARN("Start or stop date parsing error.\r\n");
  436. }
  437. return result;
  438. }
  439. int getStartSinceToday(uint8_t *stop)
  440. {
  441. int result = -1;
  442. time_t t;
  443. struct tm *tmStartToday;
  444. struct timeb tbStartToday;
  445. struct tm tmStop;
  446. struct timeb tbStop;
  447. if((sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  448. {
  449. t=time(NULL);
  450. tmStartToday=localtime(&t);
  451. tmStartToday->tm_hour = 0;
  452. tmStartToday->tm_min = 0;
  453. tmStartToday->tm_sec = 0;
  454. tbStartToday.time = mktime(tmStartToday);
  455. tmStop.tm_year -= 1900;
  456. tmStop.tm_mon -= 1;
  457. tbStop.time = mktime(&tmStop);
  458. tbStop.millitm = 0;
  459. result = DiffTimebSec(tbStartToday, tbStop);
  460. }
  461. return result;
  462. }
  463. int getStartSinceWeek(uint8_t *stop)
  464. {
  465. int result = -1;
  466. time_t t;
  467. struct tm *tmStartWeek;
  468. struct timeb tbStartWeek;
  469. struct tm tmStop;
  470. struct timeb tbStop;
  471. if((sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  472. {
  473. t=time(NULL);
  474. tmStartWeek=localtime(&t);
  475. t-=86400*tmStartWeek->tm_wday;
  476. tmStartWeek=localtime(&t);
  477. tmStartWeek->tm_hour = 0;
  478. tmStartWeek->tm_min = 0;
  479. tmStartWeek->tm_sec = 0;
  480. tbStartWeek.time = mktime(tmStartWeek);
  481. tmStop.tm_year -= 1900;
  482. tmStop.tm_mon -= 1;
  483. tbStop.time = mktime(&tmStop);
  484. tbStop.millitm = 0;
  485. result = DiffTimebSec(tbStartWeek, tbStop);
  486. }
  487. return result;
  488. }
  489. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  490. {
  491. FILE *fp;
  492. char profileFileName[128];
  493. char *line = NULL;
  494. size_t len = 0;
  495. time_t CurrentTime;
  496. struct tm *tmComposite;
  497. struct StructChargingProfile maxProfile;
  498. struct StructChargingProfile defaultTxProfile;
  499. struct StructChargingProfile txProfile;
  500. struct StructChargingSchedulePeriod tmpPeriod;
  501. uint8_t limitMax=0;
  502. uint8_t limitDef=0;
  503. uint8_t limitTx=0;
  504. int compositePeriodIdx = 0;
  505. CurrentTime = time(NULL);
  506. tmComposite=localtime(&CurrentTime);
  507. sprintf((char*)compositeProfile->ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  508. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  509. compositeProfile->ChargingSchedule.Duration = durationReq;
  510. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  511. {
  512. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  513. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  514. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  515. }
  516. compositeProfile->ChargingProfileId = 0;
  517. compositeProfile->StackLevel = 99 ;
  518. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  519. maxProfile.ChargingProfileId = -1;
  520. defaultTxProfile.ChargingProfileId = -1;
  521. txProfile.ChargingProfileId = -1;
  522. system("yes|rm /tmp/*.json");
  523. system("cp /Storage/OCPP/*.json /tmp");
  524. /*
  525. * Search valid charging profile
  526. */
  527. //DEBUG_INFO("====================================\n");
  528. // Search max profile
  529. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  530. if((access(profileFileName, F_OK))!=-1)
  531. {
  532. fp = fopen(profileFileName, "r");
  533. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  534. {
  535. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  536. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  537. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  538. }
  539. maxProfile.ChargingProfileId = -1;
  540. maxProfile.StackLevel = -1;
  541. while(getline(&line, &len, fp) != -1)
  542. {
  543. json_object *obj = NULL;
  544. obj = json_tokener_parse(line);
  545. if(is_error(obj))
  546. {
  547. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  548. }
  549. else
  550. {
  551. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  552. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  553. )
  554. {
  555. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  556. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  557. )
  558. {
  559. struct tm tmFrom, tmTo;
  560. struct timeb tbFrom, tbTo;
  561. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  562. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  563. {
  564. tmFrom.tm_year -= 1900;
  565. tmFrom.tm_mon -= 1;
  566. tbFrom.time = mktime(&tmFrom);
  567. tmTo.tm_year -= 1900;
  568. tmTo.tm_mon -= 1;
  569. tbTo.time = mktime(&tmTo);
  570. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  571. {
  572. if(maxProfile.ChargingProfileId == -1)
  573. DEBUG_INFO("MaxProfile found.\n");
  574. else
  575. DEBUG_INFO("MaxProfile updated.\n");
  576. // Required item
  577. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  578. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  579. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  580. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  581. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  582. {
  583. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  584. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  585. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  586. 3:
  587. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  588. }
  589. // Optional item
  590. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  591. {
  592. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  593. }
  594. else
  595. {
  596. sprintf((char*)maxProfile.ValidFrom, " ");
  597. }
  598. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  599. {
  600. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  601. }
  602. else
  603. {
  604. sprintf((char*)maxProfile.ValidTo, " ");
  605. }
  606. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  607. {
  608. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  609. }
  610. else
  611. {
  612. sprintf((char*)maxProfile.RecurrencyKind, " ");
  613. }
  614. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  615. {
  616. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  617. }
  618. else
  619. {
  620. maxProfile.TransactionId = -1;
  621. }
  622. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  623. {
  624. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  625. }
  626. else
  627. {
  628. maxProfile.ChargingSchedule.Duration = -1;
  629. }
  630. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  631. {
  632. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  633. }
  634. else
  635. {
  636. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, " ");
  637. }
  638. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  639. {
  640. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  641. }
  642. else
  643. {
  644. maxProfile.ChargingSchedule.MinChargingRate = -1;
  645. }
  646. }
  647. }
  648. }
  649. else
  650. {
  651. if(maxProfile.ChargingProfileId == -1)
  652. DEBUG_INFO("MaxProfile found.\n");
  653. else
  654. DEBUG_INFO("MaxProfile updated.\n");
  655. // Required item
  656. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  657. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  658. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  659. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  660. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  661. {
  662. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  663. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  664. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  665. 3:
  666. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  667. }
  668. // Optional item
  669. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  670. {
  671. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  672. }
  673. else
  674. {
  675. sprintf((char*)maxProfile.ValidFrom, " ");
  676. }
  677. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  678. {
  679. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  680. }
  681. else
  682. {
  683. sprintf((char*)maxProfile.ValidTo, " ");
  684. }
  685. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  686. {
  687. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  688. }
  689. else
  690. {
  691. sprintf((char*)maxProfile.RecurrencyKind, " ");
  692. }
  693. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  694. {
  695. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  696. }
  697. else
  698. {
  699. maxProfile.TransactionId = -1;
  700. }
  701. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  702. {
  703. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  704. }
  705. else
  706. {
  707. maxProfile.ChargingSchedule.Duration = -1;
  708. }
  709. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  710. {
  711. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  712. }
  713. else
  714. {
  715. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, " ");
  716. }
  717. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  718. {
  719. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  720. }
  721. else
  722. {
  723. maxProfile.ChargingSchedule.MinChargingRate = -1;
  724. }
  725. }
  726. }
  727. }
  728. json_object_put(obj);
  729. }
  730. fclose(fp);
  731. /*
  732. if(maxProfile.ChargingProfileId !=-1)
  733. {
  734. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  735. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  736. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  737. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  738. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  739. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  740. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  741. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  742. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  743. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  744. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  745. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  746. {
  747. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  748. {
  749. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  750. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  751. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  752. }
  753. }
  754. }
  755. else
  756. DEBUG_INFO("MaxProfile not found.\n");
  757. DEBUG_INFO("------------------------------------\n");*/
  758. }
  759. // Search default tx profile
  760. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  761. if((access(profileFileName, F_OK))==-1)
  762. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  763. if((access(profileFileName, F_OK))!=-1)
  764. {
  765. fp = fopen(profileFileName, "r");
  766. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  767. {
  768. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  769. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  770. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  771. }
  772. defaultTxProfile.ChargingProfileId = -1;
  773. defaultTxProfile.StackLevel = -1;
  774. while(getline(&line, &len, fp) != -1)
  775. {
  776. json_object *obj = NULL;
  777. obj = json_tokener_parse(line);
  778. if(is_error(obj))
  779. {
  780. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  781. }
  782. else
  783. {
  784. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  785. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  786. )
  787. {
  788. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  789. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  790. )
  791. {
  792. struct tm tmFrom, tmTo;
  793. struct timeb tbFrom, tbTo;
  794. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  795. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  796. {
  797. tmFrom.tm_year -= 1900;
  798. tmFrom.tm_mon -= 1;
  799. tbFrom.time = mktime(&tmFrom);
  800. tmTo.tm_year -= 1900;
  801. tmTo.tm_mon -= 1;
  802. tbTo.time = mktime(&tmTo);
  803. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  804. {
  805. if(defaultTxProfile.ChargingProfileId == -1)
  806. DEBUG_INFO("TxDefaultProfile found.\n");
  807. else
  808. DEBUG_INFO("TxDefaultProfile updated.\n");
  809. // Required item
  810. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  811. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  812. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  813. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  814. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  815. {
  816. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  817. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  818. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  819. 3:
  820. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  821. }
  822. // Optional item
  823. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  824. {
  825. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  826. }
  827. else
  828. {
  829. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  830. }
  831. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  832. {
  833. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  834. }
  835. else
  836. {
  837. sprintf((char*)defaultTxProfile.ValidTo, " ");
  838. }
  839. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  840. {
  841. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  842. }
  843. else
  844. {
  845. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  846. }
  847. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  848. {
  849. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  850. }
  851. else
  852. {
  853. defaultTxProfile.TransactionId = -1;
  854. }
  855. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  856. {
  857. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  858. }
  859. else
  860. {
  861. defaultTxProfile.ChargingSchedule.Duration = -1;
  862. }
  863. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  864. {
  865. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  866. }
  867. else
  868. {
  869. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, " ");
  870. }
  871. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  872. {
  873. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  874. }
  875. else
  876. {
  877. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  878. }
  879. }
  880. }
  881. }
  882. else
  883. {
  884. if(defaultTxProfile.ChargingProfileId == -1)
  885. DEBUG_INFO("TxDefaultProfile found.\n");
  886. else
  887. DEBUG_INFO("TxDefaultProfile updated.\n");
  888. // Required item
  889. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  890. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  891. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  892. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  893. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  894. {
  895. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  896. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  897. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  898. 3:
  899. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  900. }
  901. // Optional item
  902. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  903. {
  904. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  905. }
  906. else
  907. {
  908. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  909. }
  910. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  911. {
  912. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  913. }
  914. else
  915. {
  916. sprintf((char*)defaultTxProfile.ValidTo, " ");
  917. }
  918. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  919. {
  920. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  921. }
  922. else
  923. {
  924. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  925. }
  926. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  927. {
  928. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  929. }
  930. else
  931. {
  932. defaultTxProfile.TransactionId = -1;
  933. }
  934. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  935. {
  936. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  937. }
  938. else
  939. {
  940. defaultTxProfile.ChargingSchedule.Duration = -1;
  941. }
  942. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  943. {
  944. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  945. }
  946. else
  947. {
  948. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, " ");
  949. }
  950. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  951. {
  952. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  953. }
  954. else
  955. {
  956. maxProfile.ChargingSchedule.MinChargingRate = -1;
  957. }
  958. }
  959. }
  960. }
  961. json_object_put(obj);
  962. }
  963. fclose(fp);
  964. /*
  965. if(defaultTxProfile.ChargingProfileId != -1)
  966. {
  967. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  968. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  969. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  970. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  971. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  972. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  973. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  974. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  975. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  976. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  977. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  978. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  979. {
  980. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  981. {
  982. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  983. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  984. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  985. }
  986. }
  987. }
  988. else
  989. DEBUG_INFO("TxDefaultProfile not found.\n");
  990. DEBUG_INFO("------------------------------------\n");*/
  991. }
  992. // Search tx profile
  993. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  994. if((access(profileFileName, F_OK))!=-1)
  995. {
  996. fp = fopen(profileFileName, "r");
  997. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  998. {
  999. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1000. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1001. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1002. }
  1003. txProfile.ChargingProfileId = -1;
  1004. txProfile.StackLevel = -1;
  1005. while(getline(&line, &len, fp) != -1)
  1006. {
  1007. json_object *obj = NULL;
  1008. obj = json_tokener_parse(line);
  1009. if(is_error(obj))
  1010. {
  1011. DEBUG_ERROR("Parse txProfile from file error.\n");
  1012. }
  1013. else
  1014. {
  1015. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  1016. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1017. )
  1018. {
  1019. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1020. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1021. )
  1022. {
  1023. struct tm tmFrom, tmTo;
  1024. struct timeb tbFrom, tbTo;
  1025. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1026. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1027. {
  1028. tmFrom.tm_year -= 1900;
  1029. tmFrom.tm_mon -= 1;
  1030. tbFrom.time = mktime(&tmFrom);
  1031. tmTo.tm_year -= 1900;
  1032. tmTo.tm_mon -= 1;
  1033. tbTo.time = mktime(&tmTo);
  1034. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1035. {
  1036. if(txProfile.ChargingProfileId == -1)
  1037. DEBUG_INFO("TxProfile found.\n");
  1038. else
  1039. DEBUG_INFO("TxProfile updated.\n");
  1040. // Required item
  1041. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1042. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1043. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1044. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1045. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1046. {
  1047. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1048. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1049. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1050. 3:
  1051. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1052. }
  1053. // Optional item
  1054. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1055. {
  1056. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1057. }
  1058. else
  1059. {
  1060. sprintf((char*)txProfile.ValidFrom, " ");
  1061. }
  1062. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1063. {
  1064. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1065. }
  1066. else
  1067. {
  1068. sprintf((char*)txProfile.ValidTo, " ");
  1069. }
  1070. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1071. {
  1072. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1073. }
  1074. else
  1075. {
  1076. sprintf((char*)txProfile.RecurrencyKind, " ");
  1077. }
  1078. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1079. {
  1080. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1081. }
  1082. else
  1083. {
  1084. txProfile.TransactionId = -1;
  1085. }
  1086. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1087. {
  1088. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1089. }
  1090. else
  1091. {
  1092. txProfile.ChargingSchedule.Duration = -1;
  1093. }
  1094. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1095. {
  1096. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1097. }
  1098. else
  1099. {
  1100. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, " ");
  1101. }
  1102. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1103. {
  1104. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1105. }
  1106. else
  1107. {
  1108. txProfile.ChargingSchedule.MinChargingRate = -1;
  1109. }
  1110. }
  1111. }
  1112. }
  1113. else
  1114. {
  1115. if(txProfile.ChargingProfileId == -1)
  1116. DEBUG_INFO("TxProfile found.\n");
  1117. else
  1118. DEBUG_INFO("TxProfile updated.\n");
  1119. // Required item
  1120. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1121. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1122. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1123. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1124. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1125. {
  1126. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1127. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1128. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1129. 3:
  1130. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1131. }
  1132. // Optional item
  1133. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1134. {
  1135. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1136. }
  1137. else
  1138. {
  1139. sprintf((char*)txProfile.ValidFrom, " ");
  1140. }
  1141. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1142. {
  1143. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1144. }
  1145. else
  1146. {
  1147. sprintf((char*)txProfile.ValidTo, " ");
  1148. }
  1149. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1150. {
  1151. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1152. }
  1153. else
  1154. {
  1155. sprintf((char*)txProfile.RecurrencyKind, " ");
  1156. }
  1157. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1158. {
  1159. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1160. }
  1161. else
  1162. {
  1163. txProfile.TransactionId = -1;
  1164. }
  1165. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1166. {
  1167. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1168. }
  1169. else
  1170. {
  1171. txProfile.ChargingSchedule.Duration = -1;
  1172. }
  1173. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1174. {
  1175. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1176. }
  1177. else
  1178. {
  1179. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, " ");
  1180. }
  1181. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1182. {
  1183. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1184. }
  1185. else
  1186. {
  1187. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1188. }
  1189. }
  1190. }
  1191. }
  1192. json_object_put(obj);
  1193. }
  1194. fclose(fp);
  1195. /*
  1196. if(defaultTxProfile.ChargingProfileId != -1)
  1197. {
  1198. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1199. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1200. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1201. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1202. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1203. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1204. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1205. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1206. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1207. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1208. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1209. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1210. {
  1211. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1212. {
  1213. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1214. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1215. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1216. }
  1217. }
  1218. }
  1219. else
  1220. DEBUG_INFO("TxProfile not found.\n");*/
  1221. }
  1222. /*
  1223. * Align found profile start schedule & periods
  1224. */
  1225. //DEBUG_INFO("====================================\n");
  1226. /*
  1227. // For local test usage, force modify found profile start schedule info
  1228. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-10);
  1229. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-5);
  1230. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-3);
  1231. */
  1232. if(maxProfile.ChargingProfileId != -1)
  1233. {
  1234. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1235. {
  1236. if(maxProfile.ChargingSchedule.Duration != -1)
  1237. {
  1238. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1239. 0:
  1240. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1241. }
  1242. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1243. {
  1244. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1245. {
  1246. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1247. 0:
  1248. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1249. }
  1250. }
  1251. }
  1252. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1253. {
  1254. if(maxProfile.ChargingSchedule.Duration != -1)
  1255. {
  1256. maxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1257. 0:
  1258. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1259. }
  1260. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1261. {
  1262. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1263. {
  1264. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1265. 0:
  1266. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1267. }
  1268. }
  1269. }
  1270. else
  1271. {
  1272. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1273. {
  1274. if(maxProfile.ChargingSchedule.Duration != -1)
  1275. {
  1276. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1277. 0:
  1278. (maxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1279. }
  1280. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1281. {
  1282. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1283. {
  1284. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1285. 0:
  1286. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1287. }
  1288. }
  1289. }
  1290. else
  1291. {
  1292. if(maxProfile.ChargingSchedule.Duration != -1)
  1293. {
  1294. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1295. 0:
  1296. (maxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1297. }
  1298. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1299. {
  1300. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1301. {
  1302. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1303. 0:
  1304. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1305. }
  1306. }
  1307. }
  1308. }
  1309. /*
  1310. DEBUG_INFO("MaxProfile after align.\n");
  1311. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1312. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1313. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1314. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1315. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1316. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1317. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1318. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1319. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1320. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1321. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1322. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1323. {
  1324. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1325. {
  1326. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1327. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1328. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1329. }
  1330. }
  1331. DEBUG_INFO("------------------------------------\n");*/
  1332. }
  1333. if(defaultTxProfile.ChargingProfileId != -1)
  1334. {
  1335. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1336. {
  1337. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1338. {
  1339. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1340. 0:
  1341. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1342. }
  1343. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1344. {
  1345. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1346. {
  1347. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1348. 0:
  1349. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1350. }
  1351. }
  1352. }
  1353. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1354. {
  1355. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1356. {
  1357. defaultTxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1358. 0:
  1359. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1360. }
  1361. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1362. {
  1363. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1364. {
  1365. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1366. 0:
  1367. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1368. }
  1369. }
  1370. }
  1371. else
  1372. {
  1373. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1374. {
  1375. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1376. {
  1377. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1378. 0:
  1379. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1380. }
  1381. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1382. {
  1383. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1384. {
  1385. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1386. 0:
  1387. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1388. }
  1389. }
  1390. }
  1391. else
  1392. {
  1393. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1394. {
  1395. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1396. 0:
  1397. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1398. }
  1399. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1400. {
  1401. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1402. {
  1403. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1404. 0:
  1405. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1406. }
  1407. }
  1408. }
  1409. }
  1410. /*
  1411. DEBUG_INFO("defaultTxProfile after align.\n");
  1412. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1413. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1414. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1415. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1416. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1417. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1418. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1419. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1420. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1421. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1422. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1423. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1424. {
  1425. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1426. {
  1427. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1428. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1429. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1430. }
  1431. }
  1432. DEBUG_INFO("------------------------------------\n");*/
  1433. }
  1434. if(txProfile.ChargingProfileId != -1)
  1435. {
  1436. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1437. {
  1438. if(txProfile.ChargingSchedule.Duration != -1)
  1439. {
  1440. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1441. 0:
  1442. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1443. }
  1444. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1445. {
  1446. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1447. {
  1448. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1449. 0:
  1450. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1451. }
  1452. }
  1453. }
  1454. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1455. {
  1456. if(txProfile.ChargingSchedule.Duration != -1)
  1457. {
  1458. txProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1459. 0:
  1460. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1461. }
  1462. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1463. {
  1464. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1465. {
  1466. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1467. 0:
  1468. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1469. }
  1470. }
  1471. }
  1472. else
  1473. {
  1474. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1475. {
  1476. if(txProfile.ChargingSchedule.Duration != -1)
  1477. {
  1478. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1479. 0:
  1480. (txProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1481. }
  1482. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1483. {
  1484. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1485. {
  1486. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1487. 0:
  1488. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1489. }
  1490. }
  1491. }
  1492. else
  1493. {
  1494. if(txProfile.ChargingSchedule.Duration != -1)
  1495. {
  1496. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1497. 0:
  1498. (txProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1499. }
  1500. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1501. {
  1502. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1503. {
  1504. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1505. 0:
  1506. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1507. }
  1508. }
  1509. }
  1510. }
  1511. /*
  1512. DEBUG_INFO("txProfile after align.\n");
  1513. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1514. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1515. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1516. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1517. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1518. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1519. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1520. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1521. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1522. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1523. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1524. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1525. {
  1526. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1527. {
  1528. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1529. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1530. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1531. }
  1532. }*/
  1533. }
  1534. /*
  1535. * Merge to conposite schedule
  1536. */
  1537. //DEBUG_INFO("====================================\n");
  1538. // Find each profile period quantity
  1539. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1540. {
  1541. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1542. limitMax = idx+1;
  1543. }
  1544. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1545. {
  1546. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1547. limitDef = idx+1;
  1548. }
  1549. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1550. {
  1551. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1552. limitTx = idx+1;
  1553. }
  1554. // TxProfile found, composite schedule based on it
  1555. if(txProfile.ChargingProfileId != -1)
  1556. {
  1557. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1558. {
  1559. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1560. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq))
  1561. {
  1562. if(maxProfile.ChargingProfileId != -1)
  1563. {
  1564. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1565. {
  1566. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod) &&
  1567. (maxProfile.ChargingSchedule.Duration > txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod))
  1568. {
  1569. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1570. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1571. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1572. }
  1573. if(idxMaxPeriod == (limitMax-1))
  1574. {
  1575. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1576. {
  1577. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1578. {
  1579. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1580. compositePeriodIdx++;
  1581. }
  1582. else
  1583. {
  1584. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1585. }
  1586. }
  1587. }
  1588. }
  1589. }
  1590. else
  1591. {
  1592. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1593. {
  1594. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1595. compositePeriodIdx++;
  1596. }
  1597. else
  1598. {
  1599. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1600. }
  1601. }
  1602. }
  1603. if(idxTxPeriod == (limitTx-1))
  1604. {
  1605. if(defaultTxProfile.ChargingProfileId != -1)
  1606. {
  1607. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1608. {
  1609. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod > txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod) &&
  1610. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq))
  1611. {
  1612. if(maxProfile.ChargingProfileId != -1)
  1613. {
  1614. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1615. {
  1616. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1617. {
  1618. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1619. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1620. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1621. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1622. {
  1623. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1624. {
  1625. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1626. compositePeriodIdx++;
  1627. }
  1628. else
  1629. {
  1630. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1631. }
  1632. }
  1633. break;
  1634. }
  1635. }
  1636. }
  1637. else
  1638. {
  1639. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1640. {
  1641. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1642. compositePeriodIdx++;
  1643. }
  1644. else
  1645. {
  1646. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1647. }
  1648. }
  1649. }
  1650. }
  1651. }
  1652. }
  1653. }
  1654. }
  1655. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1656. else if(defaultTxProfile.ChargingProfileId != -1)
  1657. {
  1658. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1659. {
  1660. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1661. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq))
  1662. {
  1663. if(maxProfile.ChargingProfileId != -1)
  1664. {
  1665. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1666. {
  1667. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1668. {
  1669. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1670. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1671. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1672. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1673. {
  1674. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1675. {
  1676. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1677. compositePeriodIdx++;
  1678. }
  1679. else
  1680. {
  1681. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1682. }
  1683. }
  1684. break;
  1685. }
  1686. }
  1687. }
  1688. else
  1689. {
  1690. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1691. {
  1692. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1693. compositePeriodIdx++;
  1694. }
  1695. else
  1696. {
  1697. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1698. }
  1699. }
  1700. }
  1701. }
  1702. }
  1703. // Fill other period by MaxProfile
  1704. if(maxProfile.ChargingProfileId != -1)
  1705. {
  1706. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1707. {
  1708. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1709. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq))
  1710. {
  1711. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  1712. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1713. {
  1714. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  1715. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  1716. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1717. }
  1718. if(idxMaxPeriod == (limitMax-1))
  1719. {
  1720. if(maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod)
  1721. {
  1722. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  1723. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  1724. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1725. }
  1726. if(tmpPeriod.Limit != -1)
  1727. {
  1728. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1729. {
  1730. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1731. {
  1732. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1733. compositePeriodIdx++;
  1734. }
  1735. else
  1736. {
  1737. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1738. }
  1739. }
  1740. }
  1741. }
  1742. }
  1743. }
  1744. }
  1745. DEBUG_INFO("Composite schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1746. DEBUG_INFO("Composite schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1747. DEBUG_INFO("Composite rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1748. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1749. {
  1750. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1751. {
  1752. compositeProfile->ChargingProfileId = 1;
  1753. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1754. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1755. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1756. }
  1757. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1758. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1759. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1760. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1761. }
  1762. if(line)
  1763. free(line);
  1764. }
  1765. //==========================================
  1766. // Init all share memory
  1767. //==========================================
  1768. int InitShareMemory()
  1769. {
  1770. int result = PASS;
  1771. int MeterSMId;
  1772. //creat ShmSysConfigAndInfo
  1773. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1774. {
  1775. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1776. result = FAIL;
  1777. }
  1778. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1779. {
  1780. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  1781. result = FAIL;
  1782. }
  1783. else
  1784. {}
  1785. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1786. {
  1787. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1788. result = FAIL;
  1789. }
  1790. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1791. {
  1792. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1793. result = FAIL;
  1794. }
  1795. else
  1796. {}
  1797. //creat ShmPsuData
  1798. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  1799. {
  1800. DEBUG_ERROR("shmget ShmPsuData NG\n");
  1801. result = FAIL;
  1802. }
  1803. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1804. {
  1805. DEBUG_ERROR("shmat ShmPsuData NG\n");
  1806. result = FAIL;
  1807. }
  1808. else
  1809. {}
  1810. //creat ShmOCPP16Data
  1811. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1812. {
  1813. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  1814. result = FAIL;
  1815. }
  1816. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1817. {
  1818. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  1819. result = FAIL;
  1820. }
  1821. else
  1822. {}
  1823. /****************************** For Initial Settings************************************************/
  1824. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  1825. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  1826. // allocate Configuration memory address
  1827. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  1828. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  1829. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  1830. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  1831. //offline MeterValue Interval
  1832. TempMeterValueInterval = 0;
  1833. return result;
  1834. }
  1835. int ProcessShareMemory()
  1836. {
  1837. if(InitShareMemory() == FAIL)
  1838. {
  1839. DEBUG_ERROR("InitShareMemory NG\n");
  1840. if(ShmStatusCodeData!=NULL)
  1841. {
  1842. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1843. }
  1844. sleep(5);
  1845. return FAIL;
  1846. }
  1847. return PASS;
  1848. }
  1849. //---------------------common routine---------------------------//
  1850. int isOFFline(void)
  1851. {
  1852. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  1853. {
  1854. if(TempMeterValueInterval >= 2 )
  1855. {
  1856. TempMeterValueInterval = 0;
  1857. return TRUE;
  1858. }
  1859. else
  1860. {
  1861. TempMeterValueInterval = TempMeterValueInterval+ 1;
  1862. return FALSE;
  1863. }
  1864. }
  1865. else
  1866. {
  1867. return FALSE;
  1868. }
  1869. }
  1870. //---------------------------------------------
  1871. // new:
  1872. // enum SYSTEM_STATUS
  1873. // {
  1874. // SYS_MODE_BOOTING = 0,
  1875. // SYS_MODE_IDLE = 1,
  1876. // SYS_MODE_AUTHORIZING = 2,
  1877. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  1878. // SYS_MODE_REASSIGN = 4,
  1879. // SYS_MODE_PREPARING = 5,
  1880. // SYS_MODE_PREPARE_FOR_EV = 6,
  1881. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  1882. // SYS_MODE_CHARGING = 8,
  1883. // SYS_MODE_TERMINATING = 9,
  1884. // SYS_MODE_COMPLETE = 10,
  1885. // SYS_MODE_ALARM = 11,
  1886. // SYS_MODE_FAULT = 12,
  1887. // SYS_MODE_RESERVATION = 13,
  1888. // SYS_MODE_BOOKING = 14,
  1889. // SYS_MODE_MAINTAIN = 15,
  1890. // SYS_MODE_DEBUG = 16,
  1891. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  1892. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  1893. // SYS_MODE_UPDATE = 19
  1894. // };
  1895. //
  1896. //
  1897. //-----------------------------------------
  1898. void CheckSystemValue(void)
  1899. {
  1900. uint8_t reqSampleMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1901. uint8_t reqClockAlignMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1902. char filenmae[100]={0};
  1903. char str[100]={0};
  1904. int tempIndex = 0;
  1905. //===============================
  1906. // send Heartbeat
  1907. //===============================
  1908. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  1909. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  1910. {
  1911. clientTime.Heartbeat=time((time_t*)NULL);
  1912. if(server_sign == TRUE)
  1913. {
  1914. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  1915. }
  1916. else
  1917. {
  1918. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  1919. }
  1920. }
  1921. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  1922. {
  1923. //parameter for test
  1924. sendHeartbeatRequest(0);
  1925. //==============================================
  1926. // Reset Waiting Time
  1927. //==============================================
  1928. clientTime.Heartbeat=time((time_t*)NULL);
  1929. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1930. }
  1931. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1932. {
  1933. //===============================
  1934. // CSU Trigger Reset Conf
  1935. //===============================
  1936. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1937. {
  1938. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1939. }
  1940. //===============================
  1941. // CSU Trigger Authorize Request
  1942. //===============================
  1943. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  1944. {
  1945. sendAuthorizeRequest(0);
  1946. authorizeRetryTimes = authorizeRetryTimes + 1;
  1947. if(authorizeRetryTimes < 3)
  1948. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1949. }
  1950. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  1951. {
  1952. authorizeRetryTimes = 0;
  1953. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1954. server_sign = FALSE;
  1955. }
  1956. 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))
  1957. {
  1958. sendAuthorizeRequest(0);
  1959. }
  1960. //===============================
  1961. // CSU Trigger Smart Charging Profilw
  1962. //===============================
  1963. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  1964. {
  1965. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1966. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  1967. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1968. }
  1969. //==============================================
  1970. // Charger start transaction
  1971. //==============================================
  1972. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1973. {
  1974. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1975. sendStartTransactionRequest(gun_index);
  1976. clientTime.StartTransaction = time((time_t*)NULL);
  1977. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1978. }
  1979. //==============================================
  1980. // Charger stop transaction
  1981. //==============================================
  1982. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1983. {
  1984. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1985. sendStopTransactionRequest(gun_index);
  1986. clientTime.StopTransaction = time((time_t*)NULL);
  1987. }
  1988. //==============================================
  1989. // Charger status report
  1990. //==============================================
  1991. //--- Check Mode Change ---//
  1992. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  1993. if(gunType[gun_index] == 'J')
  1994. {
  1995. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1996. {
  1997. tempIndex = ((gun_index==2) ? 1: 0);
  1998. }
  1999. else
  2000. {
  2001. tempIndex = gun_index;
  2002. }
  2003. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2004. {
  2005. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2006. {
  2007. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2008. {
  2009. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2010. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2011. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2012. statusModeChage[gun_index] = TRUE;
  2013. }
  2014. #if 1 // for TempStopTransaction
  2015. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2016. {
  2017. checkTempStopTransaction(gun_index);
  2018. }
  2019. #endif
  2020. }
  2021. }
  2022. }
  2023. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2024. {
  2025. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2026. {
  2027. tempIndex = ((gun_index==2) ? 1: 0);
  2028. }
  2029. else
  2030. {
  2031. tempIndex = gun_index;
  2032. }
  2033. for (int index = 0; index < CCS_QUANTITY; index++)
  2034. {
  2035. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2036. {
  2037. 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]*/ )
  2038. {
  2039. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2040. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2041. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2042. statusModeChage[gun_index] = TRUE;
  2043. }
  2044. #if 1 // for TempStopTransaction
  2045. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2046. {
  2047. checkTempStopTransaction(gun_index);
  2048. }
  2049. #endif
  2050. }
  2051. }
  2052. }
  2053. else if(gunType[gun_index] == 'G')
  2054. {
  2055. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2056. {
  2057. tempIndex = ((gun_index==2) ? 1: 0);
  2058. }
  2059. else
  2060. {
  2061. tempIndex = gun_index;
  2062. }
  2063. for (int index = 0; index < GB_QUANTITY; index++)
  2064. {
  2065. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2066. {
  2067. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2068. {
  2069. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2070. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2071. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2072. statusModeChage[gun_index] = TRUE;
  2073. }
  2074. #if 1 // for TempStopTransaction
  2075. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2076. {
  2077. checkTempStopTransaction(gun_index);
  2078. }
  2079. #endif
  2080. }
  2081. }
  2082. }
  2083. else
  2084. {
  2085. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2086. {
  2087. tempIndex = 2;
  2088. }
  2089. else
  2090. {
  2091. tempIndex = gun_index;
  2092. }
  2093. for (int index = 0; index < AC_QUANTITY; index++)
  2094. {
  2095. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2096. {
  2097. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2098. {
  2099. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2100. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2101. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2102. statusModeChage[gun_index] = TRUE;
  2103. }
  2104. #if 1 // for TempStopTransaction
  2105. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2106. {
  2107. checkTempStopTransaction(gun_index);
  2108. }
  2109. #endif
  2110. }
  2111. }// END
  2112. }
  2113. if(isWebsocketSendable &&
  2114. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) || ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))) )
  2115. {
  2116. if(SystemInitial > 0)
  2117. SystemInitial -= 1;
  2118. sendStatusNotificationRequest(gun_index);
  2119. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2120. statusModeChage[gun_index] = FALSE;
  2121. }
  2122. //==============================================
  2123. // Meter report
  2124. //==============================================
  2125. if(/*(server_sign == TRUE) &&(isOFFline() == TRUE) ||*/
  2126. (((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)))
  2127. {
  2128. //check Transaction active
  2129. if(gunType[gun_index] == 'J')
  2130. {
  2131. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2132. {
  2133. tempIndex = ((gun_index==2) ? 1: 0);
  2134. }
  2135. else
  2136. {
  2137. tempIndex = gun_index;
  2138. }
  2139. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2140. {
  2141. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2142. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2143. {
  2144. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2145. {
  2146. reqSampleMeter[gun_index] = 1;
  2147. }
  2148. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2149. {
  2150. reqClockAlignMeter[gun_index] = 1;
  2151. }
  2152. }
  2153. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2154. {
  2155. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2156. if((access(filenmae,F_OK))!=-1)
  2157. {
  2158. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2159. sprintf(str,"rm -f %s",filenmae);
  2160. system(str);
  2161. }
  2162. }
  2163. }// End for CHAdeMO
  2164. }
  2165. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2166. {
  2167. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2168. {
  2169. tempIndex = ((gun_index==2) ? 1: 0);
  2170. }
  2171. else
  2172. {
  2173. tempIndex = gun_index;
  2174. }
  2175. for (int index = 0; index < CCS_QUANTITY; index++)
  2176. {
  2177. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2178. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2179. {
  2180. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2181. {
  2182. reqSampleMeter[gun_index] = 1;
  2183. }
  2184. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2185. {
  2186. reqClockAlignMeter[gun_index] = 1;
  2187. }
  2188. }
  2189. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2190. {
  2191. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2192. if((access(filenmae,F_OK))!=-1)
  2193. {
  2194. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2195. sprintf(str,"rm -f %s",filenmae);
  2196. system(str);
  2197. }
  2198. }
  2199. } // End for CCS
  2200. }
  2201. else if(gunType[gun_index] == 'G')
  2202. {
  2203. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2204. {
  2205. tempIndex = ((gun_index==2) ? 1: 0);
  2206. }
  2207. else
  2208. {
  2209. tempIndex = gun_index;
  2210. }
  2211. for (int index = 0; index < GB_QUANTITY; index++)
  2212. {
  2213. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2214. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2215. {
  2216. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2217. {
  2218. reqSampleMeter[gun_index] = 1;
  2219. }
  2220. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2221. {
  2222. reqClockAlignMeter[gun_index] = 1;
  2223. }
  2224. }
  2225. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2226. {
  2227. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2228. if((access(filenmae,F_OK))!=-1)
  2229. {
  2230. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2231. sprintf(str,"rm -f %s",filenmae);
  2232. system(str);
  2233. }
  2234. }
  2235. }// End for GB
  2236. }
  2237. else
  2238. {
  2239. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2240. {
  2241. tempIndex = 2;
  2242. }
  2243. else
  2244. {
  2245. tempIndex = gun_index;
  2246. }
  2247. for (int index = 0; index < AC_QUANTITY; index++)
  2248. {
  2249. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2250. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2251. {
  2252. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2253. {
  2254. reqSampleMeter[gun_index] = 1;
  2255. }
  2256. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2257. {
  2258. reqClockAlignMeter[gun_index] = 1;
  2259. }
  2260. }
  2261. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2262. {
  2263. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2264. if((access(filenmae,F_OK))!=-1)
  2265. {
  2266. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2267. sprintf(str,"rm -f %s",filenmae);
  2268. system(str);
  2269. }
  2270. }
  2271. }//End for AC
  2272. }
  2273. if(reqSampleMeter[gun_index] == 1)
  2274. {
  2275. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2276. storeTempStopTransaction(gun_index);
  2277. }
  2278. else if(reqClockAlignMeter[gun_index] == 1)
  2279. {
  2280. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2281. }
  2282. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2283. sleep(1);
  2284. }
  2285. //==============================================
  2286. // Check Connector reserved
  2287. //==============================================
  2288. //===============================
  2289. // Check if Reserve is expired
  2290. //===============================
  2291. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2292. {
  2293. double diff_t;
  2294. struct tm tp;
  2295. // current time
  2296. time_t t = time(NULL);
  2297. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2298. tp.tm_isdst = -1;
  2299. time_t utc = mktime(&tp);
  2300. diff_t = difftime(utc, t);
  2301. if(diff_t <= 0)
  2302. {
  2303. DEBUG_INFO("reserve expired.\n");
  2304. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2305. }
  2306. }//END OF Check if Reserve is expired
  2307. //==========================================
  2308. // csu trigger FirmwareStatusNotificationReq
  2309. //==========================================
  2310. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2311. {
  2312. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2313. }
  2314. //==========================================
  2315. // csu trigger CancelReservationConf
  2316. //==========================================
  2317. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2318. {
  2319. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2320. }
  2321. //==========================================
  2322. // csu trigger ChangeAvailabilityConf
  2323. //==========================================
  2324. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2325. {
  2326. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2327. }
  2328. //==========================================
  2329. // csu trigger UnlockConnectorConf
  2330. //==========================================
  2331. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2332. {
  2333. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2334. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2335. }
  2336. //==========================================
  2337. // csu trigger ReserveNowConf
  2338. //==========================================
  2339. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2340. {
  2341. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2342. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2343. }
  2344. //==========================================
  2345. // csu trigger DataTransferReq
  2346. //==========================================
  2347. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2348. {
  2349. sendDataTransferRequest(gun_index);
  2350. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2351. }
  2352. }
  2353. }
  2354. //==========================================
  2355. // send request routine
  2356. //==========================================
  2357. int sendAuthorizeRequest(int gun_index)
  2358. {
  2359. mtrace();
  2360. int result = FAIL;
  2361. char message[100]={0};
  2362. char guid[37];
  2363. char tempdata[65]={0};
  2364. DEBUG_INFO("sendAuthorizeRequest...\n");
  2365. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2366. //Local Authorize
  2367. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2368. {
  2369. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2370. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2371. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2372. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2373. result = PASS;
  2374. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2375. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2376. authorizeRetryTimes = 0;
  2377. return result;
  2378. }
  2379. 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))||
  2380. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2381. {
  2382. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2383. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2384. {
  2385. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2386. {
  2387. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2388. }
  2389. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2390. {
  2391. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2392. }
  2393. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  2394. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2395. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2396. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2397. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2398. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2399. authorizeRetryTimes = 0;
  2400. return result;
  2401. }
  2402. else
  2403. {
  2404. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  2405. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2406. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2407. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2408. result = PASS;
  2409. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2410. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2411. authorizeRetryTimes = 0;
  2412. return result;
  2413. }
  2414. }
  2415. //initailize struct Authorize
  2416. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2417. //get data from shared memory
  2418. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2419. random_uuid(guid);
  2420. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2421. LWS_Send(message);
  2422. sprintf(tempdata, "Authorize,%d", gun_index);
  2423. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2424. {
  2425. result = PASS;
  2426. DEBUG_INFO("Authorize mapItem pass\n");
  2427. }
  2428. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2429. return result;
  2430. }
  2431. int sendBootNotificationRequest(void)
  2432. {
  2433. mtrace();
  2434. int result = FAIL;
  2435. char message[500]={0}, payload[700]={0};
  2436. char guid[37]={0};
  2437. char tempdata[65]={0};
  2438. /*
  2439. int IsGunCharging = FALSE;
  2440. //check Transaction active
  2441. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2442. {
  2443. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2444. {
  2445. IsGunCharging = TRUE;
  2446. }
  2447. }
  2448. for (int index = 0; index < CCS_QUANTITY; index++)
  2449. {
  2450. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2451. {
  2452. IsGunCharging = TRUE;
  2453. }
  2454. }
  2455. for (int index = 0; index < GB_QUANTITY; index++)
  2456. {
  2457. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2458. {
  2459. IsGunCharging = TRUE;
  2460. }
  2461. }
  2462. for (int index = 0; index < AC_QUANTITY; index++)
  2463. {
  2464. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2465. {
  2466. IsGunCharging = TRUE;
  2467. }
  2468. }
  2469. if(IsGunCharging == TRUE)
  2470. {
  2471. server_sign = TRUE;
  2472. return result;
  2473. }
  2474. */
  2475. // Fill BootNotification fields
  2476. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2477. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2478. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2479. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2480. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2481. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2482. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2483. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2484. ShmOCPP16Data->ChargeBoxId
  2485. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2486. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2487. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2488. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2489. ,ShmOCPP16Data->BootNotification.CpIccid
  2490. ,ShmOCPP16Data->BootNotification.CpImsi);
  2491. random_uuid(guid);
  2492. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2493. LWS_Send(message);
  2494. sprintf(tempdata, "BootNotification,0");
  2495. 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*/)
  2496. {
  2497. result = PASS;
  2498. }
  2499. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2500. strcpy(queuedata,message);
  2501. return result;
  2502. }
  2503. int sendDataTransferRequest(int gun_index)
  2504. {
  2505. mtrace();
  2506. char message[1000]={0};
  2507. char guid[37]={0};
  2508. char tempdata[65]={0};
  2509. int result = FAIL;
  2510. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2511. random_uuid(guid);
  2512. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2513. MESSAGE_TYPE_CALL,
  2514. guid,
  2515. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2516. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2517. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2518. LWS_Send(message);
  2519. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2520. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2521. {
  2522. result = PASS;
  2523. DEBUG_INFO("DataTransfer mapItem pass\n");
  2524. }
  2525. return result;
  2526. }
  2527. int sendDiagnosticsStatusNotificationRequest(char *status)
  2528. {
  2529. mtrace();
  2530. int result = FAIL;
  2531. char message[110]={0};
  2532. char guid[37]={0};
  2533. char tempdata[65]={0};
  2534. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2535. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2536. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2537. random_uuid(guid);
  2538. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2539. LWS_Send(message);
  2540. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2541. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2542. {
  2543. result = PASS;
  2544. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2545. }
  2546. //#ifdef SystemLogMessage
  2547. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2548. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2549. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2550. //#endif
  2551. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2552. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2553. //record status
  2554. if(strcmp(status,"Idle")==0)
  2555. {
  2556. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2557. }
  2558. else if(strcmp(status,"Uploaded")==0)
  2559. {
  2560. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2561. }
  2562. else if(strcmp(status,"UploadFailed")==0)
  2563. {
  2564. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2565. }
  2566. else if(strcmp(status,"Uploading")==0)
  2567. {
  2568. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2569. }
  2570. return result;
  2571. }
  2572. int sendFirmwareStatusNotificationRequest(char *status)
  2573. {
  2574. mtrace();
  2575. int result = FAIL;
  2576. char message[110]={0};
  2577. char guid[37]={0};
  2578. char tempdata[65]={0};
  2579. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2580. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2581. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2582. random_uuid(guid);
  2583. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2584. LWS_Send(message);
  2585. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2586. 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*/)
  2587. {
  2588. result = PASS;
  2589. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2590. }
  2591. //#ifdef SystemLogMessage
  2592. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2593. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2594. //#endif
  2595. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2596. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2597. //record status
  2598. if(strcmp(status,"Downloaded")==0)
  2599. {
  2600. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2601. }
  2602. else if(strcmp(status,"DownloadFailed")==0)
  2603. {
  2604. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  2605. }
  2606. else if(strcmp(status,"Downloading")==0)
  2607. {
  2608. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2609. }
  2610. else if(strcmp(status,"Idle")==0)
  2611. {
  2612. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2613. }
  2614. else if(strcmp(status,"InstallationFailed")==0)
  2615. {
  2616. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2617. }
  2618. else if(strcmp(status,"Installing")==0)
  2619. {
  2620. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2621. }
  2622. else if(strcmp(status,"Installed")==0)
  2623. {
  2624. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2625. }
  2626. return result;
  2627. }
  2628. int sendHeartbeatRequest(int gun_index)
  2629. {
  2630. mtrace();
  2631. int result = FAIL;
  2632. char message[80]={0};
  2633. char guid[37]={0};
  2634. char tempdata[65]={0};
  2635. random_uuid(guid);
  2636. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2637. , MESSAGE_TYPE_CALL
  2638. , guid );
  2639. LWS_Send(message);
  2640. sprintf(tempdata, "Heartbeat,%d", 0);
  2641. 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*/)
  2642. {
  2643. result = PASS;
  2644. }
  2645. return result;
  2646. }
  2647. int sendStartTransactionRequest(int gun_index)
  2648. {
  2649. mtrace();
  2650. int result = FAIL;
  2651. char message[250]={0};
  2652. char guid[37]={0};
  2653. struct timeval tmnow;
  2654. struct tm *tm;
  2655. char buf[28];//, usec_buf[6];
  2656. char tempdata[65]={0};
  2657. int tempIndex = 0;
  2658. DEBUG_INFO("sendStartTransactionRequest...\n");
  2659. gettimeofday(&tmnow, NULL);
  2660. time_t t;
  2661. t = time(NULL);
  2662. /*UTC time and date*/
  2663. tm = gmtime(&t);
  2664. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2665. #if 0 // remove temporally
  2666. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2667. strcat(buf,".");
  2668. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2669. strcat(buf,usec_buf);
  2670. #endif
  2671. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2672. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2673. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2674. // clear StartTransaction Response
  2675. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2676. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2677. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2678. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2679. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2680. if(gunType[gun_index] == 'J')
  2681. {
  2682. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2683. {
  2684. tempIndex = ((gun_index==2) ? 1: 0);
  2685. }
  2686. else
  2687. {
  2688. tempIndex = gun_index;
  2689. }
  2690. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2691. {
  2692. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2693. {
  2694. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  2695. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2696. }
  2697. }
  2698. }
  2699. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2700. {
  2701. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2702. {
  2703. tempIndex = ((gun_index==2) ? 1: 0);
  2704. }
  2705. else
  2706. {
  2707. tempIndex = gun_index;
  2708. }
  2709. for (int index = 0; index < CCS_QUANTITY; index++)
  2710. {
  2711. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2712. {
  2713. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  2714. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  2715. }
  2716. }
  2717. }
  2718. else if(gunType[gun_index] == 'G')
  2719. {
  2720. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2721. {
  2722. tempIndex = ((gun_index==2) ? 1: 0);
  2723. }
  2724. else
  2725. {
  2726. tempIndex = gun_index;
  2727. }
  2728. for (int index = 0; index < GB_QUANTITY; index++)
  2729. {
  2730. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2731. {
  2732. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  2733. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  2734. }
  2735. }
  2736. }
  2737. else
  2738. {
  2739. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2740. {
  2741. tempIndex = 2;
  2742. }
  2743. else
  2744. {
  2745. tempIndex = gun_index;
  2746. }
  2747. for (int index = 0; index < AC_QUANTITY; index++)
  2748. {
  2749. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2750. {
  2751. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  2752. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  2753. }
  2754. }
  2755. }
  2756. random_uuid(guid);
  2757. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  2758. {
  2759. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  2760. , gun_index +1
  2761. , MESSAGE_TYPE_CALL
  2762. , guid
  2763. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2764. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2765. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2766. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2767. }
  2768. else
  2769. {
  2770. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  2771. , gun_index +1
  2772. , MESSAGE_TYPE_CALL
  2773. , guid
  2774. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2775. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2776. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2777. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  2778. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2779. }
  2780. #if 1
  2781. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  2782. 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*/)
  2783. {
  2784. result = PASS;
  2785. }
  2786. #endif
  2787. strcpy(queuedata, message);
  2788. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2789. /*
  2790. if(GetTransactionQueueNum() == 1)
  2791. {
  2792. LWS_Send(message + 2);
  2793. }*/
  2794. return result;
  2795. }
  2796. int sendStatusNotificationRequest(int gun_index)
  2797. {
  2798. mtrace();
  2799. int result = FAIL;
  2800. char message[600]={0};
  2801. char guid[37];
  2802. int currentStatus = 0;
  2803. struct timeval tmnow;
  2804. struct tm *tm;
  2805. char buf[28];//, usec_buf[6];
  2806. char tempdata[65]={0};
  2807. int tempIndex = 0;
  2808. gettimeofday(&tmnow, NULL);
  2809. time_t t;
  2810. t = time(NULL);
  2811. /*UTC time and date*/
  2812. tm = gmtime(&t);
  2813. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2814. #if 0 // remove temporally
  2815. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2816. strcat(buf,".");
  2817. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2818. strcat(buf,usec_buf);
  2819. #endif
  2820. printf("%s",buf);
  2821. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  2822. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  2823. // it's option
  2824. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  2825. /*
  2826. enum _SYSTEM_STATUS
  2827. {
  2828. S_BOOTING = 0,
  2829. S_IDLE, = 1
  2830. S_AUTHORIZING, =2
  2831. S_REASSIGN_CHECK, =3
  2832. S_REASSIGN, =4
  2833. S_PRECHARGE, =5
  2834. S_PREPARING_FOR_EV, =6
  2835. S_PREPARING_FOR_EVSE, =7
  2836. S_CHARGING, =8
  2837. S_TERMINATING, =9
  2838. S_COMPLETE, =10
  2839. S_ALARM, =11
  2840. S_FAULT =12
  2841. }
  2842. */
  2843. //check Transaction active
  2844. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2845. if(gunType[gun_index] == 'J')
  2846. {
  2847. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2848. {
  2849. tempIndex = ((gun_index==2) ? 1: 0);
  2850. }
  2851. else
  2852. {
  2853. tempIndex = gun_index;
  2854. }
  2855. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2856. {
  2857. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  2858. {
  2859. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  2860. {
  2861. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  2862. {
  2863. currentStatus = 1; //OCPP Status: Preparing
  2864. }
  2865. else
  2866. {
  2867. currentStatus = 0; //OCPP Status: Available
  2868. }
  2869. }
  2870. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  2871. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  2872. ) //S_PRECHARGE
  2873. {
  2874. currentStatus = 1; //OCPP Status: Preparing
  2875. }
  2876. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2877. {
  2878. currentStatus = 2; //OCPP Status: Charging
  2879. }
  2880. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  2881. {
  2882. currentStatus = 5; //OCPP Status: Finishing
  2883. }
  2884. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  2885. {
  2886. currentStatus = 4; //OCPP Status: SuspendedEV
  2887. }
  2888. 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
  2889. {
  2890. currentStatus = 7; //OCPP Status: Unavailable
  2891. }
  2892. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  2893. {
  2894. currentStatus = 8; //OCPP Status: Faulted
  2895. }
  2896. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  2897. {
  2898. currentStatus = 6; //OCPP Status: Reserved
  2899. }
  2900. } //end of the same index
  2901. }//end of for CHAdeMO_QUANTITY
  2902. }
  2903. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2904. {
  2905. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2906. {
  2907. tempIndex = ((gun_index==2) ? 1: 0);
  2908. }
  2909. else
  2910. {
  2911. tempIndex = gun_index;
  2912. }
  2913. for (int index = 0; index < CCS_QUANTITY; index++)
  2914. {
  2915. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2916. {
  2917. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  2918. {
  2919. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  2920. {
  2921. currentStatus = 1; //OCPP Status: Preparing
  2922. }
  2923. else
  2924. {
  2925. currentStatus = 0; //OCPP Status: Available
  2926. }
  2927. }
  2928. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  2929. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  2930. ) //S_PRECHARGE
  2931. {
  2932. currentStatus = 1; //OCPP Status: Preparing
  2933. }
  2934. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2935. {
  2936. currentStatus = 2; //OCPP Status: Charging
  2937. }
  2938. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  2939. {
  2940. currentStatus = 5; //OCPP Status: Finishing
  2941. }
  2942. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  2943. {
  2944. currentStatus = 4; //OCPP Status: SuspendedEV
  2945. }
  2946. 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
  2947. {
  2948. currentStatus = 7; //OCPP Status : Unavailable
  2949. }
  2950. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  2951. {
  2952. currentStatus = 8; //OCPP Status: Faulted
  2953. }
  2954. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  2955. {
  2956. currentStatus = 6; //OCPP Status: Reserved
  2957. }
  2958. } //end of the same index
  2959. } // end of for CCS_QUANTITY
  2960. }
  2961. else if(gunType[gun_index] == 'G')
  2962. {
  2963. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2964. {
  2965. tempIndex = ((gun_index==2) ? 1: 0);
  2966. }
  2967. else
  2968. {
  2969. tempIndex = gun_index;
  2970. }
  2971. for (int index = 0; index < GB_QUANTITY; index++)
  2972. {
  2973. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2974. {
  2975. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  2976. {
  2977. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  2978. {
  2979. currentStatus = 1; //OCPP Status: Preparing
  2980. }
  2981. else
  2982. {
  2983. currentStatus = 0; //OCPP Status: Available
  2984. }
  2985. }
  2986. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  2987. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  2988. ) //S_PRECHARGE
  2989. {
  2990. currentStatus = 1; //OCPP Status: Preparing
  2991. }
  2992. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2993. {
  2994. currentStatus = 2; //OCPP Status: Charging
  2995. }
  2996. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  2997. {
  2998. currentStatus = 5; //OCPP Status: Finishing
  2999. }
  3000. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3001. {
  3002. currentStatus = 4; //OCPP Status: SuspendedEV
  3003. }
  3004. 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
  3005. {
  3006. currentStatus = 7; //OCPP Status: Unavailable
  3007. }
  3008. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3009. {
  3010. currentStatus = 8; //OCPP Status: Faulted
  3011. }
  3012. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3013. {
  3014. currentStatus = 6; //OCPP Status: Reserved
  3015. }
  3016. } //end of the same index
  3017. } // end of for GB_QUANTITY
  3018. }
  3019. else
  3020. {
  3021. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3022. {
  3023. tempIndex = 2;
  3024. }
  3025. else
  3026. {
  3027. tempIndex = gun_index;
  3028. }
  3029. for (int index = 0; index < AC_QUANTITY; index++)
  3030. {
  3031. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3032. {
  3033. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3034. {
  3035. 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))
  3036. {
  3037. currentStatus = 1; //OCPP Status: Preparing
  3038. }
  3039. else
  3040. {
  3041. currentStatus = 0; //OCPP Status: Available
  3042. }
  3043. }
  3044. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3045. {
  3046. currentStatus = 1; //OCPP Status: Preparing
  3047. }
  3048. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3049. {
  3050. currentStatus = 2; //OCPP Status: Charging
  3051. }
  3052. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3053. {
  3054. currentStatus = 5; //OCPP Status: Finishing
  3055. }
  3056. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3057. {
  3058. currentStatus = 4; //OCPP Status: SuspendedEV
  3059. }
  3060. 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
  3061. {
  3062. currentStatus = 7; //OCPP Status: Unavailable
  3063. }
  3064. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3065. {
  3066. currentStatus = 8; //OCPP Status: Faulted
  3067. }
  3068. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3069. {
  3070. currentStatus = 6; //OCPP Status: Reserved
  3071. }
  3072. }//end of the same index
  3073. }//end of for AC_QUANTITY
  3074. }
  3075. //it's option
  3076. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3077. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3078. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3079. random_uuid(guid);
  3080. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3081. , MESSAGE_TYPE_CALL
  3082. , guid
  3083. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3084. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3085. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3086. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3087. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3088. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3089. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3090. LWS_Send(message);
  3091. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3092. 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*/)
  3093. {
  3094. //DEBUG_ERROR("statusNotification mapitem pass");
  3095. result = PASS;
  3096. }
  3097. return result;
  3098. }
  3099. int sendStopTransactionRequest(int gun_index)
  3100. {
  3101. mtrace();
  3102. int result = FAIL;
  3103. //char message[1500]={0};
  3104. char guid[37]={0};
  3105. char tempdata[65]={0};
  3106. int tempIndex = 0;
  3107. //int idx_sample=0;
  3108. DEBUG_ERROR("sendStopTransactionRequest \n");
  3109. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3110. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3111. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3112. if(gunType[gun_index] == 'J')
  3113. {
  3114. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3115. {
  3116. tempIndex = ((gun_index==2) ? 1: 0);
  3117. }
  3118. else
  3119. {
  3120. tempIndex = gun_index;
  3121. }
  3122. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3123. {
  3124. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3125. {
  3126. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3127. }
  3128. }// END OF CHAdeMO_QUANTITY
  3129. }
  3130. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3131. {
  3132. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3133. {
  3134. tempIndex = ((gun_index==2) ? 1: 0);
  3135. }
  3136. else
  3137. {
  3138. tempIndex = gun_index;
  3139. }
  3140. for (int index = 0; index < CCS_QUANTITY; index++)
  3141. {
  3142. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3143. {
  3144. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3145. }
  3146. }// END OF CCS_QUANTITY
  3147. }
  3148. else if(gunType[gun_index] == 'G')
  3149. {
  3150. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3151. {
  3152. tempIndex = ((gun_index==2) ? 1: 0);
  3153. }
  3154. else
  3155. {
  3156. tempIndex = gun_index;
  3157. }
  3158. for (int index = 0; index < GB_QUANTITY; index++)
  3159. {
  3160. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3161. {
  3162. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3163. }
  3164. }// END OF GB_QUANTITY
  3165. }
  3166. else
  3167. {
  3168. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3169. {
  3170. tempIndex = 2;
  3171. }
  3172. else
  3173. {
  3174. tempIndex = gun_index;
  3175. }
  3176. for (int index = 0; index < AC_QUANTITY; index++)
  3177. {
  3178. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3179. {
  3180. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3181. }
  3182. }// END OF AC_QUANTITY
  3183. }
  3184. //====================================== Stop Transaction Time =====================================================
  3185. struct timeval tmnow;
  3186. struct tm *tm;
  3187. char buf[28];//, usec_buf[6];
  3188. gettimeofday(&tmnow, NULL);
  3189. time_t t;
  3190. t = time(NULL);
  3191. /*UTC time and date*/
  3192. tm = gmtime(&t);
  3193. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3194. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3195. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3196. random_uuid(guid);
  3197. /***********************************transactionData******************************************************/
  3198. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3200. //=================================
  3201. // Transaction_Begin
  3202. //=================================
  3203. //============================================ Energy.Active.Import.Interval ================================
  3204. //idx_sample=0;
  3205. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  3206. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3207. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3208. 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*/]);
  3209. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3210. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3211. {
  3212. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3213. }
  3214. else
  3215. {
  3216. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3217. }
  3218. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3219. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3220. //=================================
  3221. // Transaction_End
  3222. //=================================
  3223. // ================================= Current.Import L1 ===============================================
  3224. //idx_sample=1;
  3225. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3226. if(gunType[gun_index] == 'J')
  3227. {
  3228. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3229. {
  3230. tempIndex = ((gun_index==2) ? 1: 0);
  3231. }
  3232. else
  3233. {
  3234. tempIndex = gun_index;
  3235. }
  3236. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3237. {
  3238. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3239. {
  3240. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3241. }
  3242. }// End of for CHAdeMO_QUANTITY
  3243. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3244. }
  3245. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3246. {
  3247. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3248. {
  3249. tempIndex = ((gun_index==2) ? 1: 0);
  3250. }
  3251. else
  3252. {
  3253. tempIndex = gun_index;
  3254. }
  3255. for (int index = 0; index < CCS_QUANTITY; index++)
  3256. {
  3257. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3258. {
  3259. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3260. }
  3261. }// End of for CCS_QUANTITY
  3262. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3263. }
  3264. else if(gunType[gun_index] == 'G')
  3265. {
  3266. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3267. {
  3268. tempIndex = ((gun_index==2) ? 1: 0);
  3269. }
  3270. else
  3271. {
  3272. tempIndex = gun_index;
  3273. }
  3274. for (int index = 0; index < GB_QUANTITY; index++)
  3275. {
  3276. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3277. {
  3278. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3279. }
  3280. }// End of for GB_QUANTITY
  3281. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3282. }
  3283. else
  3284. {
  3285. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3286. {
  3287. tempIndex = 2;
  3288. }
  3289. else
  3290. {
  3291. tempIndex = gun_index;
  3292. }
  3293. for (int index = 0; index < AC_QUANTITY; index++)
  3294. {
  3295. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3296. {
  3297. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3298. }
  3299. }// End of for AC_QUANTITY
  3300. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3301. }
  3302. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3303. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3304. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3305. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3306. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3307. // ================================= Energy.Active.Import.Interval ==============================================
  3308. //idx_sample=2;
  3309. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3310. if(gunType[gun_index] == 'J')
  3311. {
  3312. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3313. {
  3314. tempIndex = ((gun_index==2) ? 1: 0);
  3315. }
  3316. else
  3317. {
  3318. tempIndex = gun_index;
  3319. }
  3320. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3321. {
  3322. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3323. {
  3324. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3325. }
  3326. }// END OF CHAdeMO_QUANTITY
  3327. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3328. }
  3329. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3330. {
  3331. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3332. {
  3333. tempIndex = ((gun_index==2) ? 1: 0);
  3334. }
  3335. else
  3336. {
  3337. tempIndex = gun_index;
  3338. }
  3339. for (int index = 0; index < CCS_QUANTITY; index++)
  3340. {
  3341. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3342. {
  3343. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3344. }
  3345. }// END OF CCS_QUANTITY
  3346. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3347. }
  3348. else if(gunType[gun_index] == 'G')
  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 < GB_QUANTITY; index++)
  3359. {
  3360. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3361. {
  3362. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3363. }
  3364. }// END OF GB_QUANTITY
  3365. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3366. }
  3367. else
  3368. {
  3369. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3370. {
  3371. tempIndex = 2;
  3372. }
  3373. else
  3374. {
  3375. tempIndex = gun_index;
  3376. }
  3377. for (int index = 0; index < AC_QUANTITY; index++)
  3378. {
  3379. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3380. {
  3381. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3382. }
  3383. }// END OF AC_QUANTITY
  3384. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3385. }
  3386. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3387. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3388. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3389. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3390. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3391. //=================================== Power.Active.Import ==================================================
  3392. //idx_sample=3;
  3393. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3394. if(gunType[gun_index] == 'J')
  3395. {
  3396. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3397. {
  3398. tempIndex = ((gun_index==2) ? 1: 0);
  3399. }
  3400. else
  3401. {
  3402. tempIndex = gun_index;
  3403. }
  3404. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3405. {
  3406. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3407. {
  3408. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3409. }
  3410. } // End for CHAdeMO_QUANTITY
  3411. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3412. }
  3413. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3414. {
  3415. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3416. {
  3417. tempIndex = ((gun_index==2) ? 1: 0);
  3418. }
  3419. else
  3420. {
  3421. tempIndex = gun_index;
  3422. }
  3423. for (int index = 0; index < CCS_QUANTITY; index++)
  3424. {
  3425. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3426. {
  3427. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3428. }
  3429. } // END for CCS_QUANTITY
  3430. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3431. }
  3432. else if(gunType[gun_index] == 'G')
  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 < GB_QUANTITY; index++)
  3443. {
  3444. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3445. {
  3446. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3447. }
  3448. }// END for GB_QUANTITY
  3449. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3450. }
  3451. else
  3452. {
  3453. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3454. {
  3455. tempIndex = 2;
  3456. }
  3457. else
  3458. {
  3459. tempIndex = gun_index;
  3460. }
  3461. for (int index = 0; index < AC_QUANTITY; index++)
  3462. {
  3463. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3464. {
  3465. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3466. }
  3467. } // END for AC_QUANTITY
  3468. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3469. }
  3470. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3471. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3472. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3473. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3474. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3475. //============================ Voltage L1 ====================================
  3476. //idx_sample=4;
  3477. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3478. if(gunType[gun_index] == 'J')
  3479. {
  3480. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3481. {
  3482. tempIndex = ((gun_index==2) ? 1: 0);
  3483. }
  3484. else
  3485. {
  3486. tempIndex = gun_index;
  3487. }
  3488. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3489. {
  3490. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3491. {
  3492. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3493. }
  3494. } // END OF FOR CHAdeMO_QUANTITY
  3495. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3496. }
  3497. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3498. {
  3499. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3500. {
  3501. tempIndex = ((gun_index==2) ? 1: 0);
  3502. }
  3503. else
  3504. {
  3505. tempIndex = gun_index;
  3506. }
  3507. for (int index = 0; index < CCS_QUANTITY; index++)
  3508. {
  3509. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3510. {
  3511. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3512. }
  3513. } // END OF FOR CCS_QUANTITY
  3514. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3515. }
  3516. else if(gunType[gun_index] == 'G')
  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 < GB_QUANTITY; index++)
  3527. {
  3528. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3529. {
  3530. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3531. }
  3532. } // END OF FOR GB_QUANTITY
  3533. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3534. }
  3535. else
  3536. {
  3537. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3538. {
  3539. tempIndex = 2;
  3540. }
  3541. else
  3542. {
  3543. tempIndex = gun_index;
  3544. }
  3545. for (int index = 0; index < AC_QUANTITY; index++)
  3546. {
  3547. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3548. {
  3549. 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
  3550. }
  3551. } // END OF FOR AC_QUANTITY
  3552. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3553. }
  3554. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3555. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3556. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3557. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3558. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3559. //====================== SoC ================================
  3560. //idx_sample=5;
  3561. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3562. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3563. {
  3564. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3565. {
  3566. tempIndex = ((gun_index==2) ? 1: 0);
  3567. }
  3568. else
  3569. {
  3570. tempIndex = gun_index;
  3571. }
  3572. if(gunType[gun_index] == 'J')
  3573. {
  3574. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3575. {
  3576. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3577. {
  3578. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3579. }
  3580. }
  3581. }
  3582. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3583. {
  3584. for (int index = 0; index < CCS_QUANTITY; index++)
  3585. {
  3586. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3587. {
  3588. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3589. }
  3590. }
  3591. }
  3592. else if(gunType[gun_index] == 'G')
  3593. {
  3594. for (int index = 0; index < GB_QUANTITY; index++)
  3595. {
  3596. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3597. {
  3598. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  3599. }
  3600. }
  3601. }
  3602. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3603. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  3604. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  3605. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  3606. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  3607. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  3608. } // END FOR DC CASE
  3609. // ================================= Current.Import L2 ===============================================
  3610. //idx_sample=6;
  3611. // AC 3 phse L2 current
  3612. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3613. {
  3614. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3615. {
  3616. tempIndex = 2;
  3617. }
  3618. else
  3619. {
  3620. tempIndex = gun_index;
  3621. }
  3622. for (int index = 0; index < AC_QUANTITY; index++)
  3623. {
  3624. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3625. {
  3626. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  3627. }
  3628. }// End of for AC_QUANTITY
  3629. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  3630. }
  3631. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3632. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  3633. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  3634. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  3635. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3636. // ================================= Current.Import L3 ===============================================
  3637. //idx_sample=7;
  3638. // AC 3 phse L3 current
  3639. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3640. {
  3641. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3642. {
  3643. tempIndex = 2;
  3644. }
  3645. else
  3646. {
  3647. tempIndex = gun_index;
  3648. }
  3649. for (int index = 0; index < AC_QUANTITY; index++)
  3650. {
  3651. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3652. {
  3653. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  3654. }
  3655. }// End of for AC_QUANTITY
  3656. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  3657. }
  3658. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3659. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  3660. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  3661. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  3662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3663. //============================ Voltage L2 ====================================
  3664. //idx_sample=8;
  3665. // AC 3 phse L2 voltage
  3666. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3667. {
  3668. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3669. {
  3670. tempIndex = 2;
  3671. }
  3672. else
  3673. {
  3674. tempIndex = gun_index;
  3675. }
  3676. for (int index = 0; index < AC_QUANTITY; index++)
  3677. {
  3678. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3679. {
  3680. 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
  3681. }
  3682. } // END OF FOR AC_QUANTITY
  3683. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  3684. }
  3685. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3686. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  3687. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  3688. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  3689. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3690. //============================ Voltage L3 ====================================
  3691. //idx_sample=8;
  3692. // AC 3 phse L3 voltage
  3693. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3694. {
  3695. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3696. {
  3697. tempIndex = 2;
  3698. }
  3699. else
  3700. {
  3701. tempIndex = gun_index;
  3702. }
  3703. for (int index = 0; index < AC_QUANTITY; index++)
  3704. {
  3705. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3706. {
  3707. 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
  3708. }
  3709. } // END OF FOR AC_QUANTITY
  3710. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  3711. }
  3712. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3713. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  3714. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  3715. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  3716. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3717. //================================================ Message create ====================================================
  3718. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3719. {
  3720. 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\"}]}]}]"
  3721. ,gun_index+1
  3722. ,MESSAGE_TYPE_CALL
  3723. ,guid
  3724. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3725. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3726. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3727. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3728. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3729. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3730. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3731. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3732. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3733. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3734. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3735. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3736. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3737. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3738. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3739. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3740. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3741. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3742. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3743. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3744. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3745. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3746. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3747. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3748. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3749. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3750. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3751. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3752. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3753. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3754. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3755. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3756. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3757. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3758. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3759. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3760. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3761. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3762. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3763. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3764. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3765. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  3766. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  3767. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  3768. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  3769. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  3770. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  3771. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  3772. );
  3773. }
  3774. else
  3775. {
  3776. if((ShmSysConfigAndInfo->SysConfig.ModelName[2]!='Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2]!='W'))
  3777. {
  3778. 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\"}]}]}]"
  3779. ,gun_index+1
  3780. ,MESSAGE_TYPE_CALL
  3781. ,guid
  3782. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3783. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3784. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3785. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3786. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3787. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3788. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3789. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3790. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3791. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3792. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3793. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3794. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3795. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3796. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3797. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3798. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3799. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3800. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3801. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3802. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3803. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3804. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3805. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3806. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3807. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3808. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3809. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3810. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3811. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3812. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3813. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3814. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3815. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3816. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3817. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3818. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3819. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3820. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3821. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3822. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3823. );
  3824. }
  3825. else
  3826. {
  3827. 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\"}]}]}]"
  3828. ,gun_index+1
  3829. ,MESSAGE_TYPE_CALL
  3830. ,guid
  3831. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3832. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3833. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3834. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3835. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3836. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3837. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3838. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3839. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3840. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3841. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3842. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3843. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3844. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3845. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3846. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3847. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3848. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3849. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3850. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3851. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3852. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3853. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3854. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3855. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3856. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3857. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3858. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3859. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3860. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3861. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3862. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3863. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3864. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3865. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3866. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3867. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3868. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3869. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3870. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3871. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  3873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  3874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  3875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  3876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  3877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  3878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  3879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  3880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  3881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  3882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  3883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  3884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  3885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  3886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  3887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  3888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  3889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  3890. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  3891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  3892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  3893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  3894. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  3895. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  3896. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  3897. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  3898. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  3899. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  3900. );
  3901. }
  3902. }
  3903. #if 1 // for TempStopTransaction
  3904. //Delete TempStopTransaction
  3905. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  3906. {
  3907. remove("/Storage/OCPP/TempStopTransaction"); // remove file "TempStopTransaction"
  3908. }
  3909. #endif
  3910. #if 1
  3911. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  3912. if(hashmap_operation(0, guid, tempdata) == 1)
  3913. {
  3914. result = PASS;
  3915. DEBUG_INFO("StopTransaction mapitem pass\n");
  3916. }
  3917. #endif
  3918. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3919. /*
  3920. if(GetTransactionQueueNum() == 1)
  3921. {
  3922. LWS_Send(queuedata+2);
  3923. }*/
  3924. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  3925. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  3926. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  3927. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  3928. {
  3929. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  3930. }
  3931. //for test
  3932. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3933. return result;
  3934. }
  3935. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  3936. {
  3937. mtrace();
  3938. int result = FAIL;
  3939. char guid[37]={0};
  3940. char tempdata[65]={0};
  3941. int tempIndex = 0;
  3942. DEBUG_INFO("sendMeterValuesRequest ...\n");
  3943. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  3944. /*
  3945. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0) && (ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  3946. {
  3947. DEBUG_INFO("NOT SENT METER Vlaue\n");
  3948. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  3949. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  3950. return result;
  3951. }*/
  3952. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  3953. {
  3954. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  3955. }
  3956. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3957. //set value
  3958. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  3959. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) ? ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId : 0);
  3960. random_uuid(guid);
  3961. //UTC Date time
  3962. struct timeval tmnow;
  3963. struct tm *tm;
  3964. char buf[28];//, usec_buf[6];
  3965. gettimeofday(&tmnow, NULL);
  3966. time_t t;
  3967. t = time(NULL);
  3968. /*UTC time and date*/
  3969. tm = gmtime(&t);
  3970. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3971. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  3972. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  3973. //idx_sample=0;
  3974. //********************************(1)Current.Import L1************************************************/
  3975. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3976. if(gunType[gun_index] == 'J')
  3977. {
  3978. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3979. {
  3980. tempIndex = ((gun_index==2) ? 1: 0);
  3981. }
  3982. else
  3983. {
  3984. tempIndex = gun_index;
  3985. }
  3986. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3987. {
  3988. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3989. {
  3990. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  3991. }
  3992. }
  3993. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  3994. }
  3995. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3996. {
  3997. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3998. {
  3999. tempIndex = ((gun_index==2) ? 1: 0);
  4000. }
  4001. else
  4002. {
  4003. tempIndex = gun_index;
  4004. }
  4005. for (int index = 0; index < CCS_QUANTITY; index++)
  4006. {
  4007. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4008. {
  4009. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4010. }
  4011. }
  4012. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4013. }
  4014. else if(gunType[gun_index] == 'G')
  4015. {
  4016. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4017. {
  4018. tempIndex = ((gun_index==2) ? 1: 0);
  4019. }
  4020. else
  4021. {
  4022. tempIndex = gun_index;
  4023. }
  4024. for (int index = 0; index < GB_QUANTITY; index++)
  4025. {
  4026. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4027. {
  4028. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4029. }
  4030. }
  4031. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4032. }
  4033. else
  4034. {
  4035. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4036. {
  4037. tempIndex = 2;
  4038. }
  4039. else
  4040. {
  4041. tempIndex = gun_index;
  4042. }
  4043. for (int index = 0; index < AC_QUANTITY; index++)
  4044. {
  4045. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4046. {
  4047. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4048. }
  4049. }
  4050. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4051. }
  4052. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4053. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4054. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4055. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4056. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4057. //idx_sample=1;
  4058. //********************************(2)Energy.Active.Import.Register ************************************************/
  4059. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4060. if(gunType[gun_index] == 'J')
  4061. {
  4062. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4063. {
  4064. tempIndex = ((gun_index==2) ? 1: 0);
  4065. }
  4066. else
  4067. {
  4068. tempIndex = gun_index;
  4069. }
  4070. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4071. {
  4072. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4073. {
  4074. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4075. }
  4076. }
  4077. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4078. }
  4079. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4080. {
  4081. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4082. {
  4083. tempIndex = ((gun_index==2) ? 1: 0);
  4084. }
  4085. else
  4086. {
  4087. tempIndex = gun_index;
  4088. }
  4089. for (int index = 0; index < CCS_QUANTITY; index++)
  4090. {
  4091. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4092. {
  4093. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4094. }
  4095. }
  4096. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4097. }
  4098. else if(gunType[gun_index] == 'G')
  4099. {
  4100. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4101. {
  4102. tempIndex = ((gun_index==2) ? 1: 0);
  4103. }
  4104. else
  4105. {
  4106. tempIndex = gun_index;
  4107. }
  4108. for (int index = 0; index < GB_QUANTITY; index++)
  4109. {
  4110. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4111. {
  4112. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4113. }
  4114. }
  4115. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4116. }
  4117. else
  4118. {
  4119. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4120. {
  4121. tempIndex = 2;
  4122. }
  4123. else
  4124. {
  4125. tempIndex = gun_index;
  4126. }
  4127. for (int index = 0; index < AC_QUANTITY; index++)
  4128. {
  4129. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4130. {
  4131. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4132. }
  4133. }
  4134. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4135. }
  4136. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4137. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4138. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4139. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4140. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4141. //idx_sample=2;
  4142. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4143. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4144. if(gunType[gun_index] == 'J')
  4145. {
  4146. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4147. {
  4148. tempIndex = ((gun_index==2) ? 1: 0);
  4149. }
  4150. else
  4151. {
  4152. tempIndex = gun_index;
  4153. }
  4154. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4155. {
  4156. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4157. {
  4158. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4159. }
  4160. } // END OF FOR CHAdeMO_QUANTITY
  4161. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4162. }
  4163. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4164. {
  4165. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4166. {
  4167. tempIndex = ((gun_index==2) ? 1: 0);
  4168. }
  4169. else
  4170. {
  4171. tempIndex = gun_index;
  4172. }
  4173. for (int index = 0; index < CCS_QUANTITY; index++)
  4174. {
  4175. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4176. {
  4177. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4178. }
  4179. } // END OF CCS_QUANTITY
  4180. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4181. }
  4182. else if(gunType[gun_index] == 'G')
  4183. {
  4184. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4185. {
  4186. tempIndex = ((gun_index==2) ? 1: 0);
  4187. }
  4188. else
  4189. {
  4190. tempIndex = gun_index;
  4191. }
  4192. for (int index = 0; index < GB_QUANTITY; index++)
  4193. {
  4194. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4195. {
  4196. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4197. }
  4198. } // END OF GB_QUANTITY
  4199. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4200. }
  4201. else
  4202. {
  4203. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4204. {
  4205. tempIndex = 2;
  4206. }
  4207. else
  4208. {
  4209. tempIndex = gun_index;
  4210. }
  4211. for (int index = 0; index < AC_QUANTITY; index++)
  4212. {
  4213. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4214. {
  4215. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4216. }
  4217. }
  4218. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4219. }
  4220. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4221. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4222. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4223. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4224. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4225. //idx_sample=3;
  4226. //********************************(4)Power.Active.Import************************************************/
  4227. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4228. if(gunType[gun_index] == 'J')
  4229. {
  4230. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4231. {
  4232. tempIndex = ((gun_index==2) ? 1: 0);
  4233. }
  4234. else
  4235. {
  4236. tempIndex = gun_index;
  4237. }
  4238. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4239. {
  4240. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4241. {
  4242. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4243. }
  4244. } // END OF FOR
  4245. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4246. }
  4247. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4248. {
  4249. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4250. {
  4251. tempIndex = ((gun_index==2) ? 1: 0);
  4252. }
  4253. else
  4254. {
  4255. tempIndex = gun_index;
  4256. }
  4257. for (int index = 0; index < CCS_QUANTITY; index++)
  4258. {
  4259. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4260. {
  4261. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4262. }
  4263. }
  4264. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4265. }
  4266. else if(gunType[gun_index] == 'G')
  4267. {
  4268. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4269. {
  4270. tempIndex = ((gun_index==2) ? 1: 0);
  4271. }
  4272. else
  4273. {
  4274. tempIndex = gun_index;
  4275. }
  4276. for (int index = 0; index < GB_QUANTITY; index++)
  4277. {
  4278. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4279. {
  4280. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4281. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4282. }
  4283. }
  4284. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4285. }
  4286. else
  4287. {
  4288. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4289. {
  4290. tempIndex = 2;
  4291. }
  4292. else
  4293. {
  4294. tempIndex = gun_index;
  4295. }
  4296. for (int index = 0; index < AC_QUANTITY; index++)
  4297. {
  4298. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4299. {
  4300. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4301. }
  4302. }
  4303. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4304. }
  4305. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4306. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4307. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4308. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4309. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4310. //idx_sample=4;
  4311. //***********************************************(5)VOLTAGE L1******************************************************/
  4312. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4313. if(gunType[gun_index] == 'J')
  4314. {
  4315. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4316. {
  4317. tempIndex = ((gun_index==2) ? 1: 0);
  4318. }
  4319. else
  4320. {
  4321. tempIndex = gun_index;
  4322. }
  4323. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4324. {
  4325. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4326. {
  4327. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4328. }
  4329. }
  4330. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4331. }
  4332. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4333. {
  4334. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4335. {
  4336. tempIndex = ((gun_index==2) ? 1: 0);
  4337. }
  4338. else
  4339. {
  4340. tempIndex = gun_index;
  4341. }
  4342. for (int index = 0; index < CCS_QUANTITY; index++)
  4343. {
  4344. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4345. {
  4346. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4347. }
  4348. }
  4349. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4350. }
  4351. else if(gunType[gun_index] == 'G')
  4352. {
  4353. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4354. {
  4355. tempIndex = ((gun_index==2) ? 1: 0);
  4356. }
  4357. else
  4358. {
  4359. tempIndex = gun_index;
  4360. }
  4361. for (int index = 0; index < GB_QUANTITY; index++)
  4362. {
  4363. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4364. {
  4365. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4366. }
  4367. }
  4368. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4369. }
  4370. else
  4371. {
  4372. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4373. {
  4374. tempIndex = 2;
  4375. }
  4376. else
  4377. {
  4378. tempIndex = gun_index;
  4379. }
  4380. for (int index = 0; index < AC_QUANTITY; index++)
  4381. {
  4382. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4383. {
  4384. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4385. }
  4386. }
  4387. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4388. }
  4389. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4390. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4391. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4392. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4393. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4394. //***********************************************(6)SOC******************************************************/
  4395. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4396. {
  4397. //idx_sample=5;
  4398. //sampledValue = NULL;
  4399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4400. {
  4401. tempIndex = ((gun_index==2) ? 1: 0);
  4402. }
  4403. else
  4404. {
  4405. tempIndex = gun_index;
  4406. }
  4407. if(gunType[gun_index] == 'J')
  4408. {
  4409. //tempIndex = ((gun_index==2) ? 1: 0);
  4410. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4411. {
  4412. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4413. {
  4414. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4415. }
  4416. }
  4417. }
  4418. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4419. {
  4420. //tempIndex = ((gun_index==2) ? 1: 0);
  4421. for (int index = 0; index < CCS_QUANTITY; index++)
  4422. {
  4423. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4424. {
  4425. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4426. }
  4427. }
  4428. }
  4429. else if(gunType[gun_index] == 'G')
  4430. {
  4431. //tempIndex = ((gun_index==2) ? 1: 0);
  4432. for (int index = 0; index < GB_QUANTITY; index++)
  4433. {
  4434. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4435. {
  4436. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4437. }
  4438. }
  4439. }
  4440. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4441. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4442. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4443. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4444. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_Outlet]);
  4445. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4446. }
  4447. //********************************(7)Current.Import L2************************************************/
  4448. // Only for AC 3 phase
  4449. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4450. {
  4451. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4452. {
  4453. tempIndex = 2;
  4454. }
  4455. else
  4456. {
  4457. tempIndex = gun_index;
  4458. }
  4459. for (int index = 0; index < AC_QUANTITY; index++)
  4460. {
  4461. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4462. {
  4463. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  4464. }
  4465. }
  4466. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  4467. }
  4468. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  4469. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  4470. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  4471. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  4472. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4473. //********************************(8)Current.Import L3************************************************/
  4474. // Only for AC 3 phase
  4475. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4476. {
  4477. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4478. {
  4479. tempIndex = 2;
  4480. }
  4481. else
  4482. {
  4483. tempIndex = gun_index;
  4484. }
  4485. for (int index = 0; index < AC_QUANTITY; index++)
  4486. {
  4487. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4488. {
  4489. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  4490. }
  4491. }
  4492. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  4493. }
  4494. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  4495. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  4496. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  4497. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  4498. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4499. //***********************************************(9)VOLTAGE L2******************************************************/
  4500. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4501. {
  4502. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4503. {
  4504. tempIndex = 2;
  4505. }
  4506. else
  4507. {
  4508. tempIndex = gun_index;
  4509. }
  4510. for (int index = 0; index < AC_QUANTITY; index++)
  4511. {
  4512. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4513. {
  4514. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  4515. }
  4516. }
  4517. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  4518. }
  4519. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  4520. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  4521. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  4522. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  4523. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4524. //***********************************************(10)VOLTAGE L3******************************************************/
  4525. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4526. {
  4527. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4528. {
  4529. tempIndex = 2;
  4530. }
  4531. else
  4532. {
  4533. tempIndex = gun_index;
  4534. }
  4535. for (int index = 0; index < AC_QUANTITY; index++)
  4536. {
  4537. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4538. {
  4539. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  4540. }
  4541. }
  4542. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  4543. }
  4544. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  4545. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  4546. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  4547. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  4548. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4549. // Message create ====================================================================================================
  4550. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4551. {
  4552. 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\"}]}]}]"
  4553. ,gun_index + 1
  4554. ,MESSAGE_TYPE_CALL
  4555. ,guid
  4556. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4557. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4558. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4559. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4560. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4561. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4562. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4563. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4564. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4565. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4566. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4567. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4568. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4569. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4570. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4571. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4572. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4573. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4574. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4575. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4576. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4577. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4578. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4579. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4580. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4581. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4582. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4583. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4584. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4585. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4586. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4587. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4588. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4589. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4590. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4591. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4592. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4593. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4594. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value
  4595. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context
  4596. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format
  4597. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand
  4598. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase
  4599. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location
  4600. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit
  4601. );
  4602. }
  4603. else
  4604. {
  4605. if((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W'))
  4606. {
  4607. 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\"}]}]}]"
  4608. ,gun_index + 1
  4609. ,MESSAGE_TYPE_CALL
  4610. ,guid
  4611. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4612. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4613. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4614. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4615. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4616. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4617. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4618. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4619. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4620. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4621. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4622. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4623. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4624. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4625. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4626. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4627. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4628. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4629. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4630. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4631. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4632. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4633. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4634. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4635. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4636. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4637. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4638. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4639. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4640. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4641. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4642. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4643. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4644. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4645. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4646. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4647. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4648. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4649. );
  4650. }
  4651. else
  4652. {
  4653. 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\"}]}]}]"
  4654. ,gun_index + 1
  4655. ,MESSAGE_TYPE_CALL
  4656. ,guid
  4657. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4658. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4659. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4660. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4661. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4662. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4663. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4664. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4665. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4666. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4667. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4668. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4669. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4670. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4671. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4672. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4673. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4674. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4675. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4676. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4677. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4678. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4679. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4680. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4681. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4682. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4683. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4684. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4685. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4686. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4687. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4688. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4689. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4690. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4691. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4692. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4693. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4694. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4695. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value
  4696. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context
  4697. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format
  4698. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand
  4699. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase
  4700. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location
  4701. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit
  4702. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value
  4703. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context
  4704. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format
  4705. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand
  4706. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase
  4707. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location
  4708. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit
  4709. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value
  4710. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context
  4711. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format
  4712. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand
  4713. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase
  4714. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location
  4715. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit
  4716. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value
  4717. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context
  4718. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format
  4719. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand
  4720. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase
  4721. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location
  4722. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit
  4723. );
  4724. }
  4725. }
  4726. // Put request guid to hash map
  4727. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4728. 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*/)
  4729. {
  4730. result = PASS;
  4731. DEBUG_INFO("MeterValues mapitem pass\n");
  4732. }
  4733. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4734. /*
  4735. if(GetTransactionQueueNum() == 1)
  4736. {
  4737. LWS_Send(queuedata +2);
  4738. }*/
  4739. return result;
  4740. }
  4741. //==========================================
  4742. // send confirm routine
  4743. //==========================================
  4744. int sendCancelReservationConfirmation(char *uuid,char *payload)
  4745. {
  4746. mtrace();
  4747. int result = FAIL;
  4748. char message[100]={0};
  4749. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  4750. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4751. LWS_Send(message);
  4752. result = TRUE;
  4753. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  4754. return result;
  4755. }
  4756. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  4757. {
  4758. mtrace();
  4759. int result = FAIL;
  4760. char message[100]={0};
  4761. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  4762. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4763. LWS_Send(message);
  4764. result = TRUE;
  4765. return result;
  4766. }
  4767. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  4768. {
  4769. mtrace();
  4770. int result = FAIL;
  4771. char message[100]={0};
  4772. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  4773. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4774. LWS_Send(message);
  4775. result = TRUE;
  4776. return result;
  4777. }
  4778. int sendClearCacheConfirmation(char *uuid,char *payload)
  4779. {
  4780. mtrace();
  4781. int result = FAIL;
  4782. char message[500]={0};
  4783. DEBUG_INFO("sendClearCacheConfirmation...\n");
  4784. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4785. LWS_Send(message);
  4786. return result;
  4787. }
  4788. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  4789. {
  4790. mtrace();
  4791. int result = FAIL;
  4792. char message[500]={0};
  4793. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  4794. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4795. LWS_Send(message);
  4796. return result;
  4797. }
  4798. int sendDataTransferConfirmation(char *uuid,char *payload)
  4799. {
  4800. mtrace();
  4801. char statusStr[20]={0};
  4802. char dataStr[10]={0};
  4803. char sstr[20]={0};
  4804. int c = 0;
  4805. char *loc;
  4806. int result = FAIL;
  4807. DEBUG_INFO("sendDataTransferConfirmation...\n");
  4808. /**********************status**************************/
  4809. loc = strstr(payload, "status");
  4810. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4811. c = 0;
  4812. while (loc[3+strlen("status")+c] != '\"')
  4813. {
  4814. sstr[c] = loc[3+strlen("status")+c];
  4815. c++;
  4816. }
  4817. sstr[c] = '\0';
  4818. strcpy(statusStr, sstr);
  4819. /**********************data**************************/
  4820. loc = strstr(payload, "data");
  4821. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4822. c = 0;
  4823. while (loc[3+strlen("data")+c] != '\"')
  4824. {
  4825. sstr[c] = loc[3+strlen("data")+c];
  4826. c++;
  4827. }
  4828. sstr[c] = '\0';
  4829. strcpy(dataStr, sstr);
  4830. return result;
  4831. }
  4832. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  4833. {
  4834. mtrace();
  4835. int result = FAIL;
  4836. char message[1000]={0};
  4837. int CompositeScheduleIndex = 0;
  4838. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  4839. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  4840. if(nPeriod == 0)
  4841. {
  4842. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  4843. {
  4844. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  4845. ,MESSAGE_TYPE_CALLRESULT
  4846. ,uuid
  4847. ,payload
  4848. ,connectorIdInt);
  4849. }
  4850. else
  4851. {
  4852. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  4853. ,MESSAGE_TYPE_CALLRESULT
  4854. ,uuid
  4855. ,payload
  4856. ,connectorIdInt
  4857. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4858. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4859. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4860. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  4861. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  4862. }
  4863. }
  4864. else
  4865. {
  4866. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  4867. ,MESSAGE_TYPE_CALLRESULT
  4868. ,uuid
  4869. ,payload
  4870. ,connectorIdInt
  4871. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4872. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4873. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4874. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  4875. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  4876. {
  4877. if (idx_sample == 0)
  4878. {
  4879. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4880. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4881. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4882. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4883. }
  4884. else
  4885. {
  4886. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4887. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4888. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4889. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4890. }
  4891. }
  4892. sprintf(message + strlen(message), "]}}]");
  4893. }
  4894. LWS_Send(message);
  4895. result = TRUE;
  4896. return result;
  4897. }
  4898. int sendGetConfigurationConfirmation(char *uuid)
  4899. {
  4900. mtrace();
  4901. int result = FAIL;
  4902. int MaxKeySupported = 0;
  4903. int sentConfigurationNumber= 0;
  4904. int sentunConfigurationNumber= 0;
  4905. char message[4000]={0};
  4906. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  4907. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  4908. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  4909. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  4910. ,MESSAGE_TYPE_CALLRESULT
  4911. ,uuid );
  4912. //configuration key
  4913. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  4914. {
  4915. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  4916. {
  4917. if (sentConfigurationNumber == 0)
  4918. {
  4919. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  4920. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  4921. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  4922. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  4923. }
  4924. else
  4925. {
  4926. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  4927. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  4928. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  4929. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  4930. }
  4931. sentConfigurationNumber = sentConfigurationNumber + 1;
  4932. }
  4933. }
  4934. sprintf(message + strlen(message), "]");
  4935. if(UnknownKeynum != 0)
  4936. {
  4937. sprintf(message + strlen(message), ",\"unknownKey\":[");
  4938. //unkown key
  4939. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  4940. {
  4941. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  4942. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  4943. if(sentunConfigurationNumber == 0)
  4944. {
  4945. sprintf(message + strlen(message), "\"%s\""
  4946. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  4947. }
  4948. else
  4949. {
  4950. sprintf(message + strlen(message), ",\"%s\""
  4951. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  4952. }
  4953. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  4954. }
  4955. sprintf(message + strlen(message), "]");
  4956. }
  4957. sprintf(message + strlen(message), "}]");
  4958. LWS_Send(message);
  4959. return result;
  4960. }
  4961. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  4962. {
  4963. mtrace();
  4964. int result = FAIL;
  4965. char message[400]={0};
  4966. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  4967. if(strcmp(payload,"")==0)
  4968. {
  4969. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  4970. }
  4971. else
  4972. {
  4973. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4974. }
  4975. LWS_Send(message);
  4976. result = TRUE;
  4977. return result;
  4978. }
  4979. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  4980. {
  4981. mtrace();
  4982. int result = FAIL;
  4983. char message[80]={0};
  4984. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  4985. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  4986. LWS_Send(message);
  4987. result = TRUE;
  4988. return result;
  4989. }
  4990. int sendRemoteStartConfirmation(char *uuid,char *payload)
  4991. {
  4992. mtrace();
  4993. int result = FAIL;
  4994. char message[80]={0};
  4995. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  4996. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4997. LWS_Send(message);
  4998. result = TRUE;
  4999. return result;
  5000. }
  5001. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5002. {
  5003. mtrace();
  5004. int result = FAIL;
  5005. char message[80]={0};
  5006. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5007. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5008. LWS_Send(message);
  5009. result = TRUE;
  5010. return result;
  5011. }
  5012. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5013. {
  5014. mtrace();
  5015. int result = FAIL;
  5016. char message[80]={0};
  5017. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5018. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5019. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5020. LWS_Send(message);
  5021. result = TRUE;
  5022. return result;
  5023. }
  5024. int sendResetConfirmation(char *uuid,char *payload)
  5025. {
  5026. mtrace();
  5027. int result = FAIL;
  5028. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5029. char message[80]={0};
  5030. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5031. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5032. LWS_Send(message);
  5033. result = TRUE;
  5034. return result;
  5035. }
  5036. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5037. {
  5038. mtrace();
  5039. int result = FAIL;
  5040. char message[500]={0};
  5041. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5042. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5043. LWS_Send(message);
  5044. result = TRUE;
  5045. return result;
  5046. }
  5047. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5048. {
  5049. mtrace();
  5050. int result = FAIL;
  5051. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5052. char message[80]={0};
  5053. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5054. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5055. LWS_Send(message);
  5056. result = TRUE;
  5057. return result;
  5058. }
  5059. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5060. {
  5061. mtrace();
  5062. int result = FAIL;
  5063. char message[80]={0};
  5064. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5065. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5066. LWS_Send(message);
  5067. result = TRUE;
  5068. return result;
  5069. }
  5070. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5071. {
  5072. mtrace();
  5073. int result = FAIL;
  5074. char message[80]={0};
  5075. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5076. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5077. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5078. LWS_Send(message);
  5079. result = TRUE;
  5080. return result;
  5081. }
  5082. int sendUpdateFirmwareConfirmation(char *uuid)
  5083. {
  5084. mtrace();
  5085. int result = FAIL;
  5086. char message[60]={0};
  5087. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5088. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5089. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5090. LWS_Send(message);
  5091. result = TRUE;
  5092. return result;
  5093. }
  5094. //==========================================
  5095. // send CallError routine
  5096. //==========================================
  5097. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5098. {
  5099. mtrace();
  5100. char message[220]={0};
  5101. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5102. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5103. LWS_Send(message);
  5104. }
  5105. //==========================================
  5106. // Handle server request routine Start
  5107. //==========================================
  5108. int handleCancelReservationRequest(char *uuid, char *payload)
  5109. {
  5110. mtrace();
  5111. int result = FAIL;
  5112. int gunNO = 0;
  5113. int reservationIdInt =0;
  5114. char comfirmstr[20];
  5115. DEBUG_INFO("handleCancelReservationRequest...\n");
  5116. json_object *CancelReservation;
  5117. CancelReservation = json_tokener_parse(payload);
  5118. if(!is_error(CancelReservation))
  5119. {
  5120. // Required data
  5121. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5122. }
  5123. json_object_put(CancelReservation);
  5124. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5125. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5126. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5127. //check Transaction active
  5128. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5129. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5130. {
  5131. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5132. {
  5133. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5134. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5135. if(gunType[2] == 'J')
  5136. {
  5137. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5138. }
  5139. else
  5140. {
  5141. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5142. }
  5143. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5144. goto end;
  5145. }
  5146. }
  5147. for (int index = 0; index < CCS_QUANTITY; index++)
  5148. {
  5149. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5150. {
  5151. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5152. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5153. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5154. {
  5155. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5156. }
  5157. else
  5158. {
  5159. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5160. }
  5161. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5162. goto end;
  5163. }
  5164. }
  5165. for (int index = 0; index < GB_QUANTITY; index++)
  5166. {
  5167. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5168. {
  5169. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5170. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5171. if(gunType[2] == 'G')
  5172. {
  5173. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5174. }
  5175. else
  5176. {
  5177. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5178. }
  5179. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5180. goto end;
  5181. }
  5182. }
  5183. for (int index = 0; index < AC_QUANTITY; index++)
  5184. {
  5185. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5186. {
  5187. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5188. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5189. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5190. {
  5191. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5192. }
  5193. else
  5194. {
  5195. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5196. }
  5197. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5198. goto end;
  5199. }
  5200. }
  5201. //The reservationId does NOT match the reservationId
  5202. sendCancelReservationConfirmation(uuid, comfirmstr);
  5203. end:
  5204. // Fill in ocpp packet uuid
  5205. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5206. return result;
  5207. }
  5208. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5209. {
  5210. mtrace();
  5211. int result = FAIL;
  5212. int gunIndex = 0;
  5213. char typeStr[16]={0};
  5214. char comfirmstr[20];
  5215. int specificId = FALSE;
  5216. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5217. json_object *ChangeAvailability;
  5218. ChangeAvailability = json_tokener_parse(payload);
  5219. if(!is_error(ChangeAvailability))
  5220. {
  5221. // Required data
  5222. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5223. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5224. }
  5225. json_object_put(ChangeAvailability);
  5226. if(gunIndex != 0)
  5227. {
  5228. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5229. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5230. }
  5231. else
  5232. {
  5233. for(int i=0; i < gunTotalNumber; i++)
  5234. {
  5235. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5236. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5237. }
  5238. }
  5239. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5240. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5241. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  5242. {
  5243. specificId = TRUE;
  5244. }
  5245. if(specificId == FALSE)
  5246. goto end;
  5247. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5248. {
  5249. //----------------------gunIndex is 0 ------------------------------------------------//
  5250. if(gunIndex == 0)
  5251. {
  5252. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5253. {
  5254. for(int i=0; i < gunTotalNumber; i++)
  5255. {
  5256. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5257. {
  5258. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5259. {
  5260. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5261. {
  5262. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5263. goto end;
  5264. }
  5265. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5266. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5267. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5268. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5269. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5270. {
  5271. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5272. goto end;
  5273. }
  5274. }
  5275. }//END FOR CHAdeMO_QUANTITY
  5276. for (int index = 0; index < CCS_QUANTITY; index++)
  5277. {
  5278. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5279. {
  5280. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5281. {
  5282. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5283. goto end;
  5284. }
  5285. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5286. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5287. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5288. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5289. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5290. {
  5291. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5292. goto end;
  5293. }
  5294. }
  5295. }//END FOR CCS_QUANTITY
  5296. for (int index = 0; index < GB_QUANTITY; index++)
  5297. {
  5298. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5299. {
  5300. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5301. {
  5302. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5303. goto end;
  5304. }
  5305. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5306. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5307. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5308. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5309. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5310. {
  5311. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5312. goto end;
  5313. }
  5314. }
  5315. }// END FOR GB_QUANTITY
  5316. for (int index = 0; index < AC_QUANTITY; index++)
  5317. {
  5318. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5319. {
  5320. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5321. {
  5322. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5323. goto end;
  5324. }
  5325. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5326. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5327. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5328. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5329. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5330. {
  5331. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5332. goto end;
  5333. }
  5334. }
  5335. }//END FOR AC_QUANTITY
  5336. }// END FOR gunTotalNumber
  5337. }
  5338. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5339. {
  5340. for(int i=0; i < gunTotalNumber; i++)
  5341. {
  5342. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5343. {
  5344. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5345. goto end;
  5346. }
  5347. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5348. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5349. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5350. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5351. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5352. {
  5353. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5354. goto end;
  5355. }
  5356. }
  5357. }
  5358. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5359. goto end;
  5360. }
  5361. //----------------------gunIndex is not 0 ------------------------------------------------//
  5362. //check Transaction active
  5363. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5364. {
  5365. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5366. {
  5367. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5368. {
  5369. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5370. goto end;
  5371. }
  5372. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5373. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5374. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5375. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5376. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5377. {
  5378. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5379. goto end;
  5380. }
  5381. else
  5382. {
  5383. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5384. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5385. goto end;
  5386. }
  5387. }
  5388. }//END FOR CHAdeMO_QUANTITY
  5389. for (int index = 0; index < CCS_QUANTITY; index++)
  5390. {
  5391. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5392. {
  5393. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5394. {
  5395. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5396. goto end;
  5397. }
  5398. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5399. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5400. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5401. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5402. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5403. {
  5404. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5405. goto end;
  5406. }
  5407. else
  5408. {
  5409. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5410. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5411. goto end;
  5412. }
  5413. }
  5414. }//END FOR CCS_QUANTITY
  5415. for (int index = 0; index < GB_QUANTITY; index++)
  5416. {
  5417. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5418. {
  5419. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5420. {
  5421. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5422. goto end;
  5423. }
  5424. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5425. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5426. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5427. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5428. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5429. {
  5430. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5431. goto end;
  5432. }
  5433. else
  5434. {
  5435. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5436. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5437. goto end;
  5438. }
  5439. }
  5440. }// END FOR GB_QUANTITY
  5441. for (int index = 0; index < AC_QUANTITY; index++)
  5442. {
  5443. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5444. {
  5445. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5446. {
  5447. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5448. goto end;
  5449. }
  5450. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5451. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5452. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5453. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5454. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5455. {
  5456. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5457. goto end;
  5458. }
  5459. else
  5460. {
  5461. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5462. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5463. goto end;
  5464. }
  5465. }
  5466. }//END FOR AC_QUANTITY
  5467. }//END FOR AvailabilityTypeStr[Inoperative]
  5468. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5469. {
  5470. //----------------------gunIndex is 0 ------------------------------------------------//
  5471. if(gunIndex == 0)
  5472. {
  5473. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5474. {
  5475. for(int i=0; i < gunTotalNumber; i++)
  5476. {
  5477. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5478. {
  5479. 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
  5480. {
  5481. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5482. goto end;
  5483. }
  5484. }//END FOR CHAdeMO_QUANTITY
  5485. for (int index = 0; index < CCS_QUANTITY; index++)
  5486. {
  5487. 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
  5488. {
  5489. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5490. goto end;
  5491. }
  5492. }//END FOR CCS_QUANTITY
  5493. for (int index = 0; index < GB_QUANTITY; index++)
  5494. {
  5495. 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
  5496. {
  5497. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5498. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5499. goto end;
  5500. }
  5501. }// END FOR GB_QUANTITY
  5502. for (int index = 0; index < AC_QUANTITY; index++)
  5503. {
  5504. 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
  5505. {
  5506. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5507. goto end;
  5508. }
  5509. }//END FOR CHAdeMO_QUANTITY
  5510. }// END FOR gunTotalNumber
  5511. }
  5512. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5513. {
  5514. for(int i=0; i < gunTotalNumber; i++)
  5515. {
  5516. for (int index = 0; index < AC_QUANTITY; index++)
  5517. {
  5518. 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
  5519. {
  5520. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5521. goto end;
  5522. }
  5523. }//END FOR CHAdeMO_QUANTITY
  5524. } // END FOR gunTotalNumber
  5525. }
  5526. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5527. goto end;
  5528. }
  5529. //----------------------gunIndex is not 0 ------------------------------------------------//
  5530. //check Transaction active
  5531. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5532. {
  5533. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5534. {
  5535. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5536. goto end;
  5537. }
  5538. }//END FOR CHAdeMO_QUANTITY
  5539. for (int index = 0; index < CCS_QUANTITY; index++)
  5540. {
  5541. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5542. {
  5543. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5544. goto end;
  5545. }
  5546. }//END FOR CCS_QUANTITY
  5547. for (int index = 0; index < GB_QUANTITY; index++)
  5548. {
  5549. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5550. {
  5551. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5552. goto end;
  5553. }
  5554. }// END FOR GB_QUANTITY
  5555. for (int index = 0; index < AC_QUANTITY; index++)
  5556. {
  5557. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5558. {
  5559. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5560. goto end;
  5561. }
  5562. }//END FOR AC_QUANTITY
  5563. }//END FOR AvailabilityTypeStr[Operative]
  5564. end:
  5565. if(gunIndex != 0)
  5566. {
  5567. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5568. }
  5569. else
  5570. {
  5571. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5572. }
  5573. if(gunIndex != 0)
  5574. {
  5575. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5576. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5577. }
  5578. else
  5579. {
  5580. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5581. {
  5582. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5583. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5584. }
  5585. }
  5586. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5587. return result;
  5588. }
  5589. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5590. {
  5591. mtrace();
  5592. int result = FAIL;
  5593. char keystr[40]={0};
  5594. char valuestr[100]={0};
  5595. char comfirmstr[20]={0};
  5596. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5597. json_object *ChangeConfiguration;
  5598. ChangeConfiguration = json_tokener_parse(payload);
  5599. if(!is_error(ChangeConfiguration))
  5600. {
  5601. // Required data
  5602. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5603. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5604. }
  5605. json_object_put(ChangeConfiguration);
  5606. if((uuid==NULL) || (payload ==NULL) )
  5607. {
  5608. DEBUG_ERROR("Payload is null\n");
  5609. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5610. }
  5611. else
  5612. {
  5613. int status = setKeyValue(keystr, valuestr);
  5614. switch(status)
  5615. {
  5616. case ConfigurationStatus_Accepted:
  5617. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5618. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5619. StoreConfigurationTable();
  5620. break;
  5621. case ConfigurationStatus_Rejected:
  5622. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5623. break;
  5624. case RebootRequired:
  5625. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5626. StoreConfigurationTable();
  5627. break;
  5628. case NotSupported:
  5629. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5630. break;
  5631. default:
  5632. break;
  5633. }
  5634. }
  5635. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5636. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5637. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5638. {
  5639. ChageWebSocketPingInterval(atoi(valuestr));
  5640. }
  5641. return result;
  5642. }
  5643. int handleClearCacheRequest(char *uuid, char *payload)
  5644. {
  5645. mtrace();
  5646. int result = FAIL;
  5647. char comfirmstr[20];
  5648. int fd;
  5649. char rmFileCmd[100]={0};
  5650. struct stat stats;
  5651. DEBUG_INFO("handleClearCacheRequest...\n");
  5652. stat("/Storage/OCPP", &stats);
  5653. // Check for directory existence
  5654. if (S_ISDIR(stats.st_mode) == 1)
  5655. {}
  5656. else
  5657. {
  5658. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  5659. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  5660. system(rmFileCmd);
  5661. }
  5662. memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
  5663. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  5664. {
  5665. DEBUG_INFO("AuthorizationCache file exist.\n");
  5666. }
  5667. else
  5668. {
  5669. DEBUG_INFO("AuthorizationCache file not exist\n");
  5670. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  5671. if(log == NULL)
  5672. {
  5673. DEBUG_INFO("AuthorizationCache file is NULL\n");
  5674. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5675. goto end;
  5676. }
  5677. else
  5678. {
  5679. fclose(log);
  5680. }
  5681. }
  5682. if((fd = open(AuthorizationCache_JSON,O_RDWR)) < 0)
  5683. {
  5684. DEBUG_INFO("open AuthorizationCache file failed\n");
  5685. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5686. }
  5687. else
  5688. {
  5689. DEBUG_INFO("open AuthorizationCache file successful\n");
  5690. ftruncate(fd,0);
  5691. lseek(fd,0,SEEK_SET);
  5692. close(fd);
  5693. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  5694. }
  5695. end:
  5696. sendClearCacheConfirmation(uuid, comfirmstr);
  5697. return result;
  5698. }
  5699. int handleClearChargingProfileRequest(char *uuid, char *payload)
  5700. {
  5701. mtrace();
  5702. int result = FAIL;
  5703. int resultRename;
  5704. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  5705. char chargingProfilePurposeStr[26]={0};
  5706. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  5707. char tempchargingProfilePurposeStr[26]={0};
  5708. char sstr[160]={0};
  5709. char str[100]={0};
  5710. int c = 0;
  5711. char *loc;
  5712. char fname[200]={0};
  5713. char comfirmstr[20]={0};
  5714. char word[1600]={0};
  5715. int clearflag = FALSE;
  5716. int chargingProfileIdIsNULL = FALSE;
  5717. int connectorIsNULL = FALSE;
  5718. int chargingProfilePurposeIsNULL = FALSE;
  5719. int stackLevelIsNULL = FALSE;
  5720. //int GotoEnd = FALSE;
  5721. FILE *fptr1, *fptr2;
  5722. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  5723. int n_chargingProfile=0;
  5724. int isEmptyFile = FALSE;
  5725. char sLineWord[1600]={0};
  5726. char chargingProfiles[10][100]={0};
  5727. int ChargeProfileCount = 0;
  5728. char ch;
  5729. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  5730. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  5731. json_object *ClearChargingProfile;
  5732. ClearChargingProfile = json_tokener_parse(payload);
  5733. if(!is_error(ClearChargingProfile))
  5734. {
  5735. // Optional data
  5736. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  5737. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  5738. else
  5739. chargingProfileIdIsNULL = TRUE;
  5740. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  5741. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  5742. else
  5743. connectorIsNULL = TRUE;
  5744. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  5745. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  5746. else
  5747. chargingProfilePurposeIsNULL = TRUE;
  5748. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  5749. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  5750. else
  5751. stackLevelIsNULL = TRUE;
  5752. }
  5753. json_object_put(ClearChargingProfile);
  5754. if(connectorIsNULL == FALSE)
  5755. {
  5756. switch(connectorIdInt)
  5757. {
  5758. case 0:
  5759. if(chargingProfilePurposeIsNULL == TRUE)
  5760. {
  5761. int l = 0;
  5762. strcpy(fname, ChargePointMaxProfile_JSON);
  5763. if((access(fname,F_OK))!=-1)
  5764. {
  5765. strcpy(chargingProfiles[l], fname);
  5766. l = l + 1;
  5767. }
  5768. strcpy(fname, TxDefaultProfile_0_JSON);
  5769. if((access(fname,F_OK))!=-1)
  5770. {
  5771. strcpy(chargingProfiles[l], fname);
  5772. l = l + 1;
  5773. }
  5774. ChargeProfileCount = l;
  5775. }
  5776. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  5777. {
  5778. strcpy(fname, ChargePointMaxProfile_JSON);
  5779. if((access(fname,F_OK))!=-1)
  5780. {
  5781. strcpy(chargingProfiles[0], fname);
  5782. ChargeProfileCount = 1;
  5783. }
  5784. }
  5785. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5786. {
  5787. strcpy(fname, TxDefaultProfile_0_JSON);
  5788. if((access(fname,F_OK))!=-1)
  5789. {
  5790. strcpy(chargingProfiles[0], fname);
  5791. ChargeProfileCount = 1;
  5792. }
  5793. }
  5794. break;
  5795. default:
  5796. if(chargingProfilePurposeIsNULL == TRUE)
  5797. {
  5798. int m = 0;
  5799. memset(fname, 0, ARRAY_SIZE(fname));
  5800. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5801. if((access(fname,F_OK))!=-1)
  5802. {
  5803. strcpy(chargingProfiles[m], fname);
  5804. m = m + 1;
  5805. }
  5806. memset(fname, 0, ARRAY_SIZE(fname));
  5807. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5808. if((access(fname,F_OK))!=-1)
  5809. {
  5810. strcpy(chargingProfiles[m], fname);
  5811. m = m + 1;
  5812. }
  5813. ChargeProfileCount = m;
  5814. }
  5815. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5816. {
  5817. //strcpy(fname, TxDefaultProfile_1_JSON);
  5818. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5819. if((access(fname,F_OK))!=-1)
  5820. {
  5821. strcpy(chargingProfiles[0], fname);
  5822. ChargeProfileCount = 1;
  5823. }
  5824. }
  5825. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  5826. {
  5827. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5828. if((access(fname,F_OK))!=-1)
  5829. {
  5830. strcpy(chargingProfiles[0], fname);
  5831. ChargeProfileCount = 1;
  5832. }
  5833. //strcpy(fname, TxProfile_1_JSON);
  5834. }
  5835. //strcpy(fname, ChargePointMaxProfile_JSON );
  5836. break;
  5837. }
  5838. }
  5839. else // Check all Charging Profiles
  5840. {
  5841. int i = 0;
  5842. char fnametemp[200]={0};
  5843. ChargeProfileCount = 0;
  5844. //Check ChargePointMaxProfile.json exit
  5845. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  5846. {
  5847. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  5848. i = i + 1;
  5849. }
  5850. //Check TxDefaultProfile_0.json exit
  5851. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  5852. {
  5853. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  5854. i = i + 1;
  5855. }
  5856. //Check TxDefaultProfile_%d.json
  5857. for(int j=1; j <= gunTotalNumber; j++)
  5858. {
  5859. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5860. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  5861. if((access(fnametemp,F_OK))!=-1)
  5862. {
  5863. strcpy(chargingProfiles[i], fnametemp);
  5864. i = i + 1;
  5865. }
  5866. }
  5867. //Check TxProfile_%d.json
  5868. for(int j=1; j <= gunTotalNumber; j++)
  5869. {
  5870. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5871. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  5872. if((access(fnametemp,F_OK))!=-1)
  5873. {
  5874. strcpy(chargingProfiles[i], fnametemp);
  5875. i = i + 1;
  5876. }
  5877. }
  5878. ChargeProfileCount = i;
  5879. }// End connectorIsNULL is TRUE
  5880. if(ChargeProfileCount == 0)
  5881. {
  5882. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5883. goto end;
  5884. }
  5885. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  5886. {
  5887. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5888. goto end;
  5889. }
  5890. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  5891. {
  5892. memset(str, 0, ARRAY_SIZE(str));
  5893. // clear temp file
  5894. sprintf(str,"rm -f %s",temp);
  5895. system(str);
  5896. for(int k=0; k < ChargeProfileCount; k++)
  5897. {
  5898. memset(str, 0, ARRAY_SIZE(str));
  5899. //clear file in C
  5900. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5901. system(str);
  5902. }
  5903. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5904. goto end;
  5905. }
  5906. else if(connectorIsNULL == TRUE)
  5907. {
  5908. for(int k=0; k < ChargeProfileCount; k++)
  5909. {
  5910. fptr1 = fopen(chargingProfiles[k], "r");
  5911. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  5912. //Check Charging Profile Count
  5913. while(fscanf(fptr1, "%s", word) != EOF)
  5914. {
  5915. //DEBUG_INFO("word=%s\n",word);
  5916. if(strstr(word, "chargingProfileId")!= NULL)
  5917. {
  5918. //DEBUG_INFO("test chargingProfileId \n");
  5919. n_chargingProfile = n_chargingProfile + 1;
  5920. //DEBUG_INFO("chargingProfileId Found\n");
  5921. }
  5922. }
  5923. rewind(fptr1);
  5924. //search Charging Profile Element
  5925. //int i= 0;
  5926. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  5927. {
  5928. //------------------------tempconnectorIdInt------------------------//
  5929. loc = strstr(sLineWord, "connectorId");
  5930. c = 0;
  5931. memset(sstr ,0, sizeof(sstr) );
  5932. while (loc[strlen("connectorId")+2+c] != ',')
  5933. {
  5934. sstr[c] = loc[strlen("connectorId")+2+c];
  5935. c++;
  5936. }
  5937. sstr[c] = '\0';
  5938. tempconnectorIdInt = atoi(sstr);
  5939. printf("file's gun number is %d\n", tempconnectorIdInt);
  5940. //--------------------------chargingProfileId--------------------//
  5941. c = 0;
  5942. loc = strstr(sLineWord, "chargingProfileId");
  5943. memset(sstr ,0, ARRAY_SIZE(sstr));
  5944. while (loc[strlen("chargingProfileId")+2+c] != ',')
  5945. {
  5946. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5947. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5948. c++;
  5949. }
  5950. sstr[c] = '\0';
  5951. tempchargingProfileIdInt = atoi(sstr);
  5952. //stackLevel
  5953. c = 0;
  5954. loc = strstr(sLineWord, "stackLevel");
  5955. memset(sstr ,0, ARRAY_SIZE(sstr));
  5956. while (loc[strlen("stackLevel")+2+c] != ',')
  5957. {
  5958. sstr[c] = loc[strlen("stackLevel")+2+c];
  5959. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5960. c++;
  5961. }
  5962. sstr[c] = '\0';
  5963. tempstackLevelInt = atoi(sstr);
  5964. c = 0;
  5965. loc = strstr(sLineWord, "chargingProfilePurpose");
  5966. memset(sstr ,0, ARRAY_SIZE(sstr));
  5967. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5968. {
  5969. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5970. c++;
  5971. }
  5972. sstr[c] = '\0';
  5973. strcpy(tempchargingProfilePurposeStr, sstr);
  5974. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  5975. {
  5976. //------- not write to fptr2-------//
  5977. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5978. //clearflag = TRUE;
  5979. }
  5980. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  5981. {
  5982. //------- not write to fptr2-------//
  5983. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5984. }
  5985. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  5986. {
  5987. //------- not write to fptr2-------//
  5988. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5989. }
  5990. else
  5991. {
  5992. fprintf(fptr2, sLineWord);//writing data into file
  5993. }
  5994. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  5995. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  5996. if(clearflag == TRUE)
  5997. {
  5998. fclose(fptr1);
  5999. fclose(fptr2);
  6000. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6001. system(str);
  6002. // clear temp file
  6003. sprintf(str,"rm -f %s",temp);
  6004. system(str);
  6005. }
  6006. else
  6007. {
  6008. fclose(fptr1);
  6009. fclose(fptr2);
  6010. memset(str, 0, ARRAY_SIZE(str));
  6011. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6012. system(str);
  6013. resultRename = rename(temp, chargingProfiles[k]);
  6014. if(resultRename == 0)
  6015. {
  6016. DEBUG_INFO("File ChargingProfile renamed successfully");
  6017. }
  6018. else
  6019. {
  6020. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6021. }
  6022. if(comfirmstr[0]== 0)
  6023. {
  6024. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6025. }
  6026. //Check chargingProfile is empty file
  6027. /*------ Read the file ----------------*/
  6028. fptr1=fopen(chargingProfiles[k],"r");
  6029. ch=fgetc(fptr1);
  6030. rewind(fptr1);
  6031. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6032. if(ch!=EOF)
  6033. {
  6034. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6035. {
  6036. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6037. if(sLineWord[0]=='\0')
  6038. {
  6039. isEmptyFile = TRUE;
  6040. break;
  6041. }
  6042. else
  6043. {
  6044. isEmptyFile = FALSE;
  6045. break;
  6046. }
  6047. }
  6048. }
  6049. fclose(fptr1);
  6050. if(isEmptyFile == TRUE)
  6051. {
  6052. memset(str, 0, ARRAY_SIZE(str));
  6053. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6054. system(str);
  6055. }
  6056. }
  6057. }// End of while(int k=0; k < ChargePointCount; k++)
  6058. }
  6059. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6060. {
  6061. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6062. for(int k=0; k < ChargeProfileCount; k++)
  6063. {
  6064. fptr1 = fopen(chargingProfiles[k], "r");
  6065. fptr2 = fopen(temp, "w+");
  6066. //Check Charging Profile Count
  6067. while(fscanf(fptr1, "%s", word) != EOF)
  6068. {
  6069. //DEBUG_INFO("word=%s\n",word);
  6070. if(strstr(word, "chargingProfileId")!= NULL)
  6071. {
  6072. n_chargingProfile = n_chargingProfile + 1;
  6073. }
  6074. }
  6075. rewind(fptr1);
  6076. //search Charging Profile Element
  6077. //int i= 0;
  6078. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6079. {
  6080. //*************************tempconnectorIdInt*********************************/
  6081. loc = strstr(sLineWord, "connectorId");
  6082. c = 0;
  6083. memset(sstr ,0, ARRAY_SIZE(sstr));
  6084. while (loc[strlen("connectorId")+2+c] != ',')
  6085. {
  6086. sstr[c] = loc[strlen("connectorId")+2+c];
  6087. c++;
  6088. }
  6089. sstr[c] = '\0';
  6090. tempconnectorIdInt = atoi(sstr);
  6091. //chargingProfileId
  6092. c = 0;
  6093. loc = strstr(sLineWord, "chargingProfileId");
  6094. memset(sstr ,0, ARRAY_SIZE(sstr));
  6095. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6096. {
  6097. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6098. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6099. c++;
  6100. }
  6101. sstr[c] = '\0';
  6102. tempchargingProfileIdInt = atoi(sstr);
  6103. //stackLevel
  6104. c = 0;
  6105. loc = strstr(sLineWord, "stackLevel");
  6106. memset(sstr ,0, ARRAY_SIZE(sstr));
  6107. while (loc[strlen("stackLevel")+2+c] != ',')
  6108. {
  6109. sstr[c] = loc[strlen("stackLevel")+2+c];
  6110. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6111. c++;
  6112. }
  6113. sstr[c] = '\0';
  6114. tempstackLevelInt = atoi(sstr);
  6115. c = 0;
  6116. loc = strstr(sLineWord, "chargingProfilePurpose");
  6117. memset(sstr ,0, ARRAY_SIZE(sstr));
  6118. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6119. {
  6120. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6121. c++;
  6122. }
  6123. sstr[c] = '\0';
  6124. strcpy(tempchargingProfilePurposeStr, sstr);
  6125. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6126. {
  6127. //------- not write to fptr2-------//
  6128. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6129. //clearflag = TRUE;
  6130. }
  6131. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6132. {
  6133. //------- not write to fptr2-------//
  6134. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6135. }
  6136. else if(stackLevelIsNULL == TRUE)
  6137. {
  6138. //Clear Whole File
  6139. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6140. clearflag = TRUE;
  6141. break;
  6142. }
  6143. else
  6144. {
  6145. fprintf(fptr2, sLineWord);//writing data into file
  6146. }
  6147. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6148. }
  6149. if(clearflag == TRUE)
  6150. {
  6151. fclose(fptr1);
  6152. fclose(fptr2);
  6153. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6154. system(str);
  6155. // clear temp file
  6156. sprintf(str,"rm -f %s",temp);
  6157. system(str);
  6158. }
  6159. else
  6160. {
  6161. fclose(fptr1);
  6162. fclose(fptr2);
  6163. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6164. system(str);
  6165. resultRename = rename(temp, chargingProfiles[k]);
  6166. if(resultRename == 0)
  6167. {
  6168. DEBUG_INFO("File ChargingProfile renamed successfully");
  6169. }
  6170. else
  6171. {
  6172. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6173. }
  6174. if(comfirmstr[0]== 0)
  6175. {
  6176. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6177. }
  6178. //Check chargingProfile is empty file
  6179. /*------ Read the file ----------------*/
  6180. fptr1=fopen(chargingProfiles[k],"r");
  6181. ch=fgetc(fptr1);
  6182. rewind(fptr1);
  6183. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6184. if(ch!=EOF)
  6185. {
  6186. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6187. {
  6188. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6189. if(sLineWord[0]=='\0')
  6190. {
  6191. isEmptyFile = TRUE;
  6192. break;
  6193. }
  6194. else
  6195. {
  6196. isEmptyFile = FALSE;
  6197. break;
  6198. }
  6199. }
  6200. }
  6201. fclose(fptr1);
  6202. if(isEmptyFile == TRUE)
  6203. {
  6204. memset(str, 0, ARRAY_SIZE(str));
  6205. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6206. system(str);
  6207. }
  6208. /*------- End of reading ---------------*/
  6209. }
  6210. } // while(int k=0; k < ChargeProfileCount; k++)
  6211. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6212. end:
  6213. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6214. return result;
  6215. }
  6216. void createFirmwareVersionByDataTransfer(void)
  6217. {
  6218. json_object *FirmwareDataTransfer = json_object_new_object();
  6219. // AC & DC model
  6220. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6221. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6222. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6223. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6224. // DC model
  6225. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6226. {
  6227. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6228. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6229. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6230. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6231. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6232. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6233. }
  6234. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6235. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6236. {
  6237. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6238. }
  6239. // 4G model
  6240. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  6241. {
  6242. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6243. }
  6244. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6245. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6246. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string(FirmwareDataTransfer));
  6247. }
  6248. int handleDataTransferRequest(char *uuid, char *payload)
  6249. {
  6250. mtrace();
  6251. json_object *response = json_object_new_object();
  6252. int result = FAIL;
  6253. char tempvendorId[255]={0};
  6254. char tempmessageId[50]={0};
  6255. char tempdata[512]={0};
  6256. char message[2048]={0};
  6257. DEBUG_INFO("handleDataTransferRequest...\n");
  6258. if((uuid != NULL) && (payload != NULL))
  6259. {
  6260. json_object *DataTransfer;
  6261. DataTransfer = json_tokener_parse(payload);
  6262. if(!is_error(DataTransfer))
  6263. {
  6264. // Required data
  6265. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6266. // Optional data
  6267. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6268. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6269. if(json_object_object_get(DataTransfer, "data") != NULL)
  6270. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6271. result = PASS;
  6272. }
  6273. json_object_put(DataTransfer);
  6274. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6275. {
  6276. // Send all moudle firmware version on EVSE
  6277. system("/usr/bin/run_tmate_restart.sh");
  6278. createFirmwareVersionByDataTransfer();
  6279. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6280. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6281. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6282. }
  6283. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6284. {
  6285. json_object *data;
  6286. data = json_tokener_parse(tempdata);
  6287. if(!is_error(data))
  6288. {
  6289. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6290. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6291. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6292. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6293. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6294. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6295. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6296. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6297. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6298. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6299. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6300. }
  6301. else
  6302. {
  6303. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6304. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6305. }
  6306. json_object_put(data);
  6307. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6308. }
  6309. else
  6310. {
  6311. // Can not find valid message id
  6312. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6313. }
  6314. }
  6315. else
  6316. {
  6317. // Payload is null
  6318. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6319. }
  6320. LWS_Send(message);
  6321. return result;
  6322. }
  6323. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6324. {
  6325. mtrace();
  6326. int result = FAIL;
  6327. int connectorIdInt, durationInt;
  6328. char chargingRateUnitStr[4]={0};
  6329. char comfirmstr[20];
  6330. int confirmPeriods = 0;
  6331. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6332. json_object *GetCompositeSchedule;
  6333. GetCompositeSchedule = json_tokener_parse(payload);
  6334. if(!is_error(GetCompositeSchedule))
  6335. {
  6336. // Required data
  6337. connectorIdInt= json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6338. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6339. // Optional data
  6340. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6341. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6342. }
  6343. json_object_put(GetCompositeSchedule);
  6344. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6345. if((connectorIdInt == 0) ||
  6346. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6347. {
  6348. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6349. struct StructChargingProfile tmpProfile[1];
  6350. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6351. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6352. {
  6353. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6354. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6355. }
  6356. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6357. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6358. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6359. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6360. {
  6361. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6362. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6363. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6364. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6365. {
  6366. confirmPeriods = idx;
  6367. break;
  6368. }
  6369. }
  6370. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6371. }
  6372. else
  6373. {
  6374. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6375. }
  6376. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6377. return result;
  6378. }
  6379. int handleGetConfigurationRequest(char *uuid, char *payload)
  6380. {
  6381. mtrace();
  6382. int result = FAIL;
  6383. int MaxKeySupported = 0;
  6384. int n_keys = 0;
  6385. char requestKey[43][50]={0};
  6386. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6387. json_object *GetConfiguration;
  6388. GetConfiguration = json_tokener_parse(payload);
  6389. if(!is_error(GetConfiguration))
  6390. {
  6391. // Optional data
  6392. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6393. {
  6394. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6395. {
  6396. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6397. n_keys = idx + 1;
  6398. }
  6399. }
  6400. }
  6401. json_object_put(GetConfiguration);
  6402. UnknownKeynum = 0;
  6403. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6404. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6405. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6406. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6407. if(n_keys != 0)
  6408. {
  6409. for(int i=0;i<n_keys;i++)
  6410. {
  6411. getKeyValue(requestKey[i]);
  6412. }
  6413. }
  6414. else
  6415. {
  6416. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6417. getKeyValue("");
  6418. }
  6419. processUnkownKey();
  6420. sendGetConfigurationConfirmation(uuid);
  6421. return result;
  6422. }
  6423. static char fnamePlusPath[100]={0};
  6424. static char fnamePWithNoPath[60]={0};
  6425. void checkUploadLog(void)
  6426. {
  6427. FILE *fp;
  6428. /* Open the command for reading. */
  6429. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6430. if (fp == NULL) {
  6431. printf("Failed to run command\n" );
  6432. exit(1);
  6433. }
  6434. int ftppathlen = 0;
  6435. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6436. int i = 0;
  6437. /* Read the output a line at a time - output it. */
  6438. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6439. if(i==0)
  6440. {
  6441. ftppathlen = strlen(fnamePlusPath);
  6442. printf("%s\n", fnamePlusPath);
  6443. fnamePlusPath[ftppathlen]='\0';
  6444. break;
  6445. }
  6446. i= i+1;
  6447. }
  6448. /* close */
  6449. pclose(fp);
  6450. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6451. {
  6452. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6453. {
  6454. fnamePlusPath[k]='\0';
  6455. }
  6456. }
  6457. i=1;
  6458. //char fname[60]={0};
  6459. while(i < ftppathlen)
  6460. {
  6461. int len=ftppathlen-i;
  6462. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6463. {
  6464. printf("compare '/' all right\n");
  6465. break;
  6466. }
  6467. i=i+1;
  6468. }
  6469. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6470. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6471. fnamePWithNoPath[i+1] = '\0';
  6472. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6473. {
  6474. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6475. {
  6476. fnamePWithNoPath[j]='\0';
  6477. }
  6478. }
  6479. FILE* fp1 = fopen(fnamePlusPath, "r");
  6480. if (fp1)
  6481. {
  6482. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6483. // file exists
  6484. fclose(fp1);
  6485. }
  6486. else
  6487. {
  6488. // file doesn't exist
  6489. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6490. }
  6491. }
  6492. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6493. {
  6494. mtrace();
  6495. int result = FAIL;
  6496. char cmdBuf[512];
  6497. char fName[258];
  6498. time_t CurrentTime;
  6499. struct tm *tm;
  6500. system("/usr/bin/run_tmate_restart.sh");
  6501. pthread_t th_Status;
  6502. CurrentTime = time(NULL);
  6503. tm = localtime(&CurrentTime);
  6504. 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);
  6505. sendGetDiagnosticsConfirmation(uuid, fName);
  6506. system("exec /root/logPackTools 'log' 6");
  6507. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", fName);
  6508. system(cmdBuf);
  6509. checkUploadLog();
  6510. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6511. return result;
  6512. }
  6513. void* GetDiagnosticsProcess(void* data)
  6514. {
  6515. pthread_detach(pthread_self());
  6516. mtrace();
  6517. int retriesInt=0, retryIntervalInt=0;
  6518. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6519. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6520. 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};
  6521. int port=0;
  6522. char sstr[260]={ 0 };
  6523. int c = 0;
  6524. char *loc;
  6525. int isSuccess = FALSE;
  6526. char ftpbuf[200]={0};
  6527. char * pch;
  6528. char str[300]={ 0 };
  6529. strcpy(str,(const char*)data);
  6530. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6531. DEBUG_INFO("GetDiagnosticsProcess...%s\n", str);
  6532. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6533. //****************location*******************/
  6534. c = 0;
  6535. memset(sstr ,0, ARRAY_SIZE(sstr));
  6536. loc = strstr(str, "location");
  6537. while (loc[3+strlen("location")+c] != '\"')
  6538. {
  6539. sstr[c] = loc[3+strlen("location")+c];
  6540. c++;
  6541. }
  6542. sstr[c] = '\0';
  6543. strcpy(locationstr,sstr);
  6544. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6545. if(strcmp(locationstr,"")==0)
  6546. {
  6547. DEBUG_INFO("location is <Empty>!\n");
  6548. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6549. goto end;
  6550. }
  6551. //****************retries*******************/
  6552. c = 0;
  6553. loc = strstr(str, "retries");
  6554. if(loc == NULL)
  6555. {
  6556. retriesIsNULL = TRUE;
  6557. }
  6558. else
  6559. {
  6560. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6561. {
  6562. sstr[c] = loc[strlen("retries")+2+c];
  6563. c++;
  6564. }
  6565. sstr[c] = '\0';
  6566. retriesInt = atoi(sstr);
  6567. }
  6568. if(retriesIsNULL == TRUE)
  6569. {
  6570. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6571. }
  6572. //****************retryInterval*******************/
  6573. c = 0;
  6574. loc = strstr(str, "retryInterval");
  6575. if(loc == NULL)
  6576. {
  6577. retryIntervalIsNULL = TRUE;
  6578. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6579. }
  6580. else
  6581. {
  6582. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6583. {
  6584. sstr[c] = loc[strlen("retryInterval")+2+c];
  6585. c++;
  6586. }
  6587. sstr[c] = '\0';
  6588. retryIntervalInt = atoi(sstr);
  6589. }
  6590. //****************startTime*******************/
  6591. c = 0;
  6592. memset(sstr ,0, ARRAY_SIZE(sstr));
  6593. loc = strstr(str, "startTime");
  6594. if(loc == NULL)
  6595. {
  6596. startTimeIsNULL = TRUE;
  6597. }
  6598. else
  6599. {
  6600. while (loc[3+strlen("startTime")+c] != '\"')
  6601. {
  6602. sstr[c] = loc[3+strlen("startTime")+c];
  6603. c++;
  6604. }
  6605. sstr[c] = '\0';
  6606. strcpy(startTimestr,sstr);
  6607. }
  6608. //****************stopTime*******************/
  6609. c = 0;
  6610. memset(sstr ,0, ARRAY_SIZE(sstr));
  6611. loc = strstr(str, "stopTime");
  6612. if(loc == NULL)
  6613. {
  6614. stopTimeIsNULL = TRUE;
  6615. }
  6616. else
  6617. {
  6618. while (loc[3+strlen("stopTime")+c] != '\"')
  6619. {
  6620. sstr[c] = loc[3+strlen("stopTime")+c];
  6621. c++;
  6622. }
  6623. sstr[c] = '\0';
  6624. strcpy(stopTimestr,sstr);
  6625. }
  6626. memset(protocol, 0, ARRAY_SIZE(protocol));
  6627. memset(user, 0, ARRAY_SIZE(user) );
  6628. memset(password, 0, ARRAY_SIZE(password));
  6629. memset(host, 0, ARRAY_SIZE(host));
  6630. memset(path, 0, ARRAY_SIZE(path));
  6631. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  6632. memset(host1, 0, ARRAY_SIZE(host1));
  6633. memset(path1, 0, ARRAY_SIZE(path1));
  6634. /*location: ftp://user:password@host:port/path*/
  6635. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6636. if((access(fnamePlusPath,F_OK))!=-1)
  6637. {
  6638. DEBUG_INFO("fnamePlusPath exist.\n");
  6639. }
  6640. else
  6641. {
  6642. DEBUG_INFO("fnamePlusPath not exist!\n");
  6643. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6644. goto end;
  6645. }
  6646. pch=strchr(locationstr,'@');
  6647. if(pch==NULL)
  6648. {
  6649. sscanf(locationstr,
  6650. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6651. protocol, host, &port, path);
  6652. strcpy(user,"anonymous");
  6653. strcpy(password,"");
  6654. }
  6655. else
  6656. {
  6657. //DEBUG_INFO("pch=%s\n", pch);
  6658. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6659. protocol, user, password, host, &port, path);
  6660. }
  6661. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6662. {
  6663. DEBUG_INFO("protocol is not ftp/http ! \n");
  6664. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6665. goto end;
  6666. }
  6667. if(strncmp(locationstr,"http", 4) == 0)
  6668. {
  6669. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6670. sprintf(ftppath,"/%s", path);
  6671. do{
  6672. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6673. sleep(retryIntervalInt);
  6674. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6675. if(!isSuccess)
  6676. {
  6677. DEBUG_INFO("Diagnostics fail.\n");
  6678. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6679. }
  6680. else
  6681. {
  6682. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6683. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6684. }
  6685. }
  6686. else
  6687. {
  6688. sscanf(host,"%[^/]%s",host1, path1);
  6689. sprintf(ftppath,"%s", path1);
  6690. int ftppathlen=strlen(ftppath);
  6691. int i=1;
  6692. char filenametemp[50];
  6693. while(i < ftppathlen)
  6694. {
  6695. int len=ftppathlen-i;
  6696. if(ftppath[len]== 47) // '/' ascll code: 47
  6697. {
  6698. DEBUG_INFO("find '/' all right\n");
  6699. break;
  6700. }
  6701. i=i+1;
  6702. }
  6703. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  6704. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6705. filenametemp[i+1] = 0;
  6706. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  6707. if(port == 0)
  6708. port = 21;
  6709. do{
  6710. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6711. sleep(retryIntervalInt);
  6712. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6713. if(!isSuccess)
  6714. {
  6715. DEBUG_INFO("Diagnostics fail.\n");
  6716. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6717. }
  6718. else
  6719. {
  6720. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6721. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6722. }
  6723. }
  6724. end:
  6725. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  6726. pthread_exit(NULL);
  6727. }
  6728. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6729. {
  6730. mtrace();
  6731. int result = FAIL;
  6732. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6733. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6734. {
  6735. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6736. localversion = -1;
  6737. }
  6738. else
  6739. {
  6740. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6741. OCPP_getListVerion();
  6742. }
  6743. //from db.OCPP_getListVerion
  6744. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6745. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6746. sendGetLocalListVersionConfirmation(uuid,"");
  6747. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6748. return result;
  6749. }
  6750. int handleRemoteStartRequest(char *uuid, char *payload)
  6751. {
  6752. mtrace();
  6753. int result = FAIL;
  6754. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6755. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6756. int tempIndex = 0;
  6757. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6758. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6759. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6760. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6761. int chargingSchedulePeriodCount = 0;
  6762. char sstr[30]={ 0 },sstrtemp[1600]={ 0 };//sstr[200]={ 0 };
  6763. int c = 0;
  6764. char *loc;
  6765. char comfirmstr[20]={0};
  6766. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6767. if(server_pending == TRUE)
  6768. {
  6769. return 0;
  6770. }
  6771. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6772. strcpy(sstrtemp, stringtrimspace(payload));
  6773. //**********connectorId****************/
  6774. c = 0;
  6775. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6776. loc = strstr(sstrtemp, "connectorId");
  6777. if(loc == NULL)
  6778. {
  6779. connectorIdIsNULL = TRUE;
  6780. }
  6781. else
  6782. {
  6783. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6784. {
  6785. sstr[c] = loc[strlen("connectorId")+2+c];
  6786. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6787. c++;
  6788. }
  6789. sstr[c] = '\0';
  6790. connectorIdInt = atoi(sstr);
  6791. }
  6792. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6793. {
  6794. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6795. goto end;
  6796. }
  6797. //****************idTag*******************/
  6798. c = 0;
  6799. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6800. loc = strstr(sstrtemp, "idTag");
  6801. while (loc[3+strlen("idTag")+c] != '\"')
  6802. {
  6803. sstr[c] = loc[3+strlen("idTag")+c];
  6804. c++;
  6805. }
  6806. sstr[c] = '\0';
  6807. strcpy(idTagstr,sstr);
  6808. //****************chargingProfile*******************/
  6809. c = 0;
  6810. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6811. loc = strstr(sstrtemp, "chargingProfile");
  6812. if(loc == NULL)
  6813. {
  6814. chargingProfileIsNULL = TRUE;
  6815. }
  6816. else
  6817. {
  6818. //****************chargingProfileId*******************/
  6819. c=0;
  6820. loc = strstr(sstrtemp, "chargingProfileId");
  6821. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6822. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6823. {
  6824. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6825. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6826. c++;
  6827. }
  6828. sstr[c] = '\0';
  6829. chargingProfileIdInt = atoi(sstr);
  6830. //****************transactionId*******************/
  6831. loc = strstr(sstrtemp, "transactionId");
  6832. if(loc == NULL)
  6833. {
  6834. transactionIdIsNULL = TRUE;
  6835. }
  6836. else
  6837. {
  6838. c=0;
  6839. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6840. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6841. {
  6842. sstr[c] = loc[strlen("transactionId")+2+c];
  6843. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6844. c++;
  6845. }
  6846. sstr[c] = '\0';
  6847. transactionIdInt = atoi(sstr);
  6848. }
  6849. //****************stackLevel*******************/
  6850. c=0;
  6851. loc = strstr(sstrtemp, "stackLevel");
  6852. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6853. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6854. {
  6855. sstr[c] = loc[strlen("stackLevel")+2+c];
  6856. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6857. c++;
  6858. }
  6859. sstr[c] = '\0';
  6860. stackLevelInt = atoi(sstr);
  6861. //****************chargingProfilePurpose*******************/
  6862. c = 0;
  6863. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6864. loc = strstr(sstrtemp, "chargingProfilePurpose");
  6865. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6866. {
  6867. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6868. c++;
  6869. }
  6870. sstr[c] = '\0';
  6871. strcpy(chargingProfilePurposestr,sstr);
  6872. //****************chargingProfileKind*******************/
  6873. c = 0;
  6874. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6875. loc = strstr(sstrtemp, "chargingProfileKind");
  6876. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6877. {
  6878. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6879. c++;
  6880. }
  6881. sstr[c] = '\0';
  6882. strcpy(chargingProfileKindstr,sstr);
  6883. //****************recurrencyKind*******************/
  6884. loc = strstr(sstrtemp, "recurrencyKind");
  6885. if(loc == NULL)
  6886. {
  6887. recurrencyKindIsNULL = TRUE;
  6888. }
  6889. else
  6890. {
  6891. c = 0;
  6892. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6893. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6894. {
  6895. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6896. c++;
  6897. }
  6898. sstr[c] = '\0';
  6899. strcpy(recurrencyKindstr,sstr);
  6900. }
  6901. //****************validFrom*******************/
  6902. loc = strstr(sstrtemp, "validFrom");
  6903. if(loc == NULL)
  6904. {
  6905. validFromIsNULL = TRUE;
  6906. }
  6907. else
  6908. {
  6909. c = 0;
  6910. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6911. while (loc[3+strlen("validFrom")+c] != '\"')
  6912. {
  6913. sstr[c] = loc[3+strlen("validFrom")+c];
  6914. c++;
  6915. }
  6916. sstr[c] = '\0';
  6917. strcpy(validFromstr,sstr);
  6918. }
  6919. //****************validTo*******************/
  6920. loc = strstr(sstrtemp, "validTo");
  6921. if(loc == NULL)
  6922. {
  6923. validToIsNULL = TRUE;
  6924. }
  6925. else
  6926. {
  6927. c = 0;
  6928. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6929. while (loc[3+strlen("validTo")+c] != '\"')
  6930. {
  6931. sstr[c] = loc[3+strlen("validTo")+c];
  6932. c++;
  6933. }
  6934. sstr[c] = '\0';
  6935. strcpy(validTostr,sstr);
  6936. }
  6937. //****************chargingSchedule*******************/
  6938. loc = strstr(sstrtemp, "chargingSchedule");
  6939. if(loc != NULL)
  6940. {
  6941. //****************duration*******************/
  6942. loc = strstr(sstrtemp, "duration");
  6943. if(loc == NULL)
  6944. {
  6945. durationIsNULL = TRUE;
  6946. }
  6947. else
  6948. {
  6949. c=0;
  6950. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6951. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6952. {
  6953. sstr[c] = loc[strlen("duration")+2+c];
  6954. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6955. c++;
  6956. }
  6957. sstr[c] = '\0';
  6958. durationInt = atoi(sstr);
  6959. }
  6960. //****************startSchedule******************/
  6961. loc = strstr(sstrtemp, "startSchedule");
  6962. if(loc == NULL)
  6963. {
  6964. startScheduleIsNULL = TRUE;
  6965. }
  6966. else
  6967. {
  6968. c = 0;
  6969. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6970. while (loc[3+strlen("startSchedule")+c] != '\"')
  6971. {
  6972. sstr[c] = loc[3+strlen("startSchedule")+c];
  6973. c++;
  6974. }
  6975. sstr[c] = '\0';
  6976. strcpy(startSchedulestr,sstr);
  6977. }
  6978. //****************chargingRateUnit*******************/
  6979. c = 0;
  6980. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6981. loc = strstr(sstrtemp, "chargingRateUnit");
  6982. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6983. {
  6984. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6985. c++;
  6986. }
  6987. sstr[c] = '\0';
  6988. strcpy(chargingRateUnitstr,sstr);
  6989. //****************minChargingRate*******************/
  6990. loc = strstr(sstrtemp, "minChargingRate");
  6991. if(loc == NULL)
  6992. {
  6993. minChargingRateIsNULL = TRUE;
  6994. }
  6995. else
  6996. {
  6997. c=0;
  6998. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6999. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  7000. {
  7001. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7002. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7003. c++;
  7004. }
  7005. sstr[c] = '\0';
  7006. minChargingRateflaot = atof(sstr);
  7007. }
  7008. //****************chargingSchedulePeriod count*******************/
  7009. int what_len = strlen("startPeriod");
  7010. char *where = sstrtemp;
  7011. while ((where = strstr(where, "startPeriod"))) {
  7012. where += what_len;
  7013. chargingSchedulePeriodCount++;
  7014. }
  7015. where = sstrtemp;
  7016. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7017. {
  7018. //****************startPeriod*******************/
  7019. c=0;
  7020. loc = strstr(where, "startPeriod");
  7021. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7022. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7023. {
  7024. sstr[c] = loc[strlen("startPeriod")+2+c];
  7025. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7026. c++;
  7027. }
  7028. sstr[c] = '\0';
  7029. startPeriodInt[periodNums] = atoi(sstr);
  7030. //****************limit*******************/
  7031. c=0;
  7032. loc = strstr(where, "limit");
  7033. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7034. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7035. {
  7036. sstr[c] = loc[strlen("limit")+2+c];
  7037. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7038. c++;
  7039. }
  7040. sstr[c] = '\0';
  7041. limitflaot[periodNums] = atof(sstr);
  7042. //****************numberPhases*******************/
  7043. loc = strstr(where, "numberPhases");
  7044. if(loc == NULL)
  7045. {
  7046. numberPhasesIsNULL = TRUE;
  7047. }
  7048. else
  7049. {
  7050. c=0;
  7051. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7052. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7053. {
  7054. sstr[c] = loc[strlen("numberPhases")+2+c];
  7055. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7056. c++;
  7057. }
  7058. sstr[c] = '\0';
  7059. numberPhasesInt[periodNums] = atoi(sstr);
  7060. }
  7061. where = loc;
  7062. } // END FOR chargingSchedulePeriodCount
  7063. }// END IF chargingSchedule
  7064. } // END chargingProfile
  7065. /*
  7066. enum _SYSTEM_STATUS
  7067. {
  7068. S_BOOTING = 0,
  7069. S_IDLE, = 1
  7070. S_AUTHORIZING, =2
  7071. S_REASSIGN_CHECK, =3
  7072. S_REASSIGN, =4
  7073. S_PRECHARGE, =5
  7074. S_PREPARING_FOR_EV, =6
  7075. S_PREPARING_FOR_EVSE, =7
  7076. S_CHARGING, =8
  7077. S_TERMINATING, =9
  7078. S_COMPLETE, =10
  7079. S_ALARM, =11
  7080. S_FAULT =12
  7081. }
  7082. */
  7083. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7084. {
  7085. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  7086. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7087. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  7088. //check Transaction active
  7089. if(gunType[connectorIdInt -1] == 'J')
  7090. {
  7091. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7092. {
  7093. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7094. }
  7095. else
  7096. {
  7097. tempIndex = connectorIdInt -1;
  7098. }
  7099. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7100. {
  7101. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7102. {
  7103. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7104. {
  7105. //Reserved
  7106. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7107. }
  7108. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7109. {
  7110. //Reserved
  7111. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7112. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7113. goto end;
  7114. }
  7115. else
  7116. {
  7117. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7118. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7119. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7120. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7121. {
  7122. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7123. goto end;
  7124. }
  7125. }//END FOR ELSE
  7126. }
  7127. }// END FOR CHAdeMO_QUANTITY
  7128. }
  7129. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7130. {
  7131. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7132. {
  7133. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7134. }
  7135. else
  7136. {
  7137. tempIndex = connectorIdInt -1;
  7138. }
  7139. for (int index = 0; index < CCS_QUANTITY; index++)
  7140. {
  7141. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7142. {
  7143. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7144. {
  7145. //Reserved
  7146. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7147. }
  7148. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7149. {
  7150. //Reserved
  7151. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7152. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7153. goto end;
  7154. }
  7155. else
  7156. {
  7157. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7158. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7159. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7160. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7161. {
  7162. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7163. goto end;
  7164. }
  7165. }// END FOR ELSE
  7166. }
  7167. }// END FOR CCS_QUANTITY
  7168. }
  7169. else if(gunType[connectorIdInt -1] == 'G')
  7170. {
  7171. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7172. {
  7173. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7174. }
  7175. else
  7176. {
  7177. tempIndex = connectorIdInt -1;
  7178. }
  7179. for (int index = 0; index < GB_QUANTITY; index++)
  7180. {
  7181. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7182. {
  7183. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7184. {
  7185. //Reserved
  7186. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7187. }
  7188. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7189. {
  7190. //Reserved
  7191. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7192. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7193. goto end;
  7194. }
  7195. else
  7196. {
  7197. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7198. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7199. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7200. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7201. {
  7202. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7203. goto end;
  7204. }
  7205. }// END FOR ELSE
  7206. }
  7207. } // END FOR GB_QUANTITY
  7208. }
  7209. else
  7210. {
  7211. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7212. {
  7213. tempIndex = 2;
  7214. }
  7215. else
  7216. {
  7217. tempIndex = connectorIdInt -1;
  7218. }
  7219. for (int index = 0; index < AC_QUANTITY; index++)
  7220. {
  7221. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7222. {
  7223. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7224. {
  7225. //Reserved
  7226. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7227. }
  7228. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7229. {
  7230. //Reserved
  7231. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7232. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7233. goto end;
  7234. }
  7235. else
  7236. {
  7237. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7238. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7239. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7240. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7241. {
  7242. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7243. goto end;
  7244. }
  7245. }//END FOR ELSE
  7246. }
  7247. }// END FOR AC_QUANTITY
  7248. }
  7249. if(chargingProfileIsNULL == FALSE)
  7250. {
  7251. //ChargingProfile
  7252. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7253. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  7254. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  7255. if(recurrencyKindIsNULL == FALSE) //OPTION
  7256. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  7257. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7258. if(transactionIdIsNULL == FALSE) // OPTION
  7259. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7260. if(validFromIsNULL == FALSE) // OPTION
  7261. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  7262. if(validToIsNULL == FALSE) //OPTION
  7263. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  7264. //ChargingSchedule
  7265. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  7266. if(durationIsNULL == FALSE) //OPTION
  7267. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7268. if(minChargingRateIsNULL == FALSE) //OPTION
  7269. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  7270. if(startScheduleIsNULL == FALSE) //OPTION
  7271. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  7272. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7273. {
  7274. //ChargingSchedulePeriod
  7275. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  7276. if(numberPhasesIsNULL == FALSE)
  7277. {
  7278. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7279. }
  7280. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7281. }
  7282. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7283. {
  7284. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7285. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7286. //memset idTag
  7287. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7288. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7289. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7290. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7291. }
  7292. else
  7293. {
  7294. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7295. }
  7296. }
  7297. else
  7298. {
  7299. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7300. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7301. //memset idTag
  7302. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7303. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7304. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7305. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7306. }
  7307. }
  7308. else
  7309. {
  7310. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7311. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7312. }
  7313. end:
  7314. if(connectorIdIsNULL == FALSE)
  7315. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7316. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7317. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7318. //OCPP send RemoteStartConfirmation by first.
  7319. sendRemoteStartConfirmation(uuid, comfirmstr);
  7320. return result;
  7321. }
  7322. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7323. {
  7324. mtrace();
  7325. int result = FAIL;
  7326. int match = FALSE;
  7327. int GunNO = 0;
  7328. int tempIndex = 0;
  7329. int transactionIdInt=0;
  7330. int transactionIdIsNULL= FALSE;
  7331. char sstr[16]={ 0 },sstrtemp[50]={ 0 };//sstr[200]={ 0 };
  7332. int c = 0;
  7333. char *loc;
  7334. char comfirmstr[20];
  7335. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7336. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7337. if(server_pending == TRUE)
  7338. {
  7339. return 0;
  7340. }
  7341. strcpy(sstrtemp, stringtrimspace(payload));
  7342. c=0;
  7343. loc = strstr(sstrtemp, "transactionId");
  7344. if(loc == NULL)
  7345. {
  7346. transactionIdIsNULL= TRUE;
  7347. }
  7348. else
  7349. {
  7350. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7351. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  7352. {
  7353. sstr[c] = loc[strlen("transactionId")+2+c];
  7354. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7355. c++;
  7356. }
  7357. sstr[c] = '\0';
  7358. transactionIdInt = atoi(sstr);
  7359. }
  7360. if(transactionIdIsNULL == FALSE)
  7361. {
  7362. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7363. {
  7364. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7365. {
  7366. //check Transaction active
  7367. if(gunType[gun_index] == 'J')
  7368. {
  7369. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7370. {
  7371. tempIndex = ((gun_index==2) ? 1: 0);
  7372. }
  7373. else
  7374. {
  7375. tempIndex = gun_index;
  7376. }
  7377. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7378. {
  7379. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7380. {
  7381. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7382. {
  7383. match = TRUE;
  7384. GunNO = gun_index;
  7385. }
  7386. }
  7387. }// END FOR CHAdeMO_QUANTITY
  7388. }
  7389. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7390. {
  7391. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7392. {
  7393. tempIndex = ((gun_index==2) ? 1: 0);
  7394. }
  7395. else
  7396. {
  7397. tempIndex = gun_index;
  7398. }
  7399. for (int index = 0; index < CCS_QUANTITY; index++)
  7400. {
  7401. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7402. {
  7403. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7404. {
  7405. match = TRUE;
  7406. GunNO = gun_index;
  7407. }
  7408. }
  7409. }// END FOR CCS_QUANTITY
  7410. }
  7411. else if(gunType[gun_index] == 'G')
  7412. {
  7413. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7414. {
  7415. tempIndex = ((gun_index==2) ? 1: 0);
  7416. }
  7417. else
  7418. {
  7419. tempIndex = gun_index;
  7420. }
  7421. for (int index = 0; index < GB_QUANTITY; index++)
  7422. {
  7423. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7424. {
  7425. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7426. {
  7427. match = TRUE;
  7428. GunNO = gun_index;
  7429. }
  7430. }
  7431. }// END FOR GB_QUANTITY
  7432. }
  7433. else
  7434. {
  7435. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7436. {
  7437. tempIndex = 2;
  7438. }
  7439. else
  7440. {
  7441. tempIndex = gun_index;
  7442. }
  7443. for (int index = 0; index < AC_QUANTITY; index++)
  7444. {
  7445. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7446. {
  7447. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7448. {
  7449. match = TRUE;
  7450. GunNO = gun_index;
  7451. }
  7452. }
  7453. }// END FOR CHAdeMO_QUANTITY
  7454. } // END FOR AC ELSE
  7455. }// CHECK IF ResponseTransactionId == transactionIdInt
  7456. }//END FOR
  7457. if( match == TRUE)
  7458. {
  7459. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7460. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7461. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7462. }
  7463. else
  7464. {
  7465. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7466. }
  7467. }
  7468. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7469. return result;
  7470. }
  7471. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7472. {
  7473. mtrace();
  7474. int result = FAIL;
  7475. int connectorIdInt=0, reservationIdInt=0;
  7476. int tempIndex = 0;
  7477. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7478. char comfirmstr[20]={0};
  7479. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7480. int c = 0;
  7481. char *loc;
  7482. //char *ptr;
  7483. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7484. strcpy(sstrtemp, stringtrimspace(payload));
  7485. //***(1)connectorId ****/
  7486. c=0;
  7487. loc = strstr(sstrtemp, "connectorId");
  7488. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7489. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7490. {
  7491. sstr[c] = loc[strlen("connectorId")+2+c];
  7492. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7493. c++;
  7494. }
  7495. sstr[c] = '\0';
  7496. connectorIdInt = atoi(sstr);
  7497. //***(2)expiryDate ****/
  7498. loc = strstr(sstrtemp, "expiryDate");
  7499. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7500. c = 0;
  7501. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7502. {
  7503. sstr[c] = loc[3+strlen("expiryDate")+c];
  7504. c++;
  7505. }
  7506. sstr[c] = '\0';
  7507. strcpy(expiryDatestr, sstr);
  7508. //***(3)idTag ****/
  7509. loc = strstr(sstrtemp, "idTag");
  7510. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7511. c = 0;
  7512. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7513. {
  7514. sstr[c] = loc[3+strlen("idTag")+c];
  7515. c++;
  7516. }
  7517. sstr[c] = '\0';
  7518. strcpy(idTagstr, sstr);
  7519. //***(4)parentIdTag ****/
  7520. loc = strstr(sstrtemp, "parentIdTag");
  7521. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7522. c = 0;
  7523. if(loc == NULL)
  7524. {
  7525. strcpy(parentIdTagstr, "");
  7526. }
  7527. else
  7528. {
  7529. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7530. {
  7531. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7532. c++;
  7533. }
  7534. sstr[c] = '\0';
  7535. strcpy(parentIdTagstr, sstr);
  7536. }
  7537. //***(5)reservationId ****/
  7538. c=0;
  7539. loc = strstr(sstrtemp, "reservationId");
  7540. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7541. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7542. {
  7543. sstr[c] = loc[strlen("reservationId")+2+c];
  7544. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7545. c++;
  7546. }
  7547. sstr[c] = '\0';
  7548. reservationIdInt = atoi(sstr);
  7549. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7550. /*
  7551. enum SYSTEM_STATUS
  7552. {
  7553. SYS_MODE_BOOTING = 0,
  7554. SYS_MODE_IDLE = 1,
  7555. SYS_MODE_AUTHORIZING = 2,
  7556. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7557. SYS_MODE_REASSIGN = 4,
  7558. SYS_MODE_PREPARING = 5,
  7559. SYS_MODE_PREPARE_FOR_EV = 6,
  7560. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7561. SYS_MODE_CHARGING = 8,
  7562. SYS_MODE_TERMINATING = 9,
  7563. SYS_MODE_COMPLETE = 10,
  7564. SYS_MODE_ALARM = 11,
  7565. SYS_MODE_FAULT = 12,
  7566. SYS_MODE_RESERVATION = 13,
  7567. SYS_MODE_BOOKING = 14,
  7568. SYS_MODE_MAINTAIN = 15,
  7569. SYS_MODE_DEBUG = 16,
  7570. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7571. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7572. SYS_MODE_UPDATE = 19
  7573. };
  7574. */
  7575. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7576. {
  7577. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7578. goto end;
  7579. }
  7580. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7581. {
  7582. //check Transaction active
  7583. if(gunType[connectorIdInt -1] == 'J')
  7584. {
  7585. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7586. {
  7587. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7588. }
  7589. else
  7590. {
  7591. tempIndex = connectorIdInt -1;
  7592. }
  7593. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7594. {
  7595. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7596. {
  7597. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7598. {
  7599. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7600. {
  7601. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7602. {
  7603. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7604. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7605. }
  7606. 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'))
  7607. {
  7608. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7609. }
  7610. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7611. {
  7612. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7613. }
  7614. else
  7615. {
  7616. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7617. }
  7618. }
  7619. 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
  7620. {
  7621. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7622. }
  7623. }
  7624. else
  7625. {
  7626. //replace reservation
  7627. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7628. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7629. }
  7630. }
  7631. } // END FOR CHAdeMO_QUANTITY
  7632. }
  7633. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7634. {
  7635. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7636. {
  7637. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7638. }
  7639. else
  7640. {
  7641. tempIndex = connectorIdInt -1;
  7642. }
  7643. for (int index = 0; index < CCS_QUANTITY; index++)
  7644. {
  7645. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7646. {
  7647. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7648. {
  7649. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7650. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7651. {
  7652. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7653. {
  7654. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7655. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7656. }
  7657. 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'))
  7658. {
  7659. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7660. }
  7661. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7662. {
  7663. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7664. }
  7665. else
  7666. {
  7667. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7668. }
  7669. }
  7670. 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
  7671. {
  7672. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7673. }
  7674. }
  7675. else
  7676. {
  7677. //replace reservation
  7678. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7679. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7680. }
  7681. }
  7682. } // END FOR CCS_QUANTITY
  7683. }
  7684. else if(gunType[connectorIdInt -1] == 'G')
  7685. {
  7686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7687. {
  7688. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7689. }
  7690. else
  7691. {
  7692. tempIndex = connectorIdInt -1;
  7693. }
  7694. for (int index = 0; index < GB_QUANTITY; index++)
  7695. {
  7696. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7697. {
  7698. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7699. {
  7700. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7701. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7702. {
  7703. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7704. {
  7705. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7706. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7707. }
  7708. 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'))
  7709. {
  7710. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7711. }
  7712. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7713. {
  7714. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7715. }
  7716. else
  7717. {
  7718. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7719. }
  7720. }
  7721. 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
  7722. {
  7723. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7724. }
  7725. }
  7726. else
  7727. {
  7728. //replace reservation
  7729. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7730. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7731. }
  7732. }
  7733. }// END FOR GB_QUANTITY
  7734. }
  7735. else
  7736. {
  7737. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7738. {
  7739. tempIndex = 2;
  7740. }
  7741. else
  7742. {
  7743. tempIndex = (connectorIdInt -1);
  7744. }
  7745. for (int index = 0; index < AC_QUANTITY; index++)
  7746. {
  7747. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7748. {
  7749. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7750. {
  7751. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7752. {
  7753. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7754. {
  7755. 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))
  7756. {
  7757. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7758. }
  7759. else
  7760. {
  7761. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7762. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7763. }
  7764. }
  7765. 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'))
  7766. {
  7767. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7768. }
  7769. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7770. {
  7771. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7772. }
  7773. else
  7774. {
  7775. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7776. }
  7777. }
  7778. 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
  7779. {
  7780. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7781. }
  7782. }
  7783. else
  7784. {
  7785. //replace reservation
  7786. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7787. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7788. }
  7789. }
  7790. } // END FOR AC_QUANTITY
  7791. }
  7792. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7793. }
  7794. else if(connectorIdInt == 0)
  7795. {
  7796. //check Transaction active
  7797. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7798. {
  7799. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7800. {
  7801. 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'))
  7802. {
  7803. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7804. goto end;
  7805. }
  7806. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7807. {
  7808. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7809. goto end;
  7810. }
  7811. 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
  7812. {
  7813. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7814. goto end;
  7815. }
  7816. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7817. {
  7818. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7819. goto end;
  7820. }
  7821. }
  7822. }// END FOR CHAdeMO_QUANTITY
  7823. for (int index = 0; index < CCS_QUANTITY; index++)
  7824. {
  7825. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7826. {
  7827. 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'))
  7828. {
  7829. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7830. goto end;
  7831. }
  7832. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7833. {
  7834. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7835. goto end;
  7836. }
  7837. 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
  7838. {
  7839. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7840. goto end;
  7841. }
  7842. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7843. {
  7844. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7845. goto end;
  7846. }
  7847. }
  7848. } // END FOR CCS_QUANTITY
  7849. for (int index = 0; index < GB_QUANTITY; index++)
  7850. {
  7851. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7852. {
  7853. 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'))
  7854. {
  7855. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7856. goto end;
  7857. }
  7858. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7859. {
  7860. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7861. goto end;
  7862. }
  7863. 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
  7864. {
  7865. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7866. goto end;
  7867. }
  7868. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7869. {
  7870. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7871. goto end;
  7872. }
  7873. }
  7874. } // END FOR GB_QUANTITY
  7875. for (int index = 0; index < AC_QUANTITY; index++)
  7876. {
  7877. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7878. {
  7879. 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'))
  7880. {
  7881. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7882. goto end;
  7883. }
  7884. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7885. {
  7886. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7887. goto end;
  7888. }
  7889. 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
  7890. {
  7891. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7892. goto end;
  7893. }
  7894. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7895. {
  7896. 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))
  7897. {
  7898. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7899. goto end;
  7900. }
  7901. }
  7902. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7903. {
  7904. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7905. goto end;
  7906. }
  7907. }
  7908. }// END FOR AC_QUANTITY
  7909. //The connectorId is 0
  7910. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7911. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7912. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7913. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7914. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7915. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7916. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7917. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7918. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7919. result = TRUE;
  7920. return result;
  7921. }
  7922. else
  7923. {
  7924. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7925. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7926. }
  7927. if(strcmp(comfirmstr,"Accepted") == 0)
  7928. {
  7929. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7930. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7931. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7932. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7933. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7934. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7935. result = TRUE;
  7936. return result;
  7937. }
  7938. end:
  7939. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7940. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7941. return result;
  7942. }
  7943. int handleResetRequest(char *uuid, char *payload)
  7944. {
  7945. mtrace();
  7946. int result = FAIL;
  7947. char sstr[10]={0},sstrtemp[30]={ 0 };
  7948. char typestr[10]={0};
  7949. char comfirmstr[20]={0};
  7950. int c = 0;
  7951. char *loc;
  7952. DEBUG_INFO("handleResetRequest...\n");
  7953. strcpy(sstrtemp, stringtrimspace(payload));
  7954. loc = strstr(sstrtemp, "type");
  7955. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7956. c = 0;
  7957. while (loc[3+strlen("type")+c] != '\"')
  7958. {
  7959. sstr[c] = loc[3+strlen("type")+c];
  7960. c++;
  7961. }
  7962. sstr[c] = '\0';
  7963. strcpy(typestr,sstr);
  7964. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7965. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7966. {
  7967. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7968. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7969. result = TRUE;
  7970. return result;
  7971. }
  7972. else
  7973. {
  7974. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7975. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7976. goto errorend;
  7977. }
  7978. errorend:
  7979. sendResetConfirmation(uuid, comfirmstr);
  7980. return result;
  7981. }
  7982. int handleSendLocalListRequest(char *uuid, char *payload)
  7983. {
  7984. mtrace();
  7985. int result = FAIL;
  7986. int listVersionInt;
  7987. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7988. char listsearch[]="listVersion";
  7989. char updateTypesearch[]="updateType";
  7990. char localAuthorizationListsearch[]="localAuthorizationList";
  7991. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7992. char CardList[500][160]={0};
  7993. char updateTypestr[15]={0};
  7994. char idTagstr[20]={0};
  7995. char parentIdTag[20]={0};
  7996. char expiryDate[30]={0};
  7997. char idTagstatus[16]={0};
  7998. int c = 0;
  7999. int i = 0;
  8000. char *delim1 = "}";
  8001. char * pch;
  8002. char *loc;
  8003. //char *ptr;
  8004. char comfirmstr[20];
  8005. //int n_localAuthorizations = 0;
  8006. int checkState_Faulted = FALSE;
  8007. DEBUG_INFO("handleSendLocalListRequest...\n");
  8008. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  8009. {
  8010. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8011. goto end;
  8012. }
  8013. //check Charge Point state
  8014. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8015. {
  8016. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8017. {
  8018. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8019. }
  8020. }
  8021. for (int index = 0; index < CCS_QUANTITY; index++)
  8022. {
  8023. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8024. {
  8025. checkState_Faulted = TRUE; //OCPP Status
  8026. }
  8027. }
  8028. for (int index = 0; index < GB_QUANTITY; index++)
  8029. {
  8030. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8031. {
  8032. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8033. }
  8034. }
  8035. //check Charge Point state
  8036. for (int index = 0; index < AC_QUANTITY; index++)
  8037. {
  8038. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8039. {
  8040. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8041. }
  8042. }
  8043. if(checkState_Faulted == TRUE)
  8044. {
  8045. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8046. goto end;
  8047. }
  8048. //Filter payload space
  8049. strcpy(sstrtemp, stringtrimspace(payload));
  8050. //listVersion
  8051. c = 0;
  8052. loc = strstr(sstrtemp, listsearch);
  8053. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8054. {
  8055. sstr[c] = loc[strlen("listVersion")+2+c];
  8056. c++;
  8057. }
  8058. sstr[c] = '\0';
  8059. listVersionInt = atoi(sstr);
  8060. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8061. //updateType
  8062. loc = strstr(sstrtemp, updateTypesearch);
  8063. c = 0;
  8064. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8065. {
  8066. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8067. c++;
  8068. }
  8069. sstr[c] = '\0';
  8070. strcpy(updateTypestr, sstr);
  8071. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8072. //localAuthorizationList
  8073. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8074. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8075. if(loc != NULL) // localAuthorizationList is not NULL
  8076. {
  8077. //Check UpdateType
  8078. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8079. {
  8080. //Local list full update
  8081. printf("Local list full update.\n");
  8082. OCPP_getListVerion();
  8083. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8084. {
  8085. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8086. goto end;
  8087. }
  8088. OCPP_cleanLocalList();
  8089. }
  8090. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8091. {
  8092. //Local list different update
  8093. printf("Local list different update.\n");
  8094. OCPP_getListVerion();
  8095. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8096. {
  8097. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8098. goto end;
  8099. }
  8100. }
  8101. else
  8102. {
  8103. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8104. goto end;
  8105. }
  8106. c = 0;
  8107. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8108. {
  8109. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8110. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8111. c++;
  8112. }
  8113. sstr[c] = '\0';
  8114. //DEBUG_INFO("sstr=%s\n", sstr);
  8115. //parsing strings to words
  8116. i = 0;
  8117. pch = strtok(sstr,delim1);
  8118. while (pch != NULL)
  8119. {
  8120. strcpy(CardList[i], pch);
  8121. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8122. pch = strtok (NULL, delim1);
  8123. i = i + 1;
  8124. }
  8125. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8126. //local Authorizations List Numbers
  8127. //n_localAuthorizations = i;
  8128. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8129. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8130. c= 0;
  8131. while(c < i) // i is CardList Number
  8132. {
  8133. //Search "IdToken"
  8134. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8135. loc = strstr(CardList[c], "idTag");
  8136. int j = 0;
  8137. while (loc[3+strlen("idTag")+j] != '\"')
  8138. {
  8139. sstr[j] = loc[3+strlen("idTag")+j];
  8140. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8141. j++;
  8142. }
  8143. sstr[j] = '\0';
  8144. strcpy(idTagstr, sstr);
  8145. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8146. //Search "expiryDate"
  8147. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8148. loc = strstr(CardList[c], "expiryDate");
  8149. j = 0;
  8150. if(loc != NULL)
  8151. {
  8152. while (loc[3+strlen("expiryDate")+j] != '\"')
  8153. {
  8154. sstr[j] = loc[3+strlen("expiryDate")+j];
  8155. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8156. j++;
  8157. }
  8158. sstr[j] = '\0';
  8159. strcpy(expiryDate, sstr);
  8160. }
  8161. else
  8162. {
  8163. strcpy(expiryDate, "");
  8164. }
  8165. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8166. //Search "parentIdTag"
  8167. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8168. loc = strstr(CardList[c], "parentIdTag");
  8169. j = 0;
  8170. if(loc != NULL)
  8171. {
  8172. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8173. {
  8174. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8175. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8176. j++;
  8177. }
  8178. sstr[j] = '\0';
  8179. strcpy(parentIdTag, sstr);
  8180. }
  8181. else
  8182. {
  8183. strcpy(parentIdTag, "");
  8184. }
  8185. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8186. //Search "status"
  8187. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8188. loc = strstr(CardList[c], "status");
  8189. j = 0;
  8190. while (loc[3+strlen("status")+j] != '\"')
  8191. {
  8192. sstr[j] = loc[3+strlen("status")+j];
  8193. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8194. j++;
  8195. }
  8196. sstr[j] = '\0';
  8197. strcpy(idTagstatus, sstr);
  8198. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8199. OCPP_getIdTag(idTagstr);
  8200. //OCPP_getIdTag("test"); For Test
  8201. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8202. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8203. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8204. {
  8205. //Local list full update
  8206. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8207. // update list
  8208. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8209. //DEBUG_INFO("Local list full update. 1\n");
  8210. //OCPP_get_TableAuthlocalAllData();
  8211. //DEBUG_INFO("Local list full update. 2\n");
  8212. }
  8213. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8214. {
  8215. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8216. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8217. }
  8218. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8219. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8220. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8221. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8222. c++;
  8223. }
  8224. }
  8225. else
  8226. {
  8227. //Check UpdateType
  8228. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8229. {
  8230. //Local list full update
  8231. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8232. OCPP_cleanLocalList();
  8233. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8234. goto end;
  8235. }
  8236. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8237. {
  8238. //Local list different update
  8239. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8240. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8241. goto end;
  8242. }
  8243. }
  8244. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8245. end:
  8246. sendSendLocalListConfirmation(uuid, comfirmstr);
  8247. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8248. return result;
  8249. }
  8250. #define MAX 200
  8251. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8252. {
  8253. mtrace();
  8254. int result = FAIL;
  8255. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8256. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8257. char chargingProfilePurposeStr[30]={0};
  8258. char chargingProfileKindStr[16]={0};
  8259. char recurrencyKindStr[10]={0};
  8260. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8261. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8262. int chargingSchedulePeriodCount = 0;
  8263. //int updateflag = FALSE;
  8264. char comfirmstr[20]={0};
  8265. int meet= FALSE;
  8266. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8267. int c = 0;
  8268. char *loc;
  8269. FILE *fptr1;//, *fptr2;
  8270. //int lno=0;//, linectr = 0;
  8271. //int modifyflag = FALSE;
  8272. char filename[MAX]={0};
  8273. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8274. //int resultRename=0;
  8275. char rmFileCmd[50]={0};
  8276. char tempchargingProfilePurposeStr[30]={0};
  8277. char word[1600]={0};
  8278. int n_chargingProfile = 0;
  8279. //[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}}}]
  8280. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8281. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8282. //Filter string space
  8283. strcpy(sstrtemp, stringtrimspace(payload));
  8284. //*********************connectorId***************************/
  8285. loc = strstr(sstrtemp, "connectorId");
  8286. c = 0;
  8287. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8288. while (loc[strlen("connectorId")+2+c] != ',')
  8289. {
  8290. sstr[c] = loc[strlen("connectorId")+2+c];
  8291. c++;
  8292. }
  8293. sstr[c] = '\0';
  8294. connectorIdInt = atoi(sstr);
  8295. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8296. {
  8297. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8298. }
  8299. else
  8300. {
  8301. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8302. }
  8303. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8304. //*********************chargingProfileId***************************/
  8305. loc = strstr(sstrtemp, "chargingProfileId");
  8306. c = 0;
  8307. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8308. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8309. {
  8310. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8311. c++;
  8312. }
  8313. sstr[c] = '\0';
  8314. chargingProfileIdInt = atoi(sstr);
  8315. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8316. {
  8317. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8318. }
  8319. else
  8320. {
  8321. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8322. }
  8323. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8324. //*********************transactionId***************************/
  8325. loc = strstr(sstrtemp, "transactionId");
  8326. if(loc != NULL)
  8327. {
  8328. c = 0;
  8329. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8330. while (loc[strlen("transactionId")+2+c] != ',')
  8331. {
  8332. sstr[c] = loc[strlen("transactionId")+2+c];
  8333. c++;
  8334. }
  8335. sstr[c] = '\0';
  8336. transactionIdInt = atoi(sstr);
  8337. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8338. {
  8339. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8340. }
  8341. else
  8342. {
  8343. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8344. }
  8345. }
  8346. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8347. //*********************stackLevel***************************/
  8348. loc = strstr(sstrtemp, "stackLevel");
  8349. c = 0;
  8350. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8351. while (loc[strlen("stackLevel")+2+c] != ',')
  8352. {
  8353. sstr[c] = loc[strlen("stackLevel")+2+c];
  8354. c++;
  8355. }
  8356. sstr[c] = '\0';
  8357. stackLevelInt = atoi(sstr);
  8358. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8359. {
  8360. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8361. }
  8362. else
  8363. {
  8364. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8365. }
  8366. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8367. //*********************chargingProfilePurpose***************************/
  8368. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8369. c = 0;
  8370. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8371. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8372. {
  8373. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8374. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8375. c++;
  8376. }
  8377. sstr[c] = '\0';
  8378. strcpy(chargingProfilePurposeStr,sstr);
  8379. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8380. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8381. {
  8382. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8383. }
  8384. else
  8385. {
  8386. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8387. }
  8388. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8389. //*********************chargingProfileKind***************************/
  8390. loc = strstr(sstrtemp, "chargingProfileKind");
  8391. c = 0;
  8392. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8393. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8394. {
  8395. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8396. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8397. c++;
  8398. }
  8399. sstr[c] = '\0';
  8400. strcpy(chargingProfileKindStr,sstr);
  8401. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8402. {
  8403. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8404. }
  8405. else
  8406. {
  8407. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8408. }
  8409. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8410. //*********************recurrencyKind***************************/
  8411. loc = strstr(sstrtemp, "recurrencyKind");
  8412. if(loc != NULL)
  8413. {
  8414. c = 0;
  8415. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8416. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8417. {
  8418. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8419. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8420. c++;
  8421. }
  8422. sstr[c] = '\0';
  8423. strcpy(recurrencyKindStr,sstr);
  8424. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8425. {
  8426. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8427. }
  8428. else
  8429. {
  8430. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8431. }
  8432. }
  8433. else
  8434. {
  8435. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8436. {
  8437. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8438. }
  8439. else
  8440. {
  8441. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8442. }
  8443. }
  8444. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8445. //*********************validFrom***************************/
  8446. loc = strstr(sstrtemp, "validFrom");
  8447. if(loc != NULL)
  8448. {
  8449. c = 0;
  8450. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8451. while (loc[3+strlen("validFrom")+c] != '\"')
  8452. {
  8453. sstr[c] = loc[3+strlen("validFrom")+c];
  8454. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8455. c++;
  8456. }
  8457. sstr[c] = '\0';
  8458. strcpy(validFromStr,sstr);
  8459. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8460. {
  8461. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8462. }
  8463. else
  8464. {
  8465. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8466. }
  8467. }
  8468. else
  8469. {
  8470. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8471. {
  8472. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8473. }
  8474. else
  8475. {
  8476. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8477. }
  8478. }
  8479. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8480. //*********************validTo***************************/
  8481. loc = strstr(sstrtemp, "validTo");
  8482. if(loc != NULL)
  8483. {
  8484. c = 0;
  8485. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8486. while (loc[3+strlen("validTo")+c] != '\"')
  8487. {
  8488. sstr[c] = loc[3+strlen("validTo")+c];
  8489. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8490. c++;
  8491. }
  8492. sstr[c] = '\0';
  8493. strcpy(validToStr,sstr);
  8494. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8495. {
  8496. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8497. }
  8498. else
  8499. {
  8500. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8501. }
  8502. }
  8503. else
  8504. {
  8505. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8506. {
  8507. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8508. }
  8509. else
  8510. {
  8511. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8512. }
  8513. }
  8514. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8515. //*********************duration***************************/
  8516. loc = strstr(sstrtemp, "duration");
  8517. if(loc != NULL)
  8518. {
  8519. c = 0;
  8520. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8521. while (loc[strlen("duration")+2+c] != ',')
  8522. {
  8523. sstr[c] = loc[strlen("duration")+2+c];
  8524. c++;
  8525. }
  8526. sstr[c] = '\0';
  8527. durationInt = atoi(sstr);
  8528. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8529. {
  8530. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8531. }
  8532. else
  8533. {
  8534. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8535. }
  8536. }
  8537. else
  8538. {
  8539. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8540. {
  8541. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8542. }
  8543. else
  8544. {
  8545. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8546. }
  8547. }
  8548. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8549. //*********************startSchedule***************************/
  8550. loc = strstr(sstrtemp, "startSchedule");
  8551. if(loc != NULL)
  8552. {
  8553. c = 0;
  8554. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8555. while (loc[3+strlen("startSchedule")+c] != '\"')
  8556. {
  8557. sstr[c] = loc[3+strlen("startSchedule")+c];
  8558. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8559. c++;
  8560. }
  8561. sstr[c] = '\0';
  8562. strcpy(startScheduleStr,sstr);
  8563. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8564. {
  8565. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8566. }
  8567. else
  8568. {
  8569. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8570. }
  8571. }
  8572. else
  8573. {
  8574. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8575. {
  8576. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8577. }
  8578. else
  8579. {
  8580. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8581. }
  8582. }
  8583. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8584. //*********************chargingRateUnit***************************/
  8585. loc = strstr(sstrtemp, "chargingRateUnit");
  8586. if(loc != NULL)
  8587. {
  8588. c = 0;
  8589. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8590. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8591. {
  8592. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8593. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8594. c++;
  8595. }
  8596. sstr[c] = '\0';
  8597. strcpy(chargingRateUnitStr,sstr);
  8598. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8599. {
  8600. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8601. }
  8602. else
  8603. {
  8604. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8605. }
  8606. }
  8607. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8608. //****************chargingSchedulePeriod count start*******************/
  8609. int what_len = strlen("startPeriod");
  8610. char tempChargingProfile[1600]={0};
  8611. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8612. char *where = tempChargingProfile;
  8613. if (what_len)
  8614. {
  8615. while ((where = strstr(where, "startPeriod"))) {
  8616. where += what_len;
  8617. chargingSchedulePeriodCount++;
  8618. }
  8619. }
  8620. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8621. {
  8622. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8623. goto end;
  8624. }
  8625. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8626. //where = payload;
  8627. int templength = 0;
  8628. //int searchstart = 0;
  8629. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8630. {
  8631. //****************startPeriod*******************/
  8632. c=0;
  8633. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8634. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8635. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8636. {
  8637. sstr[c] = loc[strlen("startPeriod")+2+c];
  8638. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8639. c++;
  8640. }
  8641. sstr[c] = '\0';
  8642. startPeriodInt[periodNums] = atoi(sstr);
  8643. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8644. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8645. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8646. {
  8647. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8648. }
  8649. else
  8650. {
  8651. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8652. }
  8653. templength = strlen("startPeriod")+2+c;
  8654. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8655. //****************limit*******************/
  8656. c=0;
  8657. loc = strstr(tempChargingProfile + templength, "limit");
  8658. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8659. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8660. {
  8661. sstr[c] = loc[strlen("limit")+2+c];
  8662. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8663. c++;
  8664. }
  8665. sstr[c] = '\0';
  8666. limitflaot[periodNums] = atof(sstr);
  8667. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8668. {
  8669. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8670. }
  8671. else
  8672. {
  8673. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8674. }
  8675. templength = templength + strlen("limit")+2+c;
  8676. //****************numberPhases*******************/
  8677. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8678. if(loc != NULL)
  8679. {
  8680. c=0;
  8681. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8682. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8683. {
  8684. sstr[c] = loc[strlen("numberPhases")+2+c];
  8685. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8686. c++;
  8687. }
  8688. sstr[c] = '\0';
  8689. numberPhasesInt[periodNums] = atoi(sstr);
  8690. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8691. {
  8692. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8693. }
  8694. else
  8695. {
  8696. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8697. }
  8698. templength = templength + strlen("numberPhases")+2+c;
  8699. }
  8700. //where = loc;
  8701. }
  8702. //****************chargingSchedulePeriod count end*******************/
  8703. //*********************minChargingRate***************************/
  8704. loc = strstr(sstrtemp, "minChargingRate");
  8705. if(loc != NULL)
  8706. {
  8707. c = 0;
  8708. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8709. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8710. {
  8711. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8712. c++;
  8713. }
  8714. sstr[c] = '\0';
  8715. minChargingRateFloat = atof(sstr);
  8716. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8717. {
  8718. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8719. }
  8720. else
  8721. {
  8722. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8723. }
  8724. }
  8725. else
  8726. {
  8727. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8728. {
  8729. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8730. }
  8731. else
  8732. {
  8733. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8734. }
  8735. }
  8736. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8737. {
  8738. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8739. if(connectorIdInt != 0)
  8740. {
  8741. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8742. goto end;
  8743. }
  8744. strcpy(filename, ChargePointMaxProfile_JSON );
  8745. fptr1 = fopen(filename, "r");
  8746. if (!fptr1)
  8747. {
  8748. //file not exist
  8749. DEBUG_INFO("Unable to open the input file!!\n");
  8750. fptr1 = fopen(filename, "w+");
  8751. }
  8752. else
  8753. {
  8754. //Check Charging Profile Count
  8755. while(fscanf(fptr1, "%s", word) != EOF)
  8756. {
  8757. //DEBUG_INFO("word=%s\n",word);
  8758. if(strstr(word, "chargingProfileId")!= NULL)
  8759. {
  8760. //DEBUG_INFO("test chargingProfileId \n");
  8761. n_chargingProfile = n_chargingProfile + 1;
  8762. //DEBUG_INFO("chargingProfileId Found\n");
  8763. }
  8764. }
  8765. }
  8766. fclose(fptr1);
  8767. }
  8768. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8769. {
  8770. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8771. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8772. {
  8773. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8774. goto end;
  8775. }
  8776. memset(filename, 0, ARRAY_SIZE(filename));
  8777. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8778. fptr1 = fopen(filename, "r");
  8779. if (!fptr1)
  8780. {
  8781. //file not exist
  8782. //DEBUG_INFO("Unable to open the input file!!\n");
  8783. fptr1 = fopen(filename, "w+");
  8784. }
  8785. else
  8786. {
  8787. //Check Charging Profile Count
  8788. while(fscanf(fptr1, "%s", word) != EOF)
  8789. {
  8790. //DEBUG_INFO("word=%s\n",word);
  8791. if(strstr(word, "chargingProfileId")!= NULL)
  8792. {
  8793. //DEBUG_INFO("test chargingProfileId \n");
  8794. n_chargingProfile = n_chargingProfile + 1;
  8795. //DEBUG_INFO("chargingProfileId Found\n");
  8796. }
  8797. }
  8798. }
  8799. fclose(fptr1);
  8800. }
  8801. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8802. {
  8803. //printf("set chargingProfile 1-4\n");
  8804. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8805. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8806. if(connectorIdInt == 0)
  8807. {
  8808. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8809. goto end;
  8810. }
  8811. int tempIndex = 0;
  8812. //check Transaction active
  8813. if(gunType[connectorIdInt -1] == 'J')
  8814. {
  8815. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8816. {
  8817. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8818. }
  8819. else
  8820. {
  8821. tempIndex = connectorIdInt -1;
  8822. }
  8823. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8824. {
  8825. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8826. {
  8827. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8828. {
  8829. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8830. {
  8831. meet = TRUE;
  8832. break;
  8833. }
  8834. }
  8835. }
  8836. }
  8837. }
  8838. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8839. {
  8840. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8841. {
  8842. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8843. }
  8844. else
  8845. {
  8846. tempIndex = connectorIdInt -1;
  8847. }
  8848. for (int index = 0; index < CCS_QUANTITY; index++)
  8849. {
  8850. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8851. {
  8852. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8853. {
  8854. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8855. {
  8856. meet = TRUE;
  8857. break;
  8858. }
  8859. }
  8860. }
  8861. }
  8862. }
  8863. else if(gunType[connectorIdInt -1] == 'G')
  8864. {
  8865. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8866. {
  8867. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8868. }
  8869. else
  8870. {
  8871. tempIndex = connectorIdInt -1;
  8872. }
  8873. for (int index = 0; index < GB_QUANTITY; index++)
  8874. {
  8875. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8876. {
  8877. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8878. {
  8879. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8880. {
  8881. meet = TRUE;
  8882. break;
  8883. }
  8884. }
  8885. }
  8886. }
  8887. }
  8888. else
  8889. {
  8890. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8891. {
  8892. tempIndex = 2;
  8893. }
  8894. else
  8895. {
  8896. tempIndex = (connectorIdInt -1);
  8897. }
  8898. for (int index = 0; index < AC_QUANTITY; index++)
  8899. {
  8900. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8901. {
  8902. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8903. {
  8904. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8905. {
  8906. meet = TRUE;
  8907. break;
  8908. }
  8909. }
  8910. }
  8911. }
  8912. }
  8913. //check Transaction active
  8914. if(meet == FALSE)
  8915. {
  8916. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8917. goto end;
  8918. }
  8919. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8920. {
  8921. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8922. goto end;
  8923. }
  8924. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8925. fptr1 = fopen(filename, "r");
  8926. if (!fptr1)
  8927. {
  8928. //file not exist
  8929. DEBUG_INFO("Unable to open the input file!!\n");
  8930. fptr1 = fopen(filename, "w+");
  8931. }
  8932. else
  8933. {
  8934. //Check Charging Profile Count
  8935. while(fscanf(fptr1, "%s", word) != EOF)
  8936. {
  8937. //DEBUG_INFO("word=%s\n",word);
  8938. if(strstr(word, "chargingProfileId")!= NULL)
  8939. {
  8940. //DEBUG_INFO("test chargingProfileId \n");
  8941. n_chargingProfile = n_chargingProfile + 1;
  8942. //DEBUG_INFO("chargingProfileId Found\n");
  8943. }
  8944. }
  8945. }
  8946. fclose(fptr1);
  8947. }
  8948. // Check ChargeProfileMaxStackLevel
  8949. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8950. {
  8951. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8952. goto end;
  8953. }
  8954. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8955. {
  8956. int i = 0;
  8957. char fnametemp[200]={0};
  8958. n_chargingProfile = 0;
  8959. //Check ChargePointMaxProfile.json exit
  8960. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8961. {
  8962. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8963. //Check Charging Profile Count
  8964. while(fscanf(fptr1, "%s", word) != EOF)
  8965. {
  8966. //DEBUG_INFO("word=%s\n",word);
  8967. if(strstr(word, "chargingProfileId")!= NULL)
  8968. {
  8969. //DEBUG_INFO("test chargingProfileId \n");
  8970. n_chargingProfile = n_chargingProfile + 1;
  8971. i = i + 1;
  8972. //DEBUG_INFO("chargingProfileId Found\n");
  8973. }
  8974. memset(word, 0, ARRAY_SIZE(word));
  8975. }
  8976. fclose(fptr1);
  8977. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8978. }
  8979. //Check TxDefaultProfile_0.json exit
  8980. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8981. {
  8982. i = 0;
  8983. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8984. //Check Charging Profile Count
  8985. while(fscanf(fptr1, "%s", word) != EOF)
  8986. {
  8987. //DEBUG_INFO("word=%s\n",word);
  8988. if(strstr(word, "chargingProfileId")!= NULL)
  8989. {
  8990. //DEBUG_INFO("test chargingProfileId \n");
  8991. n_chargingProfile = n_chargingProfile + 1;
  8992. i = i + 1;
  8993. //DEBUG_INFO("chargingProfileId Found\n");
  8994. }
  8995. memset(word, 0, ARRAY_SIZE(word));
  8996. }
  8997. fclose(fptr1);
  8998. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8999. }
  9000. //Check TxDefaultProfile_%d.json
  9001. for(int j=1; j <= gunTotalNumber; j++)
  9002. {
  9003. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9004. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9005. if((access(fnametemp,F_OK))!=-1)
  9006. {
  9007. i = 0;
  9008. fptr1 = fopen(fnametemp, "r");
  9009. //Check Charging Profile Count
  9010. while(fscanf(fptr1, "%s", word) != EOF)
  9011. {
  9012. //DEBUG_INFO("word=%s\n",word);
  9013. if(strstr(word, "chargingProfileId")!= NULL)
  9014. {
  9015. //DEBUG_INFO("test chargingProfileId \n");
  9016. n_chargingProfile = n_chargingProfile + 1;
  9017. i = i + 1;
  9018. //DEBUG_INFO("chargingProfileId Found\n");
  9019. }
  9020. memset(word, 0, ARRAY_SIZE(word));
  9021. }
  9022. fclose(fptr1);
  9023. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9024. }
  9025. }
  9026. //Check TxProfile_%d.json
  9027. for(int j=1; j <= gunTotalNumber; j++)
  9028. {
  9029. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9030. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9031. if((access(fnametemp,F_OK))!=-1)
  9032. {
  9033. i = 0;
  9034. fptr1 = fopen(fnametemp, "r");
  9035. //Check Charging Profile Count
  9036. while(fscanf(fptr1, "%s", word) != EOF)
  9037. {
  9038. //DEBUG_INFO("word=%s\n",word);
  9039. if(strstr(word, "chargingProfileId")!= NULL)
  9040. {
  9041. //DEBUG_INFO("test chargingProfileId \n");
  9042. n_chargingProfile = n_chargingProfile + 1;
  9043. i = i + 1;
  9044. //DEBUG_INFO("chargingProfileId Found\n");
  9045. }
  9046. memset(word, 0, ARRAY_SIZE(word));
  9047. }
  9048. fclose(fptr1);
  9049. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9050. }
  9051. }
  9052. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9053. {
  9054. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9055. goto end;
  9056. }
  9057. }
  9058. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9059. //**********************************Write to File********************************************************/
  9060. FILE *infile;
  9061. FILE *outfile;
  9062. // open file for writing
  9063. infile = fopen (filename, "r");
  9064. outfile = fopen (tempfile, "w");
  9065. int d =0;
  9066. d = fgetc(infile);
  9067. //DEBUG_INFO("d:%d\n",d);
  9068. rewind(infile);
  9069. //*璉 瘚 辣蝏     1嚗   0 */
  9070. if(d == EOF)
  9071. {
  9072. //DEBUG_INFO("ChargingProfile content is NULL\n");
  9073. fprintf(outfile,"%s\n",payload);
  9074. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9075. fclose(infile);
  9076. fclose(outfile);
  9077. sprintf(rmFileCmd,"rm -f %s",filename);
  9078. system(rmFileCmd);
  9079. rename(tempfile, filename);
  9080. sleep(1);
  9081. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  9082. //system(rmFileCmd);
  9083. }
  9084. else
  9085. {
  9086. char buf[1000]={0};
  9087. int ChargingProfileAdded = FALSE;
  9088. while (fgets(buf, sizeof(buf), infile) != NULL)
  9089. {
  9090. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9091. //*************************tempconnectorIdInt*********************************/
  9092. loc = strstr(buf, "connectorId");
  9093. c = 0;
  9094. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9095. while (loc[strlen("connectorId")+2+c] != ',')
  9096. {
  9097. sstr[c] = loc[strlen("connectorId")+2+c];
  9098. c++;
  9099. }
  9100. sstr[c] = '\0';
  9101. tempconnectorIdInt = atoi(sstr);
  9102. //*************************tempchargingProfileIdInt*********************************/
  9103. loc = strstr(buf, "chargingProfileId");
  9104. c = 0;
  9105. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9106. while (loc[strlen("chargingProfileId")+2+c] != ',')
  9107. {
  9108. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  9109. c++;
  9110. }
  9111. sstr[c] = '\0';
  9112. tempchargingProfileIdInt = atoi(sstr);
  9113. //*************************tempstackLevelInt*********************************/
  9114. loc = strstr(buf, "stackLevel");
  9115. c = 0;
  9116. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9117. while (loc[strlen("stackLevel")+2+c] != ',')
  9118. {
  9119. sstr[c] = loc[strlen("stackLevel")+2+c];
  9120. c++;
  9121. }
  9122. sstr[c] = '\0';
  9123. tempstackLevelInt = atoi(sstr);
  9124. //*************************tempchargingProfilePurposeStr*********************************/
  9125. loc = strstr(payload, "chargingProfilePurpose");
  9126. c = 0;
  9127. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9128. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  9129. {
  9130. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  9131. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9132. c++;
  9133. }
  9134. sstr[c] = '\0';
  9135. strcpy(tempchargingProfilePurposeStr,sstr);
  9136. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9137. {
  9138. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9139. {
  9140. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9141. if(ChargingProfileAdded == FALSE)
  9142. {
  9143. fprintf(outfile,"%s\n",payload);
  9144. ChargingProfileAdded = TRUE;
  9145. }
  9146. }
  9147. else
  9148. {
  9149. if(tempstackLevelInt < stackLevelInt)
  9150. {
  9151. if(ChargingProfileAdded == FALSE)
  9152. {
  9153. fprintf(outfile,"%s\n",payload);
  9154. ChargingProfileAdded = TRUE;
  9155. fprintf(outfile,"%s\n",buf);
  9156. }
  9157. else
  9158. {
  9159. fprintf(outfile,"%s\n",buf);
  9160. }
  9161. }
  9162. else
  9163. {
  9164. if(ChargingProfileAdded == FALSE)
  9165. {
  9166. fprintf(outfile,"%s\n",buf);
  9167. fprintf(outfile,"%s\n",payload);
  9168. ChargingProfileAdded = TRUE;
  9169. }
  9170. else
  9171. {
  9172. fprintf(outfile,"%s\n",buf);
  9173. }
  9174. }
  9175. }
  9176. }
  9177. else
  9178. {
  9179. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9180. {
  9181. if(ChargingProfileAdded == FALSE)
  9182. {
  9183. fprintf(outfile,"%s\n",payload);
  9184. ChargingProfileAdded = TRUE;
  9185. fprintf(outfile,"%s\n",buf);
  9186. }
  9187. else
  9188. {
  9189. fprintf(outfile,"%s\n",buf);
  9190. }
  9191. }
  9192. else if(tempstackLevelInt < stackLevelInt)
  9193. {
  9194. if(ChargingProfileAdded == FALSE)
  9195. {
  9196. fprintf(outfile,"%s\n",payload);
  9197. ChargingProfileAdded = TRUE;
  9198. fprintf(outfile,"%s\n",buf);
  9199. }
  9200. else
  9201. {
  9202. fprintf(outfile,"%s\n",buf);
  9203. }
  9204. }
  9205. else
  9206. {
  9207. if(ChargingProfileAdded == FALSE)
  9208. {
  9209. fprintf(outfile,"%s\n",buf);
  9210. fprintf(outfile,"%s\n",payload);
  9211. ChargingProfileAdded = TRUE;
  9212. }
  9213. else
  9214. {
  9215. fprintf(outfile,"%s\n",buf);
  9216. }
  9217. }
  9218. }
  9219. } // end of while loop
  9220. fclose(infile);
  9221. fclose(outfile);
  9222. sprintf(rmFileCmd,"rm -f %s",filename);
  9223. system(rmFileCmd);
  9224. rename(tempfile, filename);
  9225. sleep(1);
  9226. result = TRUE;
  9227. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9228. }
  9229. end:
  9230. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9231. return result;
  9232. return result;
  9233. }
  9234. int handleTriggerMessageRequest(char *uuid, char *payload)
  9235. {
  9236. mtrace();
  9237. int result = FAIL;
  9238. int connectorIdIsNULL = FALSE;
  9239. int connectorIdInt =0;
  9240. char sstr[40]={0},sstrtemp[100]={ 0 };
  9241. char requestedMessagestr[40]={0};
  9242. char comfirmstr[20]={0};
  9243. int c = 0;
  9244. char *loc;
  9245. DEBUG_INFO("handleTriggerMessageRequest\n");
  9246. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9247. strcpy(sstrtemp, stringtrimspace(payload));
  9248. c = 0;
  9249. loc = strstr(sstrtemp, "requestedMessage");
  9250. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9251. {
  9252. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9253. c++;
  9254. }
  9255. sstr[c] = '\0';
  9256. strcpy(requestedMessagestr, sstr);
  9257. c = 0;
  9258. loc = strstr(sstrtemp, "connectorId");
  9259. if(loc == NULL)
  9260. {
  9261. connectorIdIsNULL = TRUE;
  9262. }
  9263. else
  9264. {
  9265. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9266. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9267. {
  9268. sstr[c] = loc[strlen("connectorId")+2+c];
  9269. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9270. c++;
  9271. }
  9272. sstr[c] = '\0';
  9273. connectorIdInt = atoi(sstr);
  9274. }
  9275. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  9276. {
  9277. //connectorIdInt = json_object_get_int(connectorId);
  9278. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9279. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9280. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9281. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9282. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9283. }
  9284. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9285. {
  9286. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9287. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9288. return TRUE;
  9289. }
  9290. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9291. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9292. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9293. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9294. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9295. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9296. {
  9297. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9298. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9299. return TRUE;
  9300. }
  9301. else
  9302. {
  9303. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9304. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9305. }
  9306. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9307. {
  9308. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9309. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9310. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9311. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9312. {
  9313. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9314. }
  9315. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9316. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9317. }
  9318. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9319. {
  9320. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9321. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9322. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9323. }
  9324. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9325. {
  9326. sendBootNotificationRequest();
  9327. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9328. }
  9329. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9330. {
  9331. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9332. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9333. }
  9334. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9335. {
  9336. if(connectorIdIsNULL == FALSE)
  9337. {
  9338. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9339. {
  9340. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9341. sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9342. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9343. }
  9344. }
  9345. else
  9346. {
  9347. for(int idx=0;idx< gunTotalNumber;idx++)
  9348. {
  9349. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  9350. sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9351. }
  9352. }
  9353. }
  9354. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9355. {
  9356. if(connectorIdIsNULL == FALSE)
  9357. {
  9358. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9359. {
  9360. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9361. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9362. }
  9363. }
  9364. else
  9365. {
  9366. for(int idx=0;idx< gunTotalNumber;idx++)
  9367. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9368. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9369. }
  9370. }
  9371. return result;
  9372. }
  9373. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9374. {
  9375. mtrace();
  9376. int result = FAIL;
  9377. char sstr[6]={0},sstrtemp[50]={ 0 };
  9378. int connectorIdInt =0;
  9379. char comfirmstr[20]={0};
  9380. int c = 0;
  9381. int tempIndex = 0;
  9382. char *loc;
  9383. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9384. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9385. strcpy(sstrtemp, stringtrimspace(payload));
  9386. c = 0;
  9387. loc = strstr(sstrtemp, "connectorId");
  9388. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9389. while (loc[strlen("connectorId")+2+c] != '}')
  9390. {
  9391. sstr[c] = loc[strlen("connectorId")+2+c];
  9392. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9393. c++;
  9394. }
  9395. sstr[c] = '\0';
  9396. connectorIdInt = atoi(sstr);
  9397. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  9398. if(gunTotalNumber == 0)
  9399. {
  9400. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9401. goto end;
  9402. }
  9403. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9404. {
  9405. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9406. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9407. goto end;
  9408. }
  9409. else
  9410. {
  9411. //check Transaction active
  9412. if(gunType[connectorIdInt-1] == 'J')
  9413. {
  9414. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9415. {
  9416. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9417. }
  9418. else
  9419. {
  9420. tempIndex = connectorIdInt -1;
  9421. }
  9422. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9423. {
  9424. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9425. {
  9426. //stop Transaction
  9427. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9428. }
  9429. }
  9430. }
  9431. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9432. {
  9433. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9434. {
  9435. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9436. }
  9437. else
  9438. {
  9439. tempIndex = connectorIdInt -1;
  9440. }
  9441. for (int index = 0; index < CCS_QUANTITY; index++)
  9442. {
  9443. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9444. {
  9445. //stop Transaction
  9446. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9447. }
  9448. }
  9449. }
  9450. else if(gunType[connectorIdInt-1] == 'G')
  9451. {
  9452. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9453. {
  9454. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9455. }
  9456. else
  9457. {
  9458. tempIndex = connectorIdInt -1;
  9459. }
  9460. for (int index = 0; index < GB_QUANTITY; index++)
  9461. {
  9462. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9463. {
  9464. //stop Transaction
  9465. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9466. }
  9467. }
  9468. }
  9469. else
  9470. {
  9471. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9472. {
  9473. tempIndex = 2;
  9474. }
  9475. else
  9476. {
  9477. tempIndex = connectorIdInt-1;
  9478. }
  9479. for (int index = 0; index < AC_QUANTITY; index++)
  9480. {
  9481. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9482. {
  9483. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9484. }
  9485. }
  9486. }
  9487. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9488. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9489. result = TRUE;
  9490. return result;
  9491. }
  9492. end:
  9493. //json_object_put(obj); --- remove temporally
  9494. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9495. return result;
  9496. }
  9497. static char UpdateFirmwarepayloadData[300]={0};
  9498. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9499. {
  9500. mtrace();
  9501. int result = FAIL;
  9502. pthread_t t;
  9503. sendUpdateFirmwareConfirmation(uuid);
  9504. memset(UpdateFirmwarepayloadData, 0, 300);
  9505. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9506. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9507. ////pthread_join(t, NULL); //
  9508. //pthread_detach(t);
  9509. //sendUpdateFirmwareConfirmation(uuid);
  9510. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9511. return result;
  9512. }
  9513. void *UpdateFirmwareProcess(void *data)
  9514. {
  9515. pthread_detach(pthread_self());
  9516. mtrace();
  9517. int retriesInt =0, retryIntervalInt=0;
  9518. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9519. int port=0;
  9520. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9521. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  9522. //char comfirmstr[20];
  9523. int isSuccess = 0;
  9524. char ftpbuf[200];
  9525. char temp[100];
  9526. char * pch;
  9527. int retriesISNULL=FALSE;
  9528. int retryInterval=FALSE;
  9529. int c = 0;
  9530. //int i = 0;
  9531. char *loc;
  9532. char sstr[300]={ 0 };
  9533. char str[300]={ 0 };
  9534. //char *str = (char*) data; // ? ?頛詨鞈 ?
  9535. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9536. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  9537. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  9538. //***************location **************/
  9539. loc = strstr(str, "location");
  9540. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9541. c = 0;
  9542. while (loc[3+strlen("location")+c] != '\"')
  9543. {
  9544. sstr[c] = loc[3+strlen("location")+c];
  9545. c++;
  9546. }
  9547. sstr[c] = '\0';
  9548. strcpy(locationstr, sstr);
  9549. //***************retries**************/
  9550. c = 0;
  9551. loc = strstr(str, "retries");
  9552. if(loc == NULL)
  9553. {
  9554. retriesISNULL=TRUE;
  9555. }
  9556. else
  9557. {
  9558. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9559. while (loc[strlen("retries")+2+c] != ',')
  9560. {
  9561. sstr[c] = loc[strlen("retries")+2+c];
  9562. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9563. c++;
  9564. }
  9565. sstr[c] = '\0';
  9566. }
  9567. if(retriesISNULL == FALSE)
  9568. {
  9569. retriesInt = atoi(sstr);
  9570. }
  9571. //***************retrieveDate **************/
  9572. loc = strstr(str, "retrieveDate");
  9573. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9574. c = 0;
  9575. while (loc[3+strlen("retrieveDate")+c] != '\"')
  9576. {
  9577. sstr[c] = loc[3+strlen("retrieveDate")+c];
  9578. c++;
  9579. }
  9580. sstr[c] = '\0';
  9581. strcpy(retrieveDatestr, sstr);
  9582. //***************retryInterval **************/
  9583. c = 0;
  9584. loc = strstr(str, "retryInterval");
  9585. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9586. if(loc == NULL)
  9587. {
  9588. retryInterval=TRUE;
  9589. }
  9590. else
  9591. {
  9592. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  9593. {
  9594. sstr[c] = loc[strlen("retryInterval")+2+c];
  9595. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  9596. c++;
  9597. }
  9598. sstr[c] = '\0';
  9599. }
  9600. if(retryInterval==FALSE)
  9601. {
  9602. retryIntervalInt = atoi(sstr);
  9603. }
  9604. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9605. memset(path, 0, ARRAY_SIZE(path));
  9606. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9607. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9608. if(strncmp(locationstr,"http", 4) == 0)
  9609. {
  9610. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  9611. protocol, host, path);
  9612. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9613. // protocol, user, password, host, path);
  9614. sprintf(ftppath,"/%s", path);
  9615. //DEBUG_INFO("protocol =%s\n",protocol);
  9616. //DEBUG_INFO("host =%s\n",host);
  9617. //DEBUG_INFO("path =%s\n",path);
  9618. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9619. int ftppathlen=strlen(ftppath);
  9620. int i=1;
  9621. char filenametemp[50];
  9622. while(i < ftppathlen)
  9623. {
  9624. int len=ftppathlen-i;
  9625. if(ftppath[len]== 47) // '/' ascll code: 47
  9626. {
  9627. DEBUG_INFO("compare '/' all right\n");
  9628. break;
  9629. }
  9630. i=i+1;
  9631. }
  9632. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9633. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9634. filenametemp[i+1] = 0;
  9635. do
  9636. {
  9637. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9638. sleep(retryIntervalInt);
  9639. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9640. if(!isSuccess)
  9641. {
  9642. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9643. }
  9644. else
  9645. {
  9646. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9647. }
  9648. }
  9649. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9650. {
  9651. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9652. memset(temp, 0, ARRAY_SIZE(temp));
  9653. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9654. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9655. int ftppathlen=strlen(ftpbuf);
  9656. int i=1;
  9657. char filenametemp[50];
  9658. while(i < ftppathlen)
  9659. {
  9660. int len=ftppathlen-i;
  9661. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9662. {
  9663. DEBUG_INFO(" compare '/' all right\n");
  9664. break;
  9665. }
  9666. i=i+1;
  9667. }
  9668. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9669. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9670. filenametemp[i+1] = 0;
  9671. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9672. pch=strchr(temp,'@');
  9673. if(pch==NULL)
  9674. {
  9675. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9676. protocol, host, &port, path);
  9677. strcpy(user,"anonymous");
  9678. strcpy(password,"");
  9679. }
  9680. else
  9681. {
  9682. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9683. protocol, user, password, host, &port, path);
  9684. }
  9685. sscanf(host,"%[^/]%s",host1, path1);
  9686. sprintf(ftppath,"%s", path1);
  9687. //DEBUG_INFO("protocol =%s\n",protocol);
  9688. //DEBUG_INFO("user =%s\n",user);
  9689. //DEBUG_INFO("password =%s\n",password);
  9690. //DEBUG_INFO("host1 =%s\n",host1);
  9691. //DEBUG_INFO("port =%d\n",port);
  9692. //DEBUG_INFO("path1 =%s\n",path1);
  9693. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9694. //ftpFile(host, user, password, port, ftppath, fname);
  9695. //download firmware pthred
  9696. if(port == 0)
  9697. {
  9698. port = 21;
  9699. }
  9700. do
  9701. {
  9702. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9703. sleep(retryIntervalInt);
  9704. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9705. if(!isSuccess)
  9706. {
  9707. //BulldogUtil.sleepMs(interval*1000);
  9708. DEBUG_INFO("Update firmware request and download file fail.\n");
  9709. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9710. }
  9711. else
  9712. {
  9713. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9714. }
  9715. }
  9716. else
  9717. {
  9718. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9719. }
  9720. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9721. pthread_exit(NULL);
  9722. }
  9723. //==========================================
  9724. // Handle server response routine
  9725. //==========================================
  9726. void handleAuthorizeResponse(char *payload, int gun_index)
  9727. {
  9728. mtrace();
  9729. char expiryDatestr[30]={0};
  9730. char parentIdTagstr[20]={0};
  9731. char statusstr[20]={0};
  9732. char expiryDatestrtemp[30]={0};
  9733. char parentIdTagstrtemp[20]={0};
  9734. char IdTagstrtemp[20]={0};
  9735. char statusstrtemp[20]={0};
  9736. int expiryDateISNULL=FALSE;
  9737. int parentIdTagISNULL=FALSE;
  9738. char sstr[160]={0};
  9739. char* filename = AuthorizationCache_JSON;
  9740. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9741. char *loc;
  9742. int resultRename=0;
  9743. int responseIdTagInfoAsZero= 0;
  9744. char rmFileCmd[50]={0};
  9745. DEBUG_INFO("handleAuthorizeResponse...\n");
  9746. json_object *Authorize;
  9747. Authorize = json_tokener_parse(payload);
  9748. if(!is_error(Authorize))
  9749. {
  9750. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9751. {
  9752. // Required data
  9753. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9754. // Optional data
  9755. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9756. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9757. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9758. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9759. }
  9760. }
  9761. json_object_put(Authorize);
  9762. if(expiryDateISNULL == FALSE)
  9763. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9764. if(parentIdTagISNULL == FALSE)
  9765. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9766. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9767. //Update idTag information to authorization cache if supproted
  9768. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9769. {
  9770. if((access(filename,F_OK))!=-1)
  9771. {
  9772. printf("AuthorizationCache exist.\n");
  9773. }
  9774. else
  9775. {
  9776. printf("AuthorizationCache not exist\n");
  9777. FILE *log = fopen(filename, "w+");
  9778. if(log == NULL)
  9779. {
  9780. printf("log is NULL\n");
  9781. goto out;
  9782. }
  9783. else
  9784. {
  9785. fclose(log);
  9786. }
  9787. }
  9788. FILE *infile;
  9789. FILE *outfile;
  9790. // open file for writing
  9791. infile = fopen (filename, "r");
  9792. outfile = fopen (tempfile, "w");
  9793. int c;
  9794. c = fgetc(infile);
  9795. //DEBUG_INFO("c:%d\n",c);
  9796. rewind(infile);
  9797. if(c == EOF)
  9798. {
  9799. DEBUG_INFO("Orignal File is NULL\n");
  9800. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9801. {
  9802. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9803. }
  9804. else
  9805. {
  9806. strcpy(expiryDatestrtemp, "");
  9807. }
  9808. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9809. {
  9810. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9811. }
  9812. else
  9813. {
  9814. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9815. }
  9816. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9817. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9818. fclose(infile);
  9819. fclose(outfile);
  9820. sprintf(rmFileCmd,"rm -f %s",filename);
  9821. system(rmFileCmd);
  9822. resultRename = rename(tempfile, filename);
  9823. if(resultRename == 0)
  9824. {
  9825. printf("File renamed successfully");
  9826. }
  9827. else
  9828. {
  9829. printf("Error: unable to rename the file");
  9830. }
  9831. }
  9832. else
  9833. {
  9834. char buf[160]={0};
  9835. while (fgets(buf, ARRAY_SIZE(buf), infile) != NULL)
  9836. {
  9837. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9838. memset(expiryDatestr, 0, ARRAY_SIZE(expiryDatestrtemp));
  9839. memset(parentIdTagstr,0, ARRAY_SIZE(parentIdTagstrtemp));
  9840. memset(statusstr, 0, ARRAY_SIZE(statusstrtemp));
  9841. memset(IdTagstrtemp, 0, ARRAY_SIZE(IdTagstrtemp));
  9842. memset(expiryDatestrtemp, 0, ARRAY_SIZE(expiryDatestrtemp));
  9843. memset(parentIdTagstrtemp, 0, ARRAY_SIZE(parentIdTagstrtemp));
  9844. memset(statusstrtemp, 0, ARRAY_SIZE(statusstrtemp));
  9845. //------------------IdTag-----------------------
  9846. loc = strstr(buf, "idTag");
  9847. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9848. c = 0;
  9849. while (loc[3+strlen("idTag")+c] != '\"')
  9850. {
  9851. sstr[c] = loc[3+strlen("idTag")+c];
  9852. c++;
  9853. }
  9854. sstr[c] = '\0';
  9855. strcpy(IdTagstrtemp,sstr);
  9856. //*********************expiryDate***************/
  9857. loc = strstr(buf, "expiryDate");
  9858. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9859. c = 0;
  9860. while (loc[3+strlen("expiryDate")+c] != '\"')
  9861. {
  9862. sstr[c] = loc[3+strlen("expiryDate")+c];
  9863. c++;
  9864. }
  9865. sstr[c] = '\0';
  9866. strcpy(expiryDatestr,sstr);
  9867. //*********************parentIdTag***************/
  9868. loc = strstr(buf, "parentIdTag");
  9869. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9870. c = 0;
  9871. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9872. {
  9873. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9874. c++;
  9875. }
  9876. sstr[c] = '\0';
  9877. strcpy(parentIdTagstr,sstr);
  9878. //*********************status***************/
  9879. loc = strstr(buf, "status");
  9880. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9881. c = 0;
  9882. while (loc[3+strlen("status")+c] != '\"')
  9883. {
  9884. sstr[c] = loc[3+strlen("status")+c];
  9885. c++;
  9886. }
  9887. sstr[c] = '\0';
  9888. strcpy(statusstr,sstr);
  9889. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9890. {
  9891. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9892. responseIdTagInfoAsZero = 1;
  9893. }
  9894. else
  9895. {
  9896. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9897. }
  9898. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9899. {
  9900. //modify item
  9901. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9902. {
  9903. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9904. }
  9905. else
  9906. {
  9907. strcpy(expiryDatestrtemp, "");
  9908. }
  9909. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9910. {
  9911. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9912. }
  9913. else
  9914. {
  9915. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9916. }
  9917. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9918. }
  9919. else
  9920. {
  9921. //wrie original item
  9922. strcpy(expiryDatestrtemp, expiryDatestr);
  9923. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9924. strcpy(statusstrtemp, statusstr);
  9925. }
  9926. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9927. }
  9928. fclose(infile);
  9929. fclose(outfile);
  9930. sprintf(rmFileCmd,"rm -f %s",filename);
  9931. system(rmFileCmd);
  9932. resultRename = rename(tempfile, filename);
  9933. if(resultRename == 0)
  9934. {
  9935. DEBUG_INFO("File renamed successfully");
  9936. }
  9937. else
  9938. {
  9939. DEBUG_INFO("Error: unable to rename the file");
  9940. }
  9941. }
  9942. }
  9943. out:
  9944. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9945. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9946. authorizeRetryTimes = 0;
  9947. }
  9948. char * strtrimc( char * s )
  9949. {
  9950. char * p1 = s;
  9951. char * p2 = s;
  9952. while(*p1 != '\0')
  9953. {
  9954. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9955. {
  9956. if(*p1 != ',')
  9957. {
  9958. p1 ++;
  9959. }
  9960. else
  9961. {
  9962. break;
  9963. }
  9964. }
  9965. if(*p1 != ',')
  9966. {
  9967. * p2 ++ = *p1 ++;
  9968. //printf("p2=%s\n",p2);
  9969. }
  9970. else
  9971. {
  9972. break;
  9973. }
  9974. }
  9975. *p2 = '\0';
  9976. return (s);
  9977. }
  9978. void handleBootNotificationResponse(char *payload, int gun_index)
  9979. {
  9980. mtrace();
  9981. char statusStr[12]={0};
  9982. char currentTimeStr[30]={0};
  9983. int intervalInt = 0;
  9984. struct tm tp;
  9985. char buf[28]={0};
  9986. char timebuf[50]={0};
  9987. DEBUG_INFO("handleBootNotificationResponse...\n");
  9988. json_object *BootNotification;
  9989. BootNotification = json_tokener_parse(payload);
  9990. if(!is_error(BootNotification))
  9991. {
  9992. // Required data
  9993. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9994. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9995. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9996. }
  9997. json_object_put(BootNotification);
  9998. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9999. BootNotificationInterval = intervalInt;
  10000. HeartBeatWaitTime = intervalInt;
  10001. //write back to ShmOCPP16Data->BootNotification
  10002. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  10003. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10004. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  10005. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  10006. {
  10007. server_sign = TRUE;
  10008. server_pending =FALSE;
  10009. }
  10010. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  10011. {
  10012. server_pending = TRUE;
  10013. }
  10014. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10015. tp.tm_isdst = -1;
  10016. //time_t utc = mktime(&tp);
  10017. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10018. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  10019. sprintf(timebuf,"date -s '%s'",buf);
  10020. system(timebuf);
  10021. srand(time(NULL));
  10022. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  10023. //==============================================
  10024. // RTC sync
  10025. //==============================================
  10026. system("/sbin/hwclock -w --systohc");
  10027. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  10028. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  10029. }
  10030. void handleDataTransferResponse(char *payload, int gun_index)
  10031. {
  10032. char sstr[160]={0};//sstr[200]={ 0 };
  10033. int c = 0;
  10034. char *loc;
  10035. DEBUG_INFO("handleDataTransferResponse ...\n");
  10036. loc = strstr(payload, "status");
  10037. printf("loc=%s\n",loc);
  10038. c = 0;
  10039. while (loc[3+strlen("status")+c] != '\"')
  10040. {
  10041. sstr[c] = loc[3+strlen("status")+c];
  10042. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10043. c++;
  10044. }
  10045. sstr[c] = '\0';
  10046. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  10047. }
  10048. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  10049. {
  10050. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  10051. //struct json_object *obj;
  10052. // obj = json_tokener_parse(payload);
  10053. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  10054. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  10055. //No fields are defined.
  10056. }
  10057. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  10058. {
  10059. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  10060. //struct json_object *obj;
  10061. // obj = json_tokener_parse(payload);
  10062. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  10063. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  10064. //No fields are defined.
  10065. }
  10066. void handleHeartbeatResponse(char *payload, int gun_index)
  10067. {
  10068. mtrace();
  10069. struct tm tp;
  10070. char buf[28]={0};
  10071. char timebuf[50]={0};
  10072. DEBUG_INFO("handleHeartbeatResponse...\n");
  10073. json_object *Heartbeat;
  10074. Heartbeat = json_tokener_parse(payload);
  10075. if(!is_error(Heartbeat))
  10076. {
  10077. // Required data
  10078. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  10079. }
  10080. json_object_put(BootNotification);
  10081. if(FirstHeartBeat == 0)
  10082. {
  10083. FirstHeartBeat = 1;
  10084. DEBUG_INFO("FirstHeartBeat \n");
  10085. }
  10086. HeartBeatWithNOResponse = 0;
  10087. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10088. tp.tm_isdst = -1;
  10089. //time_t utc = mktime(&tp);
  10090. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10091. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  10092. sprintf(timebuf,"date -s '%s'",buf);
  10093. system(timebuf);
  10094. //==============================================
  10095. // RTC sync
  10096. //==============================================
  10097. system("/sbin/hwclock -w --systohc");
  10098. //===============================================
  10099. //Print Out HeartBeat log
  10100. //===============================================
  10101. {
  10102. double diff_t;
  10103. struct tm tp,tp1;
  10104. // BootNotification Receive Time
  10105. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10106. tp.tm_isdst = -1;
  10107. time_t BootNotificationReceiveTime = mktime(&tp);
  10108. //HeartBeat Receive Time
  10109. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  10110. tp1.tm_isdst = -1;
  10111. time_t HeartBeatReceiveTime = mktime(&tp1);
  10112. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  10113. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  10114. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  10115. {
  10116. HeartBeatCountPerHour = (int)diff_t / 3600;
  10117. DEBUG_INFO("handleHeartbeatResponse ...\n");
  10118. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  10119. }
  10120. }
  10121. }
  10122. void handleMeterValuesResponse(char *payload, int gun_index)
  10123. {
  10124. mtrace();
  10125. DEBUG_INFO("handleMeterValuesResponse...\n");
  10126. }
  10127. void handleStartTransactionResponse(char *payload, int gun_index)
  10128. {
  10129. mtrace();
  10130. //int transactionIdInt = 0;
  10131. FILE *outfile;
  10132. char data[100]={0};
  10133. DEBUG_INFO("handleStartTransactionResponse...\n");
  10134. json_object *StartTransaction;
  10135. StartTransaction = json_tokener_parse(payload);
  10136. if(!is_error(StartTransaction))
  10137. {
  10138. // Required data
  10139. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  10140. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  10141. // Optional data
  10142. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  10143. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  10144. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10145. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  10146. }
  10147. json_object_put(StartTransaction);
  10148. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10149. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10150. //-----------Start : write to the Queue TransactionId file -----------------//
  10151. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10152. {}
  10153. else
  10154. {
  10155. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10156. if(log == NULL)
  10157. {
  10158. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10159. return ;
  10160. }
  10161. else
  10162. {
  10163. fclose(log);
  10164. }
  10165. }
  10166. // open file for writing
  10167. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10168. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10169. {
  10170. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10171. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10172. fputs(data, outfile);
  10173. fclose (outfile);
  10174. }
  10175. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10176. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10177. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10178. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10179. }
  10180. void handleStatusNotificationResponse(char *payload, int gun_index)
  10181. {
  10182. mtrace();
  10183. DEBUG_INFO("handleStatusNotificationResponse...\n");
  10184. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10185. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10186. }
  10187. void handleStopTransactionnResponse(char *payload, int gun_index)
  10188. {
  10189. mtrace();
  10190. DEBUG_INFO("handleStopTransactionnResponse...\n");
  10191. json_object *StopTransaction;
  10192. StopTransaction = json_tokener_parse(payload);
  10193. if(!is_error(StopTransaction))
  10194. {
  10195. // Optional data
  10196. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  10197. {
  10198. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  10199. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  10200. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  10201. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10202. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  10203. }
  10204. }
  10205. json_object_put(StopTransaction);
  10206. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10207. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10208. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10209. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10210. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10211. }
  10212. //==========================================
  10213. // Handle Error routine
  10214. //==========================================
  10215. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10216. {
  10217. mtrace();
  10218. #ifdef SystemLogMessage
  10219. DEBUG_INFO("errorCode: %s\n", errorCode);
  10220. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10221. DEBUG_INFO("errorDetails: %s\n", payload);
  10222. #endif
  10223. }
  10224. //===============================================
  10225. // Common routine
  10226. //===============================================
  10227. int initialConfigurationTable(void)
  10228. {
  10229. //clock_t start_t, end_t, total_t;
  10230. FILE *fp;
  10231. FILE *outfile;
  10232. char str[200]={0};
  10233. char sstr[100]={0};
  10234. int c = 0;
  10235. char *loc;
  10236. DEBUG_INFO("initialConfigurationTable...\n");
  10237. //start_t = clock();
  10238. //printf("Starting of the program, start_t = %ld\n", start_t);
  10239. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10240. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10241. {
  10242. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10243. if(outfile == NULL)
  10244. {
  10245. DEBUG_INFO("Error opening file\n");
  10246. return FALSE;
  10247. }
  10248. /*Core Profile*/
  10249. //AllowOfflineTxForUnknownId
  10250. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10253. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10254. //AuthorizationCacheEnabled
  10255. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10258. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10259. //AuthorizeRemoteTxRequests
  10260. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10263. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10264. //BlinkRepeat
  10265. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10268. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10269. //ClockAlignedDataInterval
  10270. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10271. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10273. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10274. //ConnectionTimeOut
  10275. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10278. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10279. //GetConfigurationMaxKeys
  10280. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10283. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10284. // HeartbeatInterval
  10285. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10288. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10289. // LightIntensity
  10290. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10293. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10294. // LocalAuthorizeOffline
  10295. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10298. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10299. // LocalPreAuthorize
  10300. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10303. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10304. // MaxEnergyOnInvalidId
  10305. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10308. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10309. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10310. // MeterValuesAlignedData
  10311. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10312. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10313. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10315. else
  10316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10318. // MeterValuesAlignedDataMaxLength
  10319. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10321. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10323. else
  10324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10325. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10326. // MeterValuesSampledData
  10327. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10329. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10331. else
  10332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10333. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10334. // MeterValuesSampledDataMaxLength
  10335. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10337. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10339. else
  10340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10341. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10342. // MeterValueSampleInterval
  10343. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10346. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10347. // MinimumStatusDuration
  10348. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10351. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10352. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10353. // NumberOfConnectors
  10354. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10356. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10357. {
  10358. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10359. }
  10360. else
  10361. {
  10362. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10363. }
  10364. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10365. // ResetRetries
  10366. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10370. // ConnectorPhaseRotation
  10371. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10375. // ConnectorPhaseRotationMaxLength
  10376. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10379. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10380. // StopTransactionOnEVSideDisconnect
  10381. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10384. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10385. // StopTransactionOnInvalidId
  10386. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10388. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10389. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10390. // StopTxnAlignedData
  10391. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10395. // StopTxnAlignedDataMaxLength
  10396. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10399. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10400. // StopTxnSampledData
  10401. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10403. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10404. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10405. else
  10406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10408. // StopTxnSampledDataMaxLength
  10409. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10411. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10412. {
  10413. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10414. }
  10415. else
  10416. {
  10417. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10418. }
  10419. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10420. // SupportedFeatureProfiles
  10421. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10423. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10425. // SupportedFeatureProfilesMaxLength
  10426. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10430. // TransactionMessageAttempts
  10431. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10432. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10434. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10435. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10436. // TransactionMessageRetryInterval
  10437. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10438. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10440. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10441. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10442. // UnlockConnectorOnEVSideDisconnect
  10443. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10445. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10446. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10447. // WebSocketPingInterval
  10448. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10451. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10452. // QueueOffLineStartTransactionMessage
  10453. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10456. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10457. //* Local Auth List Management Profile*/
  10458. #if 0
  10459. //For OCTT Test Case
  10460. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10461. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10463. #endif
  10464. #if 1
  10465. //LocalAuthListEnabled
  10466. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10467. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10469. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10470. #endif
  10471. //LocalAuthListMaxLength
  10472. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10475. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10476. //SendLocalListMaxLength
  10477. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10479. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10480. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10481. //ReserveConnectorZeroSupported
  10482. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10484. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10485. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10486. //* Smart Charging Profile */
  10487. //ChargeProfileMaxStackLevel
  10488. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10491. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10492. // ChargingScheduleAllowedChargingRateUnit
  10493. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10494. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10495. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10496. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10497. // ChargingScheduleMaxPeriods
  10498. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10499. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10501. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10502. // ConnectorSwitch3to1PhaseSupported
  10503. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10506. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10507. // MaxChargingProfilesInstalled
  10508. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10511. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10512. fclose(outfile);
  10513. }
  10514. else
  10515. {
  10516. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10517. char keystr[60]={0};
  10518. char readonlystr[10]={0};
  10519. char valuestr[100]={0};
  10520. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10521. if(fp == NULL) {
  10522. DEBUG_INFO("Error opening file");
  10523. return FALSE;
  10524. }
  10525. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10526. {
  10527. //DEBUG_INFO("Get Configuration \n");
  10528. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10529. //*************************key*********************************/
  10530. loc = strstr(str, "key");
  10531. c = 0;
  10532. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10533. while (loc[strlen("key")+3+c] != '\"')
  10534. {
  10535. sstr[c] = loc[strlen("key")+3+c];
  10536. c++;
  10537. }
  10538. sstr[c] = '\0';
  10539. strcpy(keystr,sstr);
  10540. //*************************readonly*********************************/
  10541. loc = strstr(str, "readonly");
  10542. c = 0;
  10543. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10544. while (loc[strlen("readonly")+2+c] != ',')
  10545. {
  10546. sstr[c] = loc[strlen("readonly")+2+c];
  10547. c++;
  10548. }
  10549. sstr[c] = '\0';
  10550. strcpy(readonlystr,sstr);
  10551. //*************************value*********************************/
  10552. loc = strstr(str, "value");
  10553. c = 0;
  10554. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10555. while (loc[strlen("value")+3+c] != '\"')
  10556. {
  10557. sstr[c] = loc[strlen("value")+3+c];
  10558. c++;
  10559. }
  10560. sstr[c] = '\0';
  10561. strcpy(valuestr,sstr);
  10562. // DEBUG_INFO("keystr=%s\n",keystr);
  10563. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10564. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10565. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10566. {
  10567. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10568. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10569. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10570. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10571. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10572. }
  10573. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10574. {
  10575. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10576. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10577. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10578. }
  10579. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10580. {
  10581. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10582. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10583. }
  10584. if(strcmp(keystr, "BlinkRepeat") == 0)
  10585. {
  10586. //Charger.BlinkRepeat = Integer.parseInt(value);
  10587. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10588. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10589. }
  10590. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10591. {
  10592. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10593. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10594. }
  10595. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10596. {
  10597. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10598. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10599. }
  10600. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10601. {
  10602. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10603. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10604. }
  10605. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10606. {
  10607. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10608. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10609. HeartBeatWaitTime = atoi(valuestr);
  10610. }
  10611. if(strcmp(keystr, "LightIntensity") == 0)
  10612. {
  10613. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10615. }
  10616. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10617. {
  10618. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10619. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10620. }
  10621. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10622. {
  10623. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10624. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10625. }
  10626. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10627. {
  10628. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10629. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10630. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10631. }
  10632. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10633. {
  10634. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10635. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10636. }
  10637. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10638. {
  10639. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10640. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10641. }
  10642. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10643. {
  10644. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10645. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10646. }
  10647. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10648. {
  10649. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10650. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10651. }
  10652. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10653. {
  10654. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10655. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10656. }
  10657. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10658. {
  10659. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10660. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10661. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10662. }
  10663. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10664. {
  10665. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10666. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10667. }
  10668. if(strcmp(keystr, "ResetRetries") == 0)
  10669. {
  10670. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10671. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10672. }
  10673. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10674. {
  10675. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10676. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10677. }
  10678. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10679. {
  10680. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10681. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10682. }
  10683. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10684. {
  10685. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10686. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10687. }
  10688. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10689. {
  10690. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10691. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10692. }
  10693. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10694. {
  10695. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10696. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10697. }
  10698. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10699. {
  10700. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10701. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10702. }
  10703. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10704. {
  10705. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10706. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10707. }
  10708. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10709. {
  10710. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10711. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10712. }
  10713. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10714. {
  10715. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10716. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10717. }
  10718. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10719. {
  10720. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10721. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10722. }
  10723. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10724. {
  10725. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10726. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10727. TransactionMessageAttemptsValue = atoi(valuestr);
  10728. }
  10729. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10730. {
  10731. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10732. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10733. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10734. }
  10735. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10736. {
  10737. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10738. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10739. }
  10740. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10741. {
  10742. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10743. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10744. }
  10745. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10746. {
  10747. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10748. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10749. }
  10750. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10751. {
  10752. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10753. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10754. }
  10755. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10756. {
  10757. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10758. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10759. }
  10760. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10761. {
  10762. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10763. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10764. }
  10765. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10766. {
  10767. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10768. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10769. }
  10770. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10771. {
  10772. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10773. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10774. }
  10775. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10776. {
  10777. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10778. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10779. }
  10780. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10781. {
  10782. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10783. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10784. }
  10785. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10786. {
  10787. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10788. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10789. }
  10790. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10791. {
  10792. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10793. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10794. }
  10795. }
  10796. fclose(fp);
  10797. }
  10798. return 0;
  10799. }
  10800. void StoreConfigurationTable(void)
  10801. {
  10802. FILE *outfile;
  10803. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10804. if(outfile == NULL)
  10805. {
  10806. DEBUG_INFO("Error opening file");
  10807. return ;
  10808. }
  10809. /*Core Profile*/
  10810. //AllowOfflineTxForUnknownId
  10811. /*
  10812. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10813. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10816. */
  10817. //DEBUG_INFO("data=%s\n",data);
  10818. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10819. //AuthorizationCacheEnabled
  10820. /*
  10821. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10824. */
  10825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10826. //AuthorizeRemoteTxRequests
  10827. /*
  10828. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10831. */
  10832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10833. //BlinkRepeat
  10834. /*
  10835. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10838. */
  10839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10840. //ClockAlignedDataInterval
  10841. /*
  10842. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10845. */
  10846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10847. //ConnectionTimeOut
  10848. /*
  10849. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10852. */
  10853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10854. //GetConfigurationMaxKeys
  10855. /*
  10856. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10859. */
  10860. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10861. // HeartbeatInterval
  10862. /*
  10863. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10866. */
  10867. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10868. // LightIntensity
  10869. /*
  10870. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10873. */
  10874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10875. // LocalAuthorizeOffline
  10876. /*
  10877. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10880. */
  10881. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10882. // LocalPreAuthorize
  10883. /*
  10884. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10885. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10887. */
  10888. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10889. // MaxEnergyOnInvalidId
  10890. /*
  10891. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10894. */
  10895. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10897. // MeterValuesAlignedData
  10898. /*
  10899. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10902. */
  10903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10904. // MeterValuesAlignedDataMaxLength
  10905. /*
  10906. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10909. */
  10910. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10911. // MeterValuesSampledData
  10912. /*
  10913. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10916. */
  10917. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10918. // MeterValuesSampledDataMaxLength
  10919. /*
  10920. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10923. */
  10924. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10925. // MeterValueSampleInterval
  10926. /*
  10927. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10928. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10930. */
  10931. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10932. // MinimumStatusDuration
  10933. /*
  10934. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10937. */
  10938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10939. // NumberOfConnectors
  10940. /*
  10941. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10943. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10944. {
  10945. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10946. }
  10947. else
  10948. {
  10949. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10950. }
  10951. */
  10952. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10953. // ResetRetries
  10954. /*
  10955. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10958. */
  10959. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10960. // ConnectorPhaseRotation
  10961. /*
  10962. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10965. */
  10966. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10967. // ConnectorPhaseRotationMaxLength
  10968. /*
  10969. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10970. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10972. */
  10973. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10974. // StopTransactionOnEVSideDisconnect
  10975. /*
  10976. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10979. */
  10980. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10981. // StopTransactionOnInvalidId
  10982. /*
  10983. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10986. */
  10987. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10988. // StopTxnAlignedData
  10989. /*
  10990. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10993. */
  10994. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10995. // StopTxnAlignedDataMaxLength
  10996. /*
  10997. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11000. */
  11001. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11002. // StopTxnSampledData
  11003. /*
  11004. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  11007. */
  11008. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11009. // StopTxnSampledDataMaxLength
  11010. /*
  11011. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  11014. */
  11015. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11016. // SupportedFeatureProfiles
  11017. /*
  11018. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11021. */
  11022. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11023. // SupportedFeatureProfilesMaxLength
  11024. /*
  11025. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11028. */
  11029. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11030. // TransactionMessageAttempts
  11031. /*
  11032. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11035. */
  11036. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11037. // TransactionMessageRetryInterval
  11038. /*
  11039. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11042. */
  11043. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11044. // UnlockConnectorOnEVSideDisconnect
  11045. /*
  11046. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11049. */
  11050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11051. // WebSocketPingInterval
  11052. /*
  11053. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11056. */
  11057. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11058. // QueueOffLineStartTransactionMessage
  11059. /*
  11060. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  11061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11063. */
  11064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11065. //* Local Auth List Management Profile*/
  11066. //LocalAuthListEnabled
  11067. /*
  11068. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11071. */
  11072. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11073. //LocalAuthListMaxLength
  11074. /*
  11075. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11078. */
  11079. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11080. //SendLocalListMaxLength
  11081. /*
  11082. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  11085. */
  11086. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11087. //ReserveConnectorZeroSupported
  11088. /*
  11089. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11092. */
  11093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11094. //* Smart Charging Profile */
  11095. //ChargeProfileMaxStackLevel
  11096. /*
  11097. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11100. */
  11101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11102. // ChargingScheduleAllowedChargingRateUnit
  11103. /*
  11104. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11107. */
  11108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11109. // ChargingScheduleMaxPeriods
  11110. /*
  11111. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11114. */
  11115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11116. // ConnectorSwitch3to1PhaseSupported
  11117. /*
  11118. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11121. */
  11122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11123. // MaxChargingProfilesInstalled
  11124. /*
  11125. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  11128. */
  11129. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11130. fclose(outfile);
  11131. }
  11132. void getKeyValue(char *keyReq)
  11133. {
  11134. int isEmpty = FALSE;
  11135. int isKnowKey = FALSE;
  11136. DEBUG_INFO("keyReq = %s\n", keyReq);
  11137. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11138. isEmpty = TRUE;
  11139. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11140. {
  11141. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11143. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11144. {
  11145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11146. }
  11147. else
  11148. {
  11149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11150. }
  11151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11152. isKnowKey = TRUE;
  11153. }
  11154. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11155. {
  11156. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11158. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11159. {
  11160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11161. }
  11162. else
  11163. {
  11164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11165. }
  11166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11167. isKnowKey = TRUE;
  11168. }
  11169. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11170. {
  11171. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11173. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11174. {
  11175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11176. }
  11177. else
  11178. {
  11179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11180. }
  11181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11182. isKnowKey = TRUE;
  11183. }
  11184. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11185. {
  11186. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11188. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11189. {
  11190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11191. }
  11192. else
  11193. {
  11194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11195. }
  11196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11197. isKnowKey = TRUE;
  11198. }
  11199. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11200. {
  11201. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11203. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11204. {
  11205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11206. }
  11207. else
  11208. {
  11209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11210. }
  11211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11212. isKnowKey = TRUE;
  11213. }
  11214. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11215. {
  11216. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11218. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11219. {
  11220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11221. }
  11222. else
  11223. {
  11224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11225. }
  11226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11227. isKnowKey = TRUE;
  11228. }
  11229. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11230. {
  11231. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11233. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11234. {
  11235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11236. }
  11237. else
  11238. {
  11239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11240. }
  11241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11242. isKnowKey = TRUE;
  11243. }
  11244. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11245. {
  11246. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11248. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11249. {
  11250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11251. }
  11252. else
  11253. {
  11254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11255. }
  11256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11257. isKnowKey = TRUE;
  11258. }
  11259. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11260. {
  11261. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11263. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11264. {
  11265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11266. }
  11267. else
  11268. {
  11269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11270. }
  11271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11272. isKnowKey = TRUE;
  11273. }
  11274. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11275. {
  11276. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11278. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11279. {
  11280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11281. }
  11282. else
  11283. {
  11284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11285. }
  11286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11287. isKnowKey = TRUE;
  11288. }
  11289. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11290. {
  11291. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11293. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11294. {
  11295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11296. }
  11297. else
  11298. {
  11299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11300. }
  11301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11302. isKnowKey = TRUE;
  11303. }
  11304. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11305. {
  11306. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11308. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11309. {
  11310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11311. }
  11312. else
  11313. {
  11314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11315. }
  11316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11317. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11318. isKnowKey = TRUE;
  11319. }
  11320. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11321. {
  11322. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11324. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11325. {
  11326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11327. }
  11328. else
  11329. {
  11330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11331. }
  11332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11333. isKnowKey = TRUE;
  11334. }
  11335. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11336. {
  11337. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11339. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11340. {
  11341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11342. }
  11343. else
  11344. {
  11345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11346. }
  11347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11348. isKnowKey = TRUE;
  11349. }
  11350. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11351. {
  11352. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11354. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11355. {
  11356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11357. }
  11358. else
  11359. {
  11360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11361. }
  11362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11363. isKnowKey = TRUE;
  11364. }
  11365. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11366. {
  11367. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11369. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11370. {
  11371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11372. }
  11373. else
  11374. {
  11375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11376. }
  11377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11378. isKnowKey = TRUE;
  11379. }
  11380. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11381. {
  11382. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11384. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11385. {
  11386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11387. }
  11388. else
  11389. {
  11390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11391. }
  11392. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11393. isKnowKey = TRUE;
  11394. }
  11395. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11396. {
  11397. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11399. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11400. {
  11401. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11402. }
  11403. else
  11404. {
  11405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11406. }
  11407. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11408. isKnowKey = TRUE;
  11409. }
  11410. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11411. {
  11412. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11414. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11415. {
  11416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11417. }
  11418. else
  11419. {
  11420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11421. }
  11422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11423. isKnowKey = TRUE;
  11424. }
  11425. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11426. {
  11427. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11429. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11430. {
  11431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11432. }
  11433. else
  11434. {
  11435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11436. }
  11437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11438. isKnowKey = TRUE;
  11439. }
  11440. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11441. {
  11442. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11444. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11445. {
  11446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11447. }
  11448. else
  11449. {
  11450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11451. }
  11452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11453. isKnowKey = TRUE;
  11454. }
  11455. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11456. {
  11457. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11459. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11460. {
  11461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11462. }
  11463. else
  11464. {
  11465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11466. }
  11467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11468. isKnowKey = TRUE;
  11469. }
  11470. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11471. {
  11472. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11474. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11475. {
  11476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11477. }
  11478. else
  11479. {
  11480. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11481. }
  11482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11483. isKnowKey = TRUE;
  11484. }
  11485. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11486. {
  11487. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11489. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11490. {
  11491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11492. }
  11493. else
  11494. {
  11495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11496. }
  11497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11498. isKnowKey = TRUE;
  11499. }
  11500. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11501. {
  11502. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11504. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11505. {
  11506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11507. }
  11508. else
  11509. {
  11510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11511. }
  11512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11513. isKnowKey = TRUE;
  11514. }
  11515. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11516. {
  11517. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11519. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11520. {
  11521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11522. }
  11523. else
  11524. {
  11525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11526. }
  11527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11528. isKnowKey = TRUE;
  11529. }
  11530. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11531. {
  11532. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11534. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11535. {
  11536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11537. }
  11538. else
  11539. {
  11540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11541. }
  11542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11543. isKnowKey = TRUE;
  11544. }
  11545. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11546. {
  11547. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11549. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11550. {
  11551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11552. }
  11553. else
  11554. {
  11555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11556. }
  11557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11558. isKnowKey = TRUE;
  11559. }
  11560. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11561. {
  11562. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11564. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11565. {
  11566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11567. }
  11568. else
  11569. {
  11570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11571. }
  11572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11573. isKnowKey = TRUE;
  11574. }
  11575. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11576. {
  11577. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11579. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11580. {
  11581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11582. }
  11583. else
  11584. {
  11585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11586. }
  11587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11588. isKnowKey = TRUE;
  11589. }
  11590. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11591. {
  11592. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11594. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11595. {
  11596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11597. }
  11598. else
  11599. {
  11600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11601. }
  11602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11603. isKnowKey = TRUE;
  11604. }
  11605. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11606. {
  11607. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11609. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11610. {
  11611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11612. }
  11613. else
  11614. {
  11615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11616. }
  11617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11618. isKnowKey = TRUE;
  11619. }
  11620. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11621. {
  11622. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11624. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11625. {
  11626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11627. }
  11628. else
  11629. {
  11630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11631. }
  11632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11633. isKnowKey = TRUE;
  11634. }
  11635. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11636. {
  11637. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11639. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11640. {
  11641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11642. }
  11643. else
  11644. {
  11645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11646. }
  11647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11648. isKnowKey = TRUE;
  11649. }
  11650. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11651. {
  11652. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11654. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11655. {
  11656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11657. }
  11658. else
  11659. {
  11660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11661. }
  11662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11663. isKnowKey = TRUE;
  11664. }
  11665. #if 1
  11666. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11667. {
  11668. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11670. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11671. {
  11672. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11673. }
  11674. else
  11675. {
  11676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11677. }
  11678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11679. isKnowKey = TRUE;
  11680. }
  11681. #endif
  11682. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11683. {
  11684. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11686. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11687. {
  11688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11689. }
  11690. else
  11691. {
  11692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11693. }
  11694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11695. isKnowKey = TRUE;
  11696. }
  11697. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11698. {
  11699. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11701. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11702. {
  11703. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11704. }
  11705. else
  11706. {
  11707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11708. }
  11709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11710. isKnowKey = TRUE;
  11711. }
  11712. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11713. {
  11714. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11716. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11717. {
  11718. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11719. }
  11720. else
  11721. {
  11722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11723. }
  11724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11725. isKnowKey = TRUE;
  11726. }
  11727. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11728. {
  11729. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11731. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11732. {
  11733. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11734. }
  11735. else
  11736. {
  11737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11738. }
  11739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11740. isKnowKey = TRUE;
  11741. }
  11742. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11743. {
  11744. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11746. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11747. {
  11748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11749. }
  11750. else
  11751. {
  11752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11753. }
  11754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11755. isKnowKey = TRUE;
  11756. }
  11757. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11758. {
  11759. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11761. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11762. {
  11763. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11764. }
  11765. else
  11766. {
  11767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11768. }
  11769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11770. isKnowKey = TRUE;
  11771. }
  11772. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11773. {
  11774. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11776. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11777. {
  11778. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11779. }
  11780. else
  11781. {
  11782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11783. }
  11784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11785. isKnowKey = TRUE;
  11786. }
  11787. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11788. {
  11789. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11791. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11792. {
  11793. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11794. }
  11795. else
  11796. {
  11797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11798. }
  11799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11800. isKnowKey = TRUE;
  11801. }
  11802. //=========================================================
  11803. if(!isEmpty && !isKnowKey)
  11804. {
  11805. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11806. strcpy(unknownkey[UnknownKeynum], keyReq);
  11807. UnknownKeynum = UnknownKeynum + 1;
  11808. }
  11809. }
  11810. void processUnkownKey(void)
  11811. {
  11812. DEBUG_INFO("processUnkownKey...\n");
  11813. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11814. for(int index=0; index < UnknownKeynum; index++)
  11815. {
  11816. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11817. {
  11818. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11819. }
  11820. }
  11821. }
  11822. int setKeyValue(char *key, char *value)
  11823. {
  11824. int isSuccess = NotSupported;
  11825. int check_ascii=0;
  11826. char str[10]={0};
  11827. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11828. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11829. {
  11830. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11831. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11832. {
  11833. strcpy(str, (const char*)value);
  11834. for(int i = 0; str[i]; i++){
  11835. str[i] = tolower(str[i]);
  11836. }
  11837. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11838. isSuccess = ConfigurationStatus_Accepted;
  11839. }
  11840. else
  11841. {
  11842. isSuccess = ConfigurationStatus_Rejected;
  11843. }
  11844. }
  11845. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11846. {
  11847. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11848. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11849. {
  11850. strcpy(str, (const char*)value);
  11851. for(int i = 0; str[i]; i++){
  11852. str[i] = tolower(str[i]);
  11853. }
  11854. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11855. isSuccess = ConfigurationStatus_Accepted;
  11856. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11857. }
  11858. else
  11859. {
  11860. isSuccess = ConfigurationStatus_Rejected;
  11861. }
  11862. }
  11863. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11864. {
  11865. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11866. {
  11867. strcpy(str, (const char*)value);
  11868. for(int i = 0; str[i]; i++)
  11869. {
  11870. str[i] = tolower(str[i]);
  11871. }
  11872. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11873. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11874. isSuccess = ConfigurationStatus_Accepted;
  11875. }
  11876. else
  11877. {
  11878. isSuccess = ConfigurationStatus_Rejected;
  11879. }
  11880. }
  11881. if(strcmp(key, "BlinkRepeat") == 0)
  11882. {
  11883. //Charger.BlinkRepeat = Integer.parseInt(value);
  11884. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11885. {
  11886. check_ascii = value[0];
  11887. if( (check_ascii < 48) || (check_ascii > 57) )
  11888. {
  11889. isSuccess = ConfigurationStatus_Rejected;
  11890. }
  11891. else
  11892. {
  11893. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11894. isSuccess = ConfigurationStatus_Accepted;
  11895. }
  11896. }
  11897. else
  11898. {
  11899. isSuccess = ConfigurationStatus_Rejected;
  11900. }
  11901. }
  11902. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11903. {
  11904. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11905. {
  11906. check_ascii = value[0];
  11907. if( (check_ascii < 48) || (check_ascii > 57) )
  11908. {
  11909. isSuccess = ConfigurationStatus_Rejected;
  11910. }
  11911. else
  11912. {
  11913. if((atoi(value) == 0) || (atoi(value) >= 10))
  11914. {
  11915. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11916. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11917. isSuccess = ConfigurationStatus_Accepted;
  11918. }
  11919. else
  11920. isSuccess = ConfigurationStatus_Rejected;
  11921. }
  11922. }
  11923. else
  11924. {
  11925. isSuccess = ConfigurationStatus_Rejected;
  11926. }
  11927. }
  11928. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11929. {
  11930. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11931. {
  11932. check_ascii = value[0];
  11933. if( (check_ascii < 48) || (check_ascii > 57) )
  11934. {
  11935. isSuccess = ConfigurationStatus_Rejected;
  11936. }
  11937. else
  11938. {
  11939. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11940. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11941. isSuccess = ConfigurationStatus_Accepted;
  11942. }
  11943. }
  11944. else
  11945. {
  11946. isSuccess = ConfigurationStatus_Rejected;
  11947. }
  11948. }
  11949. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11950. {
  11951. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11952. {
  11953. check_ascii = value[0];
  11954. if( (check_ascii < 48) || (check_ascii > 57) )
  11955. {
  11956. isSuccess = ConfigurationStatus_Rejected;
  11957. }
  11958. else
  11959. {
  11960. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11961. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11962. isSuccess = ConfigurationStatus_Accepted;
  11963. }
  11964. }
  11965. else
  11966. {
  11967. isSuccess = ConfigurationStatus_Rejected;
  11968. }
  11969. }
  11970. if(strcmp(key, "HeartbeatInterval") == 0)
  11971. {
  11972. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11973. {
  11974. check_ascii = value[0];
  11975. if( (check_ascii < 48) || (check_ascii > 57) )
  11976. {
  11977. isSuccess = ConfigurationStatus_Rejected;
  11978. }
  11979. else
  11980. {
  11981. if((atoi(value) == 0) || (atoi(value) >= 10))
  11982. {
  11983. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11984. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11985. HeartBeatWaitTime = atoi(value);
  11986. isSuccess = ConfigurationStatus_Accepted;
  11987. }
  11988. else
  11989. {
  11990. isSuccess = ConfigurationStatus_Rejected;
  11991. }
  11992. }
  11993. }
  11994. else
  11995. {
  11996. isSuccess = ConfigurationStatus_Rejected;
  11997. }
  11998. }
  11999. if(strcmp(key, "LightIntensity") == 0)
  12000. {
  12001. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12002. {
  12003. check_ascii = value[0];
  12004. if( (check_ascii < 48) || (check_ascii > 57) )
  12005. {
  12006. isSuccess = ConfigurationStatus_Rejected;
  12007. }
  12008. else
  12009. {
  12010. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  12011. isSuccess = ConfigurationStatus_Accepted;
  12012. }
  12013. }
  12014. else
  12015. {
  12016. isSuccess = ConfigurationStatus_Rejected;
  12017. }
  12018. }
  12019. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  12020. {
  12021. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12022. {
  12023. strcpy(str, (const char*)value);
  12024. for(int i = 0; str[i]; i++)
  12025. {
  12026. str[i] = tolower(str[i]);
  12027. }
  12028. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12029. isSuccess = ConfigurationStatus_Accepted;
  12030. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12031. }
  12032. else
  12033. {
  12034. isSuccess = ConfigurationStatus_Rejected;
  12035. }
  12036. }
  12037. if(strcmp(key, "LocalPreAuthorize") == 0)
  12038. {
  12039. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12040. {
  12041. strcpy(str, (const char*)value);
  12042. for(int i = 0; str[i]; i++)
  12043. {
  12044. str[i] = tolower(str[i]);
  12045. }
  12046. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12047. isSuccess = ConfigurationStatus_Accepted;
  12048. }
  12049. else
  12050. {
  12051. isSuccess = ConfigurationStatus_Rejected;
  12052. }
  12053. }
  12054. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  12055. {
  12056. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12057. {
  12058. check_ascii = value[0];
  12059. if( (check_ascii < 48) || (check_ascii > 57) )
  12060. {
  12061. isSuccess = ConfigurationStatus_Rejected;
  12062. }
  12063. else
  12064. {
  12065. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  12066. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  12067. isSuccess = ConfigurationStatus_Accepted;
  12068. }
  12069. }
  12070. else
  12071. {
  12072. isSuccess = ConfigurationStatus_Rejected;
  12073. }
  12074. }
  12075. if(strcmp(key, "MeterValuesAlignedData") == 0)
  12076. {
  12077. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12078. {
  12079. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  12080. isSuccess = ConfigurationStatus_Accepted;
  12081. }
  12082. else
  12083. {
  12084. isSuccess = ConfigurationStatus_Rejected;
  12085. }
  12086. }
  12087. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  12088. {
  12089. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12090. {
  12091. check_ascii = value[0];
  12092. if( (check_ascii < 48) || (check_ascii > 57) )
  12093. {
  12094. isSuccess = ConfigurationStatus_Rejected;
  12095. }
  12096. else
  12097. {
  12098. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12099. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  12100. isSuccess = ConfigurationStatus_Accepted;
  12101. }
  12102. }
  12103. else
  12104. {
  12105. isSuccess = ConfigurationStatus_Rejected;
  12106. }
  12107. }
  12108. if(strcmp(key, "MeterValuesSampledData") == 0 )
  12109. {
  12110. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12111. {
  12112. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  12113. isSuccess = ConfigurationStatus_Accepted;
  12114. }
  12115. else
  12116. {
  12117. isSuccess = ConfigurationStatus_Rejected;
  12118. }
  12119. }
  12120. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  12121. {
  12122. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12123. {
  12124. check_ascii = value[0];
  12125. if( (check_ascii < 48) || (check_ascii > 57) )
  12126. {
  12127. isSuccess = ConfigurationStatus_Rejected;
  12128. }
  12129. else
  12130. {
  12131. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12132. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12133. isSuccess = ConfigurationStatus_Accepted;
  12134. }
  12135. }
  12136. else
  12137. {
  12138. isSuccess = ConfigurationStatus_Rejected;
  12139. }
  12140. }
  12141. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12142. {
  12143. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12144. {
  12145. check_ascii = value[0];
  12146. if( (check_ascii < 48) || (check_ascii > 57) )
  12147. {
  12148. isSuccess = ConfigurationStatus_Rejected;
  12149. }
  12150. else
  12151. {
  12152. if((atoi(value) == 0) || (atoi(value) >= 10))
  12153. {
  12154. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12155. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12156. isSuccess = ConfigurationStatus_Accepted;
  12157. }
  12158. else
  12159. {
  12160. isSuccess = ConfigurationStatus_Rejected;
  12161. }
  12162. }
  12163. }
  12164. else
  12165. {
  12166. isSuccess = ConfigurationStatus_Rejected;
  12167. }
  12168. }
  12169. if(strcmp(key, "MinimumStatusDuration") == 0)
  12170. {
  12171. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12172. {
  12173. check_ascii = value[0];
  12174. if( (check_ascii < 48) || (check_ascii > 57) )
  12175. {
  12176. isSuccess = ConfigurationStatus_Rejected;
  12177. }
  12178. else
  12179. {
  12180. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12181. {
  12182. isSuccess = ConfigurationStatus_Rejected;
  12183. }
  12184. else
  12185. {
  12186. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12187. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12188. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12189. isSuccess = ConfigurationStatus_Accepted;
  12190. }
  12191. }
  12192. }
  12193. else
  12194. {
  12195. isSuccess = ConfigurationStatus_Rejected;
  12196. }
  12197. }
  12198. if(strcmp(key, "NumberOfConnectors") == 0)
  12199. {
  12200. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12201. {
  12202. check_ascii = value[0];
  12203. if( (check_ascii < 48) || (check_ascii > 57) )
  12204. {
  12205. isSuccess = ConfigurationStatus_Rejected;
  12206. }
  12207. else
  12208. {
  12209. //Charger.ResetRetries = Integer.parseInt(value);
  12210. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12211. isSuccess = ConfigurationStatus_Accepted;
  12212. }
  12213. }
  12214. else
  12215. {
  12216. isSuccess = ConfigurationStatus_Rejected;
  12217. }
  12218. }
  12219. if(strcmp(key, "ResetRetries") == 0)
  12220. {
  12221. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12222. {
  12223. check_ascii = value[0];
  12224. if( (check_ascii < 48) || (check_ascii > 57) )
  12225. {
  12226. isSuccess = ConfigurationStatus_Rejected;
  12227. }
  12228. else
  12229. {
  12230. //Charger.ResetRetries = Integer.parseInt(value);
  12231. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12232. isSuccess = ConfigurationStatus_Accepted;
  12233. }
  12234. }
  12235. else
  12236. {
  12237. isSuccess = ConfigurationStatus_Rejected;
  12238. }
  12239. }
  12240. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12241. {
  12242. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12243. {
  12244. strcpy(str, (const char*)value);
  12245. for(int i = 0; str[i]; i++)
  12246. {
  12247. str[i] = tolower(str[i]);
  12248. }
  12249. if(strcmp(str, "notapplicable")== 0)
  12250. {
  12251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12252. isSuccess = ConfigurationStatus_Accepted;
  12253. }
  12254. else if(strcmp(str, "unknown")== 0)
  12255. {
  12256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12257. isSuccess = ConfigurationStatus_Accepted;
  12258. }
  12259. else if(strcmp(str, "rst")== 0)
  12260. {
  12261. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12262. isSuccess = ConfigurationStatus_Accepted;
  12263. }
  12264. else if(strcmp(str, "rts")== 0)
  12265. {
  12266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12267. isSuccess = ConfigurationStatus_Accepted;
  12268. }
  12269. else if(strcmp(str, "srt")== 0)
  12270. {
  12271. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12272. isSuccess = ConfigurationStatus_Accepted;
  12273. }
  12274. else if(strcmp(str, "str")== 0)
  12275. {
  12276. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12277. isSuccess = ConfigurationStatus_Accepted;
  12278. }
  12279. else if(strcmp(str, "trs")== 0)
  12280. {
  12281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12282. isSuccess = ConfigurationStatus_Accepted;
  12283. }
  12284. else if(strcmp(str, "tsr")== 0)
  12285. {
  12286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12287. isSuccess = ConfigurationStatus_Accepted;
  12288. }
  12289. else
  12290. {
  12291. isSuccess = ConfigurationStatus_Rejected;
  12292. }
  12293. }
  12294. else
  12295. {
  12296. isSuccess = ConfigurationStatus_Rejected;
  12297. }
  12298. }
  12299. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12300. {
  12301. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12302. {
  12303. check_ascii = value[0];
  12304. if( (check_ascii < 48) || (check_ascii > 57) )
  12305. {
  12306. isSuccess = ConfigurationStatus_Rejected;
  12307. }
  12308. else
  12309. {
  12310. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12311. isSuccess = ConfigurationStatus_Accepted;
  12312. }
  12313. }
  12314. else
  12315. {
  12316. isSuccess = ConfigurationStatus_Rejected;
  12317. }
  12318. }
  12319. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12320. {
  12321. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12322. {
  12323. strcpy(str, (const char*)value);
  12324. for(int i = 0; str[i]; i++)
  12325. {
  12326. str[i] = tolower(str[i]);
  12327. }
  12328. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12329. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12330. isSuccess = ConfigurationStatus_Accepted;
  12331. }
  12332. else
  12333. {
  12334. isSuccess = ConfigurationStatus_Rejected;
  12335. }
  12336. }
  12337. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12338. {
  12339. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12340. {
  12341. strcpy(str, (const char*)value);
  12342. for(int i = 0; str[i]; i++)
  12343. {
  12344. str[i] = tolower(str[i]);
  12345. }
  12346. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12347. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12348. isSuccess = ConfigurationStatus_Accepted;
  12349. }
  12350. else
  12351. {
  12352. isSuccess = ConfigurationStatus_Rejected;
  12353. }
  12354. }
  12355. if(strcmp(key, "StopTxnAlignedData") == 0)
  12356. {
  12357. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12358. {
  12359. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12360. isSuccess = ConfigurationStatus_Accepted;
  12361. }
  12362. else
  12363. {
  12364. isSuccess = ConfigurationStatus_Rejected;
  12365. }
  12366. }
  12367. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12368. {
  12369. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12370. {
  12371. check_ascii = value[0];
  12372. if( (check_ascii < 48) || (check_ascii > 57) )
  12373. {
  12374. isSuccess = ConfigurationStatus_Rejected;
  12375. }
  12376. else
  12377. {
  12378. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12379. isSuccess = ConfigurationStatus_Accepted;
  12380. }
  12381. }
  12382. else
  12383. {
  12384. isSuccess = ConfigurationStatus_Rejected;
  12385. }
  12386. }
  12387. if(strcmp(key, "StopTxnSampledData") == 0)
  12388. {
  12389. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12390. {
  12391. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12392. isSuccess = ConfigurationStatus_Accepted;
  12393. }
  12394. else
  12395. {
  12396. isSuccess = ConfigurationStatus_Rejected;
  12397. }
  12398. }
  12399. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12400. {
  12401. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12402. {
  12403. check_ascii = value[0];
  12404. if( (check_ascii < 48) || (check_ascii > 57) )
  12405. {
  12406. isSuccess = ConfigurationStatus_Rejected;
  12407. }
  12408. else
  12409. {
  12410. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12411. isSuccess = ConfigurationStatus_Accepted;
  12412. }
  12413. }
  12414. else
  12415. {
  12416. isSuccess = ConfigurationStatus_Rejected;
  12417. }
  12418. }
  12419. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12420. {
  12421. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12422. {
  12423. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12424. isSuccess = ConfigurationStatus_Accepted;
  12425. }
  12426. else
  12427. {
  12428. isSuccess = ConfigurationStatus_Rejected;
  12429. }
  12430. }
  12431. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12432. {
  12433. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12434. {
  12435. check_ascii = value[0];
  12436. if( (check_ascii < 48) || (check_ascii > 57) )
  12437. {
  12438. isSuccess = ConfigurationStatus_Rejected;
  12439. }
  12440. else
  12441. {
  12442. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12443. isSuccess = ConfigurationStatus_Accepted;
  12444. }
  12445. }
  12446. else
  12447. {
  12448. isSuccess = ConfigurationStatus_Rejected;
  12449. }
  12450. }
  12451. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12452. {
  12453. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12454. {
  12455. check_ascii = value[0];
  12456. if( (check_ascii < 48) || (check_ascii > 57) )
  12457. {
  12458. isSuccess = ConfigurationStatus_Rejected;
  12459. }
  12460. else
  12461. {
  12462. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12463. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12464. TransactionMessageAttemptsValue = atoi(value);
  12465. isSuccess = ConfigurationStatus_Accepted;
  12466. }
  12467. }
  12468. else
  12469. {
  12470. isSuccess = ConfigurationStatus_Rejected;
  12471. }
  12472. }
  12473. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12474. {
  12475. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12476. {
  12477. check_ascii = value[0];
  12478. if( (check_ascii < 48) || (check_ascii > 57) )
  12479. {
  12480. isSuccess = ConfigurationStatus_Rejected;
  12481. }
  12482. else
  12483. {
  12484. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12485. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12486. TransactionMessageRetryIntervalValue = atoi(value);
  12487. isSuccess = ConfigurationStatus_Accepted;
  12488. }
  12489. }
  12490. else
  12491. {
  12492. isSuccess = ConfigurationStatus_Rejected;
  12493. }
  12494. }
  12495. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12496. {
  12497. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12498. {
  12499. strcpy(str, (const char*)value);
  12500. for(int i = 0; str[i]; i++)
  12501. {
  12502. str[i] = tolower(str[i]);
  12503. }
  12504. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12505. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12506. isSuccess = ConfigurationStatus_Accepted;
  12507. }
  12508. else
  12509. {
  12510. isSuccess = ConfigurationStatus_Rejected;
  12511. }
  12512. }
  12513. if(strcmp(key, "WebSocketPingInterval") == 0)
  12514. {
  12515. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12516. {
  12517. check_ascii = value[0];
  12518. if( (check_ascii < 48) || (check_ascii > 57) )
  12519. {
  12520. isSuccess = ConfigurationStatus_Rejected;
  12521. }
  12522. else
  12523. {
  12524. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12525. isSuccess = ConfigurationStatus_Accepted;
  12526. }
  12527. }
  12528. else
  12529. {
  12530. isSuccess = ConfigurationStatus_Rejected;
  12531. }
  12532. }
  12533. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12534. {
  12535. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12536. {
  12537. strcpy(str, (const char*)value);
  12538. for(int i = 0; str[i]; i++)
  12539. {
  12540. str[i] = tolower(str[i]);
  12541. }
  12542. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12543. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12544. isSuccess = ConfigurationStatus_Accepted;
  12545. }
  12546. else
  12547. {
  12548. isSuccess = ConfigurationStatus_Rejected;
  12549. }
  12550. }
  12551. #if 0
  12552. //For OCPP Test Case
  12553. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12554. {
  12555. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12556. {
  12557. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12558. isSuccess = ConfigurationStatus_Accepted;
  12559. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12560. }
  12561. else
  12562. {
  12563. isSuccess = ConfigurationStatus_Rejected;
  12564. }
  12565. }
  12566. #endif
  12567. #if 1
  12568. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12569. {
  12570. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12571. {
  12572. strcpy(str, (const char*)value);
  12573. for(int i = 0; str[i]; i++)
  12574. {
  12575. str[i] = tolower(str[i]);
  12576. }
  12577. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12578. isSuccess = ConfigurationStatus_Accepted;
  12579. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12580. }
  12581. else
  12582. {
  12583. isSuccess = ConfigurationStatus_Rejected;
  12584. }
  12585. }
  12586. #endif
  12587. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12588. {
  12589. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12590. {
  12591. check_ascii = value[0];
  12592. if( (check_ascii < 48) || (check_ascii > 57) )
  12593. {
  12594. isSuccess = ConfigurationStatus_Rejected;
  12595. }
  12596. else
  12597. {
  12598. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12599. isSuccess = ConfigurationStatus_Accepted;
  12600. }
  12601. }
  12602. else
  12603. {
  12604. isSuccess = ConfigurationStatus_Rejected;
  12605. }
  12606. }
  12607. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12608. {
  12609. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12610. {
  12611. check_ascii = value[0];
  12612. if( (check_ascii < 48) || (check_ascii > 57) )
  12613. {
  12614. isSuccess = ConfigurationStatus_Rejected;
  12615. }
  12616. else
  12617. {
  12618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12619. isSuccess = ConfigurationStatus_Accepted;
  12620. }
  12621. }
  12622. else
  12623. {
  12624. isSuccess = ConfigurationStatus_Rejected;
  12625. }
  12626. }
  12627. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12628. {
  12629. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12630. {
  12631. strcpy(str, (const char*)value);
  12632. for(int i = 0; str[i]; i++)
  12633. {
  12634. str[i] = tolower(str[i]);
  12635. }
  12636. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12637. isSuccess = ConfigurationStatus_Accepted;
  12638. }
  12639. else
  12640. {
  12641. isSuccess = ConfigurationStatus_Rejected;
  12642. }
  12643. }
  12644. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12645. {
  12646. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12647. {
  12648. check_ascii = value[0];
  12649. if( (check_ascii < 48) || (check_ascii > 57) )
  12650. {
  12651. isSuccess = ConfigurationStatus_Rejected;
  12652. }
  12653. else
  12654. {
  12655. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12656. isSuccess = ConfigurationStatus_Accepted;
  12657. }
  12658. }
  12659. else
  12660. {
  12661. isSuccess = ConfigurationStatus_Rejected;
  12662. }
  12663. }
  12664. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12665. {
  12666. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12667. {
  12668. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12669. isSuccess = ConfigurationStatus_Accepted;
  12670. }
  12671. else
  12672. {
  12673. isSuccess = ConfigurationStatus_Rejected;
  12674. }
  12675. }
  12676. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12677. {
  12678. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12679. {
  12680. check_ascii = value[0];
  12681. if( (check_ascii < 48) || (check_ascii > 57) )
  12682. {
  12683. isSuccess = ConfigurationStatus_Rejected;
  12684. }
  12685. else
  12686. {
  12687. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12688. isSuccess = ConfigurationStatus_Accepted;
  12689. }
  12690. }
  12691. else
  12692. {
  12693. isSuccess = ConfigurationStatus_Rejected;
  12694. }
  12695. }
  12696. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12697. {
  12698. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12699. {
  12700. strcpy(str, (const char*)value);
  12701. for(int i = 0; str[i]; i++)
  12702. {
  12703. str[i] = tolower(str[i]);
  12704. }
  12705. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12706. isSuccess = ConfigurationStatus_Accepted;
  12707. }
  12708. else
  12709. {
  12710. isSuccess = ConfigurationStatus_Rejected;
  12711. }
  12712. }
  12713. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12714. {
  12715. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12716. {
  12717. check_ascii = value[0];
  12718. if( (check_ascii < 48) || (check_ascii > 57) )
  12719. {
  12720. isSuccess = ConfigurationStatus_Rejected;
  12721. }
  12722. else
  12723. {
  12724. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12725. isSuccess = ConfigurationStatus_Accepted;
  12726. }
  12727. }
  12728. else
  12729. {
  12730. isSuccess = ConfigurationStatus_Rejected;
  12731. }
  12732. }
  12733. return isSuccess;
  12734. }
  12735. int TransactionMessageAttemptsGet(void)
  12736. {
  12737. return TransactionMessageAttemptsValue;
  12738. }
  12739. int FirstHeartBeatResponse(void)
  12740. {
  12741. return FirstHeartBeat;
  12742. }
  12743. int TransactionMessageRetryIntervalGet(void)
  12744. {
  12745. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12746. }
  12747. int ReadHttpStatus(int sock)
  12748. {
  12749. //char c;
  12750. char buff[1024]="",*ptr=buff+1;
  12751. int bytes_received, status;
  12752. DEBUG_INFO("Begin Response ..\n");
  12753. while((bytes_received = recv(sock, ptr, 1, 0))){
  12754. if(bytes_received==-1){
  12755. perror("ReadHttpStatus");
  12756. exit(1);
  12757. }
  12758. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12759. ptr++;
  12760. }
  12761. *ptr=0;
  12762. ptr=buff+1;
  12763. sscanf(ptr,"%*s %d ", &status);
  12764. DEBUG_INFO("%s\n",ptr);
  12765. DEBUG_INFO("status=%d\n",status);
  12766. DEBUG_INFO("End Response ..\n");
  12767. return (bytes_received>0)?status:0;
  12768. }
  12769. //the only filed that it parsed is 'Content-Length'
  12770. int ParseHeader(int sock)
  12771. {
  12772. //char c;
  12773. char buff[1024]="",*ptr=buff+4;
  12774. int bytes_received;
  12775. DEBUG_INFO("Begin HEADER ..\n");
  12776. while((bytes_received = recv(sock, ptr, 1, 0))){
  12777. if(bytes_received==-1){
  12778. perror("Parse Header");
  12779. exit(1);
  12780. }
  12781. if(
  12782. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12783. (ptr[-1]=='\r') && (*ptr=='\n' )
  12784. ) break;
  12785. ptr++;
  12786. }
  12787. *ptr=0;
  12788. ptr=buff+4;
  12789. //printf("%s",ptr);
  12790. if(bytes_received){
  12791. ptr=strstr(ptr,"Content-Length:");
  12792. if(ptr){
  12793. sscanf(ptr,"%*s %d",&bytes_received);
  12794. }else
  12795. bytes_received=-1; //unknown size
  12796. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12797. }
  12798. DEBUG_INFO("End HEADER ..\n");
  12799. return bytes_received ;
  12800. }
  12801. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12802. {
  12803. char rmFileCmd[100]={0};
  12804. char FilePath[100]={0};
  12805. char ftpbuf[200];
  12806. int systemresult;
  12807. //DEBUG_INFO("filename=%s\n",filename);
  12808. //DEBUG_INFO("url=%s\n",url);
  12809. sprintf(FilePath,"/mnt/%s",filename);
  12810. if((access(FilePath,F_OK))!=-1)
  12811. {
  12812. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12813. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12814. system(rmFileCmd);
  12815. }
  12816. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12817. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12818. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12819. systemresult = system(ftpbuf);
  12820. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12821. if(systemresult != 0)
  12822. {
  12823. DEBUG_INFO("http DownLoad error!\n");
  12824. return FALSE;
  12825. }
  12826. return TRUE;
  12827. }
  12828. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12829. {
  12830. char rmFileCmd[100]={0};
  12831. char FilePath[100]={0};
  12832. char ftpbuf[200];
  12833. int systemresult;
  12834. //char temp[100];
  12835. sprintf(FilePath,"/mnt/%s",filename);
  12836. if((access(FilePath,F_OK))!=-1)
  12837. {
  12838. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12839. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12840. system(rmFileCmd);
  12841. }
  12842. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12843. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12844. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12845. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12846. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12847. systemresult = system(ftpbuf);
  12848. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12849. if(systemresult != 0)
  12850. {
  12851. printf("wget error!\n");
  12852. return FALSE;
  12853. }
  12854. return TRUE;
  12855. }
  12856. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12857. {
  12858. char rmFileCmd[100]={0};
  12859. char FilePath[100]={0};
  12860. char ftpbuf[200];
  12861. int systemresult;
  12862. //DEBUG_INFO("filename=%s\n",filename);
  12863. //DEBUG_INFO("url=%s\n",url);
  12864. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12865. if((access(FilePath,F_OK))!=-1)
  12866. {
  12867. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12868. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12869. system(rmFileCmd);
  12870. }
  12871. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12872. if(fp == NULL)
  12873. {
  12874. DEBUG_INFO("log is NULL\n");
  12875. return FALSE;
  12876. }
  12877. else
  12878. {
  12879. fprintf(fp, "%s\n", url);
  12880. fprintf(fp, "%s\n", filename);
  12881. fclose(fp);
  12882. }
  12883. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12884. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12885. systemresult = system(ftpbuf);
  12886. DEBUG_INFO("systemresult = %d\n",systemresult);
  12887. if(systemresult != 0)
  12888. {
  12889. DEBUG_INFO("http upload error!\n");
  12890. return FALSE;
  12891. }
  12892. return TRUE;
  12893. }
  12894. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12895. {
  12896. struct hostent* server;
  12897. char *IPbuffer;
  12898. char ftpbuf[200];
  12899. int systemresult;
  12900. // To retrieve host information
  12901. server = gethostbyname(location);
  12902. // To convert an Internet network
  12903. // address into ASCII string
  12904. IPbuffer = inet_ntoa(*((struct in_addr*)
  12905. server->h_addr_list[0]));
  12906. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12907. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12908. /* format : ftpput -u username -p passwd IP target source*/
  12909. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12910. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12911. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12912. systemresult = system(ftpbuf);
  12913. DEBUG_INFO("systemresult=%d\n",systemresult);
  12914. if(systemresult != 0)
  12915. {
  12916. DEBUG_INFO("ftpput error!\n");
  12917. return FALSE;
  12918. }
  12919. return TRUE;
  12920. }
  12921. /**
  12922. * Place the contents of the specified file into a memory buffer
  12923. *
  12924. * @param[in] filename The path and name of the file to read
  12925. * @param[out] filebuffer A pointer to the contents in memory
  12926. * @return status 0 success, 1 on failure
  12927. */
  12928. int get_file_contents(const char* filename, char** outbuffer) {
  12929. FILE* file = NULL;
  12930. long filesize;
  12931. const int blocksize = 1;
  12932. size_t readsize;
  12933. char* filebuffer;
  12934. // Open the file
  12935. file = fopen(filename, "r");
  12936. if (NULL == file)
  12937. {
  12938. printf("'%s' not opened\n", filename);
  12939. exit(EXIT_FAILURE);
  12940. }
  12941. // Determine the file size
  12942. fseek(file, 0, SEEK_END);
  12943. filesize = ftell(file);
  12944. rewind (file);
  12945. // Allocate memory for the file contents
  12946. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12947. *outbuffer = filebuffer;
  12948. if (filebuffer == NULL)
  12949. {
  12950. fputs ("malloc out-of-memory", stderr);
  12951. exit(EXIT_FAILURE);
  12952. }
  12953. // Read in the file
  12954. readsize = fread(filebuffer, blocksize, filesize, file);
  12955. if (readsize != filesize)
  12956. {
  12957. fputs ("didn't read file completely",stderr);
  12958. exit(EXIT_FAILURE);
  12959. }
  12960. // Clean exit
  12961. fclose(file);
  12962. return EXIT_SUCCESS;
  12963. }
  12964. static int selectSqlCount = 0;
  12965. static int callback(void *data, int argc, char **argv, char **azColName){
  12966. int i;
  12967. //printf("%s: ", (const char*)data);
  12968. selectSqlCount = argc;
  12969. for(i = 0; i<argc; i++){
  12970. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12971. }
  12972. //printf("\n");
  12973. return 0;
  12974. }
  12975. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12976. //int i;
  12977. //printf("%s:\n", (const char*)data);
  12978. localversion = argv[5] ? atoi(argv[5]) : 0;
  12979. //printf("localversion=%d\n", localversion);
  12980. return 0;
  12981. }
  12982. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12983. //int i;
  12984. //printf("%s:\n", (const char*)data);
  12985. //idTag
  12986. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12987. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12988. //parentIdTag
  12989. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12990. //expir_date
  12991. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12992. //status
  12993. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12994. //version
  12995. idTagQuery.listVersionInt = atoi(argv[5]);
  12996. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12997. return 0;
  12998. }
  12999. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  13000. {
  13001. // localversion = argv[5] ? atoi(argv[5]) : 0;
  13002. // printf("localversion=%d\n", localversion);
  13003. return 0;
  13004. }
  13005. //=========================================
  13006. // Sqlite3 related function
  13007. //=========================================
  13008. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  13009. {
  13010. for (int i = 0; i < n_columns; i++)
  13011. {
  13012. DEBUG_INFO("%s/t", col_values[i]);
  13013. }
  13014. DEBUG_INFO("/n");
  13015. return 0;
  13016. }
  13017. void OCPP_getListVerion()
  13018. {
  13019. int rc = 0;
  13020. // const char* data = "Callback function called";
  13021. char sql[100];
  13022. char zErrMsg[100];
  13023. memset(sql, 0, 100);
  13024. memset(zErrMsg, 0, 100);
  13025. strcpy(sql, "select * from ocpp_auth_local order by idx");
  13026. /* Execute SQL statement */
  13027. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  13028. if( rc != SQLITE_OK )
  13029. {
  13030. DEBUG_INFO("SQL error: %s", zErrMsg);
  13031. }
  13032. }
  13033. void OCPP_getIdTag(char idTag[])
  13034. {
  13035. int rc = 0;
  13036. // const char* data = "Callback function called";
  13037. char sql[100];
  13038. char zErrMsg[100];
  13039. memset(sql, 0, 100);
  13040. memset(zErrMsg, 0, 100);
  13041. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  13042. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13043. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  13044. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13045. /* Execute SQL statement */
  13046. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13047. if( rc != SQLITE_OK )
  13048. {
  13049. DEBUG_INFO("SQL error: %s", zErrMsg);
  13050. }
  13051. //return ver;
  13052. }
  13053. void OCPP_get_TableAuthlocalAllData(void)
  13054. {
  13055. int rc = 0;
  13056. char sql[100];
  13057. char zErrMsg[100];
  13058. memset(sql, 0, 100);
  13059. memset(zErrMsg, 0, 100);
  13060. sprintf(sql,"select * from ocpp_auth_local ");
  13061. /* Execute SQL statement */
  13062. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  13063. if( rc != SQLITE_OK )
  13064. {
  13065. DEBUG_INFO("SQL error: %s", zErrMsg);
  13066. }
  13067. //return ver;
  13068. }
  13069. int OCPP_cleanLocalList()
  13070. {
  13071. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  13072. char *errMsg = 0;
  13073. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13074. if (SQLITE_OK != rc)
  13075. {
  13076. DEBUG_INFO("%s\n",errMsg);
  13077. return FALSE;
  13078. }
  13079. return TRUE;
  13080. }
  13081. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13082. {
  13083. int isSuccess = FALSE;
  13084. int ret = 0;
  13085. //const char* data = "Callback function called";
  13086. char sql[300];
  13087. char zErrMsg[200];
  13088. memset(sql, 0, 300);
  13089. memset(zErrMsg, 0, 200);
  13090. 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);
  13091. //* Execute SQL statement */
  13092. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13093. if( ret != SQLITE_OK )
  13094. {
  13095. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13096. return isSuccess;
  13097. }
  13098. memset(sql, 0, 300);
  13099. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13100. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13101. if( ret != SQLITE_OK )
  13102. {
  13103. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13104. return isSuccess;
  13105. }
  13106. isSuccess = TRUE;
  13107. return isSuccess;
  13108. }
  13109. void OCPP_deleteIdTag(char idTag[])
  13110. {
  13111. //int ver = 0;
  13112. //int isSuccess = FALSE;
  13113. int rc = 0;
  13114. char sql[100];
  13115. char zErrMsg[100];
  13116. memset(sql, 0, 100);
  13117. memset(zErrMsg, 0, 100);
  13118. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13119. //* Execute SQL statement */
  13120. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13121. if( rc != SQLITE_OK )
  13122. {
  13123. DEBUG_INFO("SQL error: %s", zErrMsg);
  13124. }
  13125. }
  13126. int GetOcppServerURL()
  13127. {
  13128. int result = FALSE;
  13129. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  13130. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  13131. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  13132. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13133. {
  13134. #if 1
  13135. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13136. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13137. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13138. #endif
  13139. result = TRUE;
  13140. goto End;
  13141. }
  13142. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13143. {
  13144. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13145. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13146. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13147. result = TRUE;
  13148. goto End;
  13149. }
  13150. else
  13151. {
  13152. strcpy(OcppHost,"");
  13153. }
  13154. End:
  13155. return result;
  13156. }
  13157. int GetOcppPath()
  13158. {
  13159. int result = FALSE;
  13160. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13161. {
  13162. if(OcppTempPath == NULL)
  13163. {
  13164. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13165. }
  13166. else
  13167. {
  13168. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13169. }
  13170. result = TRUE;
  13171. goto End;
  13172. }
  13173. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13174. {
  13175. if(OcppTempPath == NULL)
  13176. {
  13177. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13178. }
  13179. else
  13180. {
  13181. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13182. }
  13183. result = TRUE;
  13184. goto End;
  13185. }
  13186. else
  13187. {
  13188. strcpy(OcppPath,"");
  13189. }
  13190. End:
  13191. return result;
  13192. }
  13193. int GetOcppPort()
  13194. {
  13195. return OcppPort;
  13196. }
  13197. int GetOcppConnStatus(void)
  13198. {
  13199. return ShmOCPP16Data->OcppConnStatus;
  13200. }
  13201. void SetOcppConnStatus(uint8_t status)
  13202. {
  13203. ShmOCPP16Data->OcppConnStatus = status;
  13204. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13205. }
  13206. int GetHeartBeatWithNOResponse(void)
  13207. {
  13208. return HeartBeatWithNOResponse;
  13209. }
  13210. void SetHeartBeatWithNOResponse(void)
  13211. {
  13212. HeartBeatWithNOResponse = 0;
  13213. }
  13214. void GetStartTransactionIdTag(int gun_index)
  13215. {
  13216. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13217. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13218. }
  13219. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13220. {
  13221. char ch;
  13222. FILE *fptr1;
  13223. int temptransactionId;
  13224. char str[100]={0};
  13225. temptransactionId = 0;
  13226. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  13227. {
  13228. DEBUG_INFO("IdTag is empty.\n");
  13229. return temptransactionId;
  13230. }
  13231. /*------ Read the file ----------------*/
  13232. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13233. if (!fptr1)
  13234. {
  13235. DEBUG_INFO("QueueTransactionId file open error.\n");
  13236. //printf(" File not found or unable to open the input file!!\n");
  13237. return temptransactionId;
  13238. }
  13239. ch=fgetc(fptr1);
  13240. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13241. rewind(fptr1);
  13242. if(ch!=EOF)
  13243. {
  13244. // printf("%c",ch);
  13245. while (fgets(str, 100, fptr1) != NULL)
  13246. {
  13247. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13248. if(str[0]=='\0')
  13249. {
  13250. break;
  13251. }
  13252. char *revbuf[8] = {0}; //存放分割後的子字串
  13253. int num = 0;//分割後子字串的個數
  13254. DEBUG_INFO("str: %s\n", str);
  13255. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13256. DEBUG_INFO("revbuf[0]: %s\n", revbuf[0]);
  13257. DEBUG_INFO("revbuf[1]: %s\n", revbuf[1]);
  13258. DEBUG_INFO("revbuf[2]: %s\n", revbuf[2]);
  13259. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13260. {
  13261. if(isStopTransaction)
  13262. {
  13263. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13264. {
  13265. temptransactionId = atoi(revbuf[2]);
  13266. break;
  13267. }
  13268. }
  13269. else
  13270. {
  13271. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13272. {
  13273. temptransactionId = atoi(revbuf[2]);
  13274. break;
  13275. }
  13276. }
  13277. }
  13278. }
  13279. }
  13280. else
  13281. DEBUG_INFO("EOF\n");
  13282. fclose(fptr1);
  13283. /*------- End of reading ---------------*/
  13284. return temptransactionId;
  13285. }
  13286. void SetTransactionIdZero(int transactionId)
  13287. {
  13288. char ch;
  13289. FILE *fptr1, *fptr2;
  13290. int temptransactionId = 0;
  13291. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13292. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13293. if (!fptr1)
  13294. {
  13295. //printf(" File not found or unable to open the input file!!\n");
  13296. return ;
  13297. }
  13298. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13299. if (!fptr2)
  13300. {
  13301. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13302. fclose(fptr1);
  13303. return ;
  13304. }
  13305. ch=fgetc(fptr1);
  13306. rewind(fptr1);
  13307. if(ch!=EOF)
  13308. {
  13309. // copy all contents to the temporary file except the specific line
  13310. while (fgets(str, 100, fptr1) != NULL)
  13311. {
  13312. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13313. if(str[0]=='\0')
  13314. {
  13315. break;
  13316. }
  13317. char *revbuf[8] = {0};
  13318. int num = 0;
  13319. strcpy(strtemp, str);
  13320. splitstring(str,",",revbuf,&num);
  13321. if(revbuf[2][0] != '\0')
  13322. {
  13323. temptransactionId = atoi(revbuf[2]);
  13324. if(transactionId != temptransactionId)
  13325. {
  13326. fprintf(fptr2, "%s\n", strtemp);
  13327. }
  13328. }
  13329. }
  13330. }
  13331. fclose(fptr1);
  13332. fclose(fptr2);
  13333. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13334. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13335. /*------ Read the file ----------------*/
  13336. }
  13337. int InternetDisconnect(void)
  13338. {
  13339. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13340. }
  13341. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13342. void storeTempStopTransaction(int gun_index)
  13343. {
  13344. char guid[37]={0};
  13345. int tempIndex = 0;
  13346. DEBUG_INFO("storeTempStopTransaction...\n");
  13347. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13348. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13349. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13350. if(gunType[gun_index] == 'J')
  13351. {
  13352. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13353. {
  13354. tempIndex = ((gun_index==2) ? 1: 0);
  13355. }
  13356. else
  13357. {
  13358. tempIndex = gun_index;
  13359. }
  13360. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13361. {
  13362. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13363. {
  13364. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13365. }
  13366. }// END OF CHAdeMO_QUANTITY
  13367. }
  13368. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13369. {
  13370. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13371. {
  13372. tempIndex = ((gun_index==2) ? 1: 0);
  13373. }
  13374. else
  13375. {
  13376. tempIndex = gun_index;
  13377. }
  13378. for (int index = 0; index < CCS_QUANTITY; index++)
  13379. {
  13380. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13381. {
  13382. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13383. }
  13384. }// END OF CCS_QUANTITY
  13385. }
  13386. else if(gunType[gun_index] == 'G')
  13387. {
  13388. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13389. {
  13390. tempIndex = ((gun_index==2) ? 1: 0);
  13391. }
  13392. else
  13393. {
  13394. tempIndex = gun_index;
  13395. }
  13396. for (int index = 0; index < GB_QUANTITY; index++)
  13397. {
  13398. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13399. {
  13400. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13401. }
  13402. }// END OF GB_QUANTITY
  13403. }
  13404. else
  13405. {
  13406. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13407. {
  13408. tempIndex = 2;
  13409. }
  13410. else
  13411. {
  13412. tempIndex = gun_index;
  13413. }
  13414. for (int index = 0; index < AC_QUANTITY; index++)
  13415. {
  13416. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13417. {
  13418. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13419. }
  13420. }// END OF AC_QUANTITY
  13421. }
  13422. //Stop Transaction Time
  13423. struct timeval tmnow;
  13424. struct tm *tm;
  13425. char buf[28];//, usec_buf[6];
  13426. gettimeofday(&tmnow, NULL);
  13427. time_t t;
  13428. t = time(NULL);
  13429. /*UTC time and date*/
  13430. tm = gmtime(&t);
  13431. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13432. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13433. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13434. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13435. random_uuid(guid);
  13436. /***********************************transactionData******************************************************/
  13437. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13438. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13439. //=================================
  13440. //1. Transaction_Begin
  13441. //=================================
  13442. //============================== Energy.Active.Import.Interval ===========================================
  13443. //idx_sample=0;
  13444. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  13445. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13446. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13447. 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*/]);
  13448. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13449. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13450. {
  13451. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13452. }
  13453. else
  13454. {
  13455. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13456. }
  13457. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13458. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13459. //=================================
  13460. //2. Transaction_End
  13461. //=================================
  13462. //2.1====================================== Current.Import L1 ==============================================
  13463. //idx_sample=1;
  13464. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13465. if(gunType[gun_index] == 'J')
  13466. {
  13467. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13468. {
  13469. tempIndex = ((gun_index==2) ? 1: 0);
  13470. }
  13471. else
  13472. {
  13473. tempIndex = gun_index;
  13474. }
  13475. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13476. {
  13477. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13478. {
  13479. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13480. }
  13481. }// End of for CHAdeMO_QUANTITY
  13482. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13483. }
  13484. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13485. {
  13486. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13487. {
  13488. tempIndex = ((gun_index==2) ? 1: 0);
  13489. }
  13490. else
  13491. {
  13492. tempIndex = gun_index;
  13493. }
  13494. for (int index = 0; index < CCS_QUANTITY; index++)
  13495. {
  13496. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13497. {
  13498. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13499. }
  13500. }// End of for CCS_QUANTITY
  13501. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13502. }
  13503. else if(gunType[gun_index] == 'G')
  13504. {
  13505. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13506. {
  13507. tempIndex = ((gun_index==2) ? 1: 0);
  13508. }
  13509. else
  13510. {
  13511. tempIndex = gun_index;
  13512. }
  13513. for (int index = 0; index < GB_QUANTITY; index++)
  13514. {
  13515. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13516. {
  13517. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13518. }
  13519. }// End of for GB_QUANTITY
  13520. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13521. }
  13522. else
  13523. {
  13524. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13525. {
  13526. tempIndex = 2;
  13527. }
  13528. else
  13529. {
  13530. tempIndex = gun_index;
  13531. }
  13532. for (int index = 0; index < AC_QUANTITY; index++)
  13533. {
  13534. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13535. {
  13536. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13537. }
  13538. }// End of for AC_QUANTITY
  13539. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13540. }
  13541. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13542. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13543. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13544. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13545. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13546. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13547. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13548. //idx_sample=2;
  13549. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13550. if(gunType[gun_index] == 'J')
  13551. {
  13552. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13553. {
  13554. tempIndex = ((gun_index==2) ? 1: 0);
  13555. }
  13556. else
  13557. {
  13558. tempIndex = gun_index;
  13559. }
  13560. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13561. {
  13562. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13563. {
  13564. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13565. }
  13566. }// END OF CHAdeMO_QUANTITY
  13567. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13568. }
  13569. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13570. {
  13571. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13572. {
  13573. tempIndex = ((gun_index==2) ? 1: 0);
  13574. }
  13575. else
  13576. {
  13577. tempIndex = gun_index;
  13578. }
  13579. for (int index = 0; index < CCS_QUANTITY; index++)
  13580. {
  13581. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13582. {
  13583. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13584. }
  13585. }// END OF CCS_QUANTITY
  13586. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13587. }
  13588. else if(gunType[gun_index] == 'G')
  13589. {
  13590. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13591. {
  13592. tempIndex = ((gun_index==2) ? 1: 0);
  13593. }
  13594. else
  13595. {
  13596. tempIndex = gun_index;
  13597. }
  13598. for (int index = 0; index < GB_QUANTITY; index++)
  13599. {
  13600. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13601. {
  13602. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13603. }
  13604. }// END OF GB_QUANTITY
  13605. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13606. }
  13607. else
  13608. {
  13609. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13610. {
  13611. tempIndex = 2;
  13612. }
  13613. else
  13614. {
  13615. tempIndex = gun_index;
  13616. }
  13617. for (int index = 0; index < AC_QUANTITY; index++)
  13618. {
  13619. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13620. {
  13621. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13622. }
  13623. }// END OF AC_QUANTITY
  13624. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13625. }
  13626. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13627. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13628. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13629. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13630. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13631. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13632. //2.3====================================== Power.Active.Import =========================================
  13633. //idx_sample=3;
  13634. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13635. if(gunType[gun_index] == 'J')
  13636. {
  13637. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13638. {
  13639. tempIndex = ((gun_index==2) ? 1: 0);
  13640. }
  13641. else
  13642. {
  13643. tempIndex = gun_index;
  13644. }
  13645. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13646. {
  13647. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13648. {
  13649. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13650. }
  13651. } // End for CHAdeMO_QUANTITY
  13652. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13653. }
  13654. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13655. {
  13656. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13657. {
  13658. tempIndex = ((gun_index==2) ? 1: 0);
  13659. }
  13660. else
  13661. {
  13662. tempIndex = gun_index;
  13663. }
  13664. for (int index = 0; index < CCS_QUANTITY; index++)
  13665. {
  13666. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13667. {
  13668. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13669. }
  13670. } // END for CCS_QUANTITY
  13671. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13672. }
  13673. else if(gunType[gun_index] == 'G')
  13674. {
  13675. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13676. {
  13677. tempIndex = ((gun_index==2) ? 1: 0);
  13678. }
  13679. else
  13680. {
  13681. tempIndex = gun_index;
  13682. }
  13683. for (int index = 0; index < GB_QUANTITY; index++)
  13684. {
  13685. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13686. {
  13687. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13688. }
  13689. }// END for GB_QUANTITY
  13690. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13691. }
  13692. else
  13693. {
  13694. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13695. {
  13696. tempIndex = 2;
  13697. }
  13698. else
  13699. {
  13700. tempIndex = gun_index;
  13701. }
  13702. for (int index = 0; index < AC_QUANTITY; index++)
  13703. {
  13704. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13705. {
  13706. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13707. }
  13708. } // END for AC_QUANTITY
  13709. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13710. }
  13711. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13712. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13713. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13714. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13715. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13716. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13717. //2.4====================================== Voltage L1 ====================================================
  13718. //idx_sample=4;
  13719. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13720. if(gunType[gun_index] == 'J')
  13721. {
  13722. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13723. {
  13724. tempIndex = ((gun_index==2) ? 1: 0);
  13725. }
  13726. else
  13727. {
  13728. tempIndex = gun_index;
  13729. }
  13730. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13731. {
  13732. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13733. {
  13734. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13735. }
  13736. } // END OF FOR CHAdeMO_QUANTITY
  13737. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13738. }
  13739. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13740. {
  13741. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13742. {
  13743. tempIndex = ((gun_index==2) ? 1: 0);
  13744. }
  13745. else
  13746. {
  13747. tempIndex = gun_index;
  13748. }
  13749. for (int index = 0; index < CCS_QUANTITY; index++)
  13750. {
  13751. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13752. {
  13753. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13754. }
  13755. } // END OF FOR CCS_QUANTITY
  13756. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13757. }
  13758. else if(gunType[gun_index] == 'G')
  13759. {
  13760. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13761. {
  13762. tempIndex = ((gun_index==2) ? 1: 0);
  13763. }
  13764. else
  13765. {
  13766. tempIndex = gun_index;
  13767. }
  13768. for (int index = 0; index < GB_QUANTITY; index++)
  13769. {
  13770. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13771. {
  13772. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13773. }
  13774. } // END OF FOR GB_QUANTITY
  13775. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13776. }
  13777. else
  13778. {
  13779. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13780. {
  13781. tempIndex = 2;
  13782. }
  13783. else
  13784. {
  13785. tempIndex = gun_index;
  13786. }
  13787. for (int index = 0; index < AC_QUANTITY; index++)
  13788. {
  13789. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13790. {
  13791. 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
  13792. }
  13793. } // END OF FOR AC_QUANTITY
  13794. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13795. }
  13796. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13797. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13798. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13799. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13800. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13801. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13802. //2.5============================================== SoC =========================================================
  13803. //idx_sample=5;
  13804. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13805. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13806. {
  13807. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13808. {
  13809. tempIndex = ((gun_index==2) ? 1: 0);
  13810. }
  13811. else
  13812. {
  13813. tempIndex = gun_index;
  13814. }
  13815. if(gunType[gun_index] == 'J')
  13816. {
  13817. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13818. {
  13819. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13820. {
  13821. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13822. }
  13823. }
  13824. }
  13825. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13826. {
  13827. for (int index = 0; index < CCS_QUANTITY; index++)
  13828. {
  13829. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13830. {
  13831. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13832. }
  13833. }
  13834. }
  13835. else if(gunType[gun_index] == 'G')
  13836. {
  13837. for (int index = 0; index < GB_QUANTITY; index++)
  13838. {
  13839. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13840. {
  13841. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13842. }
  13843. }
  13844. }
  13845. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13846. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13847. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13848. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13849. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  13850. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13851. } // END FOR DC CASE
  13852. //2.6====================================== Current.Import L2 ==============================================
  13853. // idx_sample=6;
  13854. // AC 3 phase L2 current
  13855. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13856. {
  13857. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13858. {
  13859. tempIndex = 2;
  13860. }
  13861. else
  13862. {
  13863. tempIndex = gun_index;
  13864. }
  13865. for (int index = 0; index < AC_QUANTITY; index++)
  13866. {
  13867. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13868. {
  13869. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  13870. }
  13871. }// End of for AC_QUANTITY
  13872. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  13873. }
  13874. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13875. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  13876. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  13877. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  13878. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13879. //2.7====================================== Current.Import L3 ==============================================
  13880. // idx_sample=7;
  13881. // AC 3 phase L3 current
  13882. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13883. {
  13884. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13885. {
  13886. tempIndex = 2;
  13887. }
  13888. else
  13889. {
  13890. tempIndex = gun_index;
  13891. }
  13892. for (int index = 0; index < AC_QUANTITY; index++)
  13893. {
  13894. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13895. {
  13896. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  13897. }
  13898. }// End of for AC_QUANTITY
  13899. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  13900. }
  13901. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13902. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  13903. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  13904. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  13905. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13906. //2.9====================================== Voltage L2 ====================================================
  13907. //idx_sample=8;
  13908. // AC 3 phase L2 volatge
  13909. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13910. {
  13911. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13912. {
  13913. tempIndex = 2;
  13914. }
  13915. else
  13916. {
  13917. tempIndex = gun_index;
  13918. }
  13919. for (int index = 0; index < AC_QUANTITY; index++)
  13920. {
  13921. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13922. {
  13923. 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
  13924. }
  13925. } // END OF FOR AC_QUANTITY
  13926. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  13927. }
  13928. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13929. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  13930. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  13931. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  13932. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13933. //2.10====================================== Voltage L3 ====================================================
  13934. //idx_sample=9;
  13935. // AC 3 phase L3 volatge
  13936. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13937. {
  13938. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13939. {
  13940. tempIndex = 2;
  13941. }
  13942. else
  13943. {
  13944. tempIndex = gun_index;
  13945. }
  13946. for (int index = 0; index < AC_QUANTITY; index++)
  13947. {
  13948. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13949. {
  13950. 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
  13951. }
  13952. } // END OF FOR AC_QUANTITY
  13953. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  13954. }
  13955. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13956. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  13957. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  13958. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  13959. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13960. //======================================== Message create ==============================================
  13961. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13962. {
  13963. 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\"}]}]}]"
  13964. ,gun_index+1
  13965. ,MESSAGE_TYPE_CALL
  13966. ,guid
  13967. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13968. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13969. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13970. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13971. ,"PowerLoss"
  13972. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13973. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13974. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13975. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13976. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13977. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13978. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13979. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13980. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13981. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13982. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13983. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13984. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13985. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13986. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13987. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13988. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13989. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13990. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13991. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13992. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13993. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13994. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13995. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13996. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13997. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13998. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13999. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  14000. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  14001. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  14002. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  14003. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  14004. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  14005. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  14006. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  14007. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  14008. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  14009. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  14010. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  14011. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  14012. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  14013. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  14014. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  14015. );
  14016. }
  14017. else
  14018. {
  14019. if(((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W')))
  14020. {
  14021. 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\"}]}]}]"
  14022. ,gun_index+1
  14023. ,MESSAGE_TYPE_CALL
  14024. ,guid
  14025. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  14026. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  14027. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  14028. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  14029. ,"PowerLoss"
  14030. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  14031. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  14032. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  14033. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  14034. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  14035. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  14036. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  14037. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  14038. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  14039. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  14040. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  14041. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  14042. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  14043. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  14044. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  14045. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  14046. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  14047. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  14048. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  14049. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  14050. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  14051. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  14052. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  14053. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  14054. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  14055. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  14056. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  14057. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  14058. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  14059. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  14060. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  14061. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  14062. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  14063. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  14064. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  14065. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  14066. );
  14067. }
  14068. else
  14069. {
  14070. 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\"}]}]}]"
  14071. ,gun_index+1
  14072. ,MESSAGE_TYPE_CALL
  14073. ,guid
  14074. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  14075. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  14076. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  14077. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  14078. ,"PowerLoss"
  14079. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  14080. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  14081. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  14082. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  14083. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  14084. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  14085. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  14086. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  14087. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  14088. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  14089. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  14090. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  14091. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  14092. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  14093. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  14094. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  14095. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  14096. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  14097. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  14098. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  14099. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  14100. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  14101. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  14102. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  14103. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  14104. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  14105. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  14106. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  14107. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  14108. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  14109. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  14110. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  14111. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  14112. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  14113. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  14114. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  14115. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  14116. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  14117. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  14118. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  14119. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  14120. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  14121. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  14122. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  14123. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  14124. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  14125. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  14126. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  14127. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  14128. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  14129. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  14130. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  14131. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  14132. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  14133. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  14134. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  14135. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  14136. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  14137. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  14138. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  14139. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  14140. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  14141. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  14142. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  14143. );
  14144. }
  14145. }
  14146. // Check File "TempStopTransaction" Exist
  14147. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  14148. {
  14149. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14150. fclose(fopen("/Storage/OCPP/TempStopTransaction", "w"));
  14151. }
  14152. else
  14153. {
  14154. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  14155. FILE *log = fopen("/Storage/OCPP/TempStopTransaction", "w+");
  14156. if(log == NULL)
  14157. {
  14158. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  14159. return ;
  14160. }
  14161. else
  14162. {
  14163. fclose(log);
  14164. }
  14165. }
  14166. //Add TempStopTransaction | Update TempStopTransaction
  14167. // open file for writing
  14168. FILE *outfile;
  14169. outfile = fopen ("/Storage/OCPP/TempStopTransaction", "a");
  14170. //DEBUG_INFO("data = %s\n", queuedata);
  14171. fputs(queuedata, outfile);
  14172. fputs("\n", outfile);
  14173. fclose (outfile);
  14174. }
  14175. void checkTempStopTransaction(int gun_index)
  14176. {
  14177. FILE *fptr1;
  14178. char ch;
  14179. char str[QUEUE_MESSAGE_LENGTH]={0};
  14180. char guid[37]={0};
  14181. char tempdata[65]={0};
  14182. char connectorStr[2]={0};
  14183. fptr1 = fopen("/Storage/OCPP/TempStopTransaction", "r");
  14184. //TempStopTransaction格式: 槍號,StopTransaction封包
  14185. if (!fptr1)
  14186. {
  14187. //printf(" File not found or unable to open the input file!!\n");
  14188. return ;
  14189. }
  14190. ch=fgetc(fptr1);
  14191. //printf(" Now the content of the file %s is : \n",fname);
  14192. rewind(fptr1);
  14193. if(ch!=EOF)
  14194. {
  14195. // copy all contents to the temporary file except the specific line
  14196. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14197. {
  14198. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14199. if(str[0]=='\0')
  14200. {
  14201. break;
  14202. }
  14203. //TempStopTransaction格式: 槍號,StopTransaction封包
  14204. strncpy(connectorStr, str, 1);
  14205. if(atoi(connectorStr) != (gun_index+1))
  14206. {
  14207. DEBUG_INFO("atoi(connectorStr) = %d\n", atoi(connectorStr));
  14208. return ;
  14209. }
  14210. //random_uuid(guid);
  14211. strncpy(guid, str+6, 36); //copy guid
  14212. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14213. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14214. {
  14215. DEBUG_INFO("StopTransaction mapitem pass\n");
  14216. }
  14217. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14218. memset(str,0,ARRAY_SIZE(str));
  14219. }
  14220. }
  14221. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14222. fclose(fptr1);
  14223. remove("/Storage/OCPP/TempStopTransaction"); // remove the original file
  14224. }
  14225. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14226. {
  14227. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14228. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14229. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14230. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14231. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14232. }
  14233. int GetWebSocketPingInterval(void)
  14234. {
  14235. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14236. }
  14237. int GetServerSign(void)
  14238. {
  14239. return server_sign;
  14240. }
  14241. void SetServerSign(int value)
  14242. {
  14243. server_sign = value;
  14244. }
  14245. int GetBootNotificationInterval(void)
  14246. {
  14247. return BootNotificationInterval;
  14248. }
  14249. int GetInternetConn(void)
  14250. {
  14251. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14252. }
  14253. void InitialSystemValue(void)
  14254. {
  14255. int connectorIndex = 0;
  14256. //int valueASCII = 0;
  14257. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14258. gunTotalNumber=0;
  14259. SystemInitial = 0;
  14260. localversion=0;
  14261. BootNotificationInterval = 0;
  14262. authorizeRetryTimes = 0;
  14263. GunStatusInterval = 10;
  14264. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14265. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14266. //Hear Beat
  14267. HeartBeatWithNOResponse = 0;
  14268. HeartBeatCountPerHour = 0;
  14269. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14270. FirstHeartBeat = 0;
  14271. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14272. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14273. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14274. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14275. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14276. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14277. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14278. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14279. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14280. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14281. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14282. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14283. memset(gunType, 0, ARRAY_SIZE(gunType));
  14284. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14285. {
  14286. //check connector / socket type (index: 8, 9, 10)
  14287. for(int index=7; index <10 ; index++)
  14288. {
  14289. if(index != 8)
  14290. {
  14291. // DC Connector
  14292. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  14293. {
  14294. SystemInitial = SystemInitial + 1;
  14295. gunTotalNumber = gunTotalNumber + 1;
  14296. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14297. connectorIndex = connectorIndex + 1;
  14298. }
  14299. }
  14300. else
  14301. {
  14302. // AC Connector
  14303. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14304. {
  14305. SystemInitial = SystemInitial + 1;
  14306. gunTotalNumber = gunTotalNumber + 1;
  14307. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14308. connectorIndex = connectorIndex + 1;
  14309. }
  14310. }
  14311. }
  14312. //DEBUG_INFO("DC ...\n");
  14313. }
  14314. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14315. {
  14316. //check connector / socket type (index: 8, 9, 10)
  14317. for(int index=7; index <10 ; index++)
  14318. {
  14319. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14320. {
  14321. SystemInitial = SystemInitial + 1;
  14322. gunTotalNumber = gunTotalNumber + 1;
  14323. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14324. connectorIndex = connectorIndex + 1;
  14325. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14326. }
  14327. }
  14328. }
  14329. //Status && ConnectorPlugIn Setting
  14330. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14331. {
  14332. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14333. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14334. }
  14335. for (int index = 0; index < CCS_QUANTITY; index++)
  14336. {
  14337. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14338. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14339. }
  14340. for (int index = 0; index < GB_QUANTITY; index++)
  14341. {
  14342. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14343. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14344. }
  14345. for (int index = 0; index < AC_QUANTITY; index++)
  14346. {
  14347. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14348. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14349. }
  14350. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14351. {
  14352. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14353. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14354. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14355. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14356. }
  14357. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14358. clientTime.Heartbeat=time((time_t*)NULL);
  14359. sleep(1);
  14360. }
  14361. void LWS_Send(char * str)
  14362. {
  14363. //=====================================================
  14364. // Check InternetConn 0: disconnected, 1: connected
  14365. //====================================================
  14366. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14367. {
  14368. DEBUG_INFO("offline now !!!\n");
  14369. return;
  14370. }
  14371. pthread_mutex_lock(&lock_send);
  14372. memset(SendBuffer, 0, SendBufLen);
  14373. sprintf((char *)SendBuffer, "%s", str);
  14374. pthread_mutex_unlock(&lock_send);
  14375. lws_callback_on_writable(wsi_client);
  14376. //lws_service(context, 0);
  14377. //sleep(1);
  14378. }