MessageHandler.c 674 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. #define TxDefaultProfile_1_JSON "/Storage/OCPP/TxDefaultProfile_1.json"
  8. #define TxDefaultProfile_2_JSON "/Storage/OCPP/TxDefaultProfile_2.json"
  9. //TxProfile
  10. #define TxProfile_1_JSON "/Storage/OCPP/TxProfile_1.json"
  11. #define TxProfile_2_JSON "/Storage/OCPP/TxProfile_2.json"
  12. #define ChargingProfile_0_JSON "/Storage/OCPP/chargingprofile_0.json"
  13. #define ChargingProfile_1_JSON "/Storage/OCPP/chargingprofile_1.json"
  14. #define ChargingProfile_2_JSON "/Storage/OCPP/chargingprofile_2.json"
  15. #define AuthorizationCache_JSON "/Storage/OCPP/AuthorizationCache.json"
  16. #define LocalAuthorizationList_JSON "/Storage/OCPP/LocalAuthorizationList.json"
  17. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  18. struct StatusCodeData *ShmStatusCodeData;
  19. struct PsuData *ShmPsuData ;
  20. struct OCPP16Data *ShmOCPP16Data;
  21. //ConfigurationMaxKeys
  22. #define GetConfigurationMaxKeysNUM 44
  23. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  24. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  25. //=================================
  26. // StatusNotification cycle
  27. //=================================
  28. static int server_cycle_Status = 120;
  29. //===============================
  30. // Configuration: unknownkey
  31. //===============================
  32. static char unknownkey[10][20] = {0};
  33. static int UnknownKeynum = 0;
  34. //===============================
  35. // Gun Total Numbers
  36. //===============================
  37. static int gunTotalNumber = 0;
  38. static uint8_t gunType[4] = {0};
  39. //===============================
  40. // Local List Version
  41. //===============================
  42. static int localversion=0;
  43. static char idTagAuthorization[32] = {0};
  44. //===============================
  45. // OCPP sign variable
  46. //===============================
  47. static int server_sign = FALSE;
  48. int server_pending = FALSE;
  49. static int BootNotificationInterval = 0;
  50. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  51. //===============================
  52. // OCPP auth variable
  53. //===============================
  54. static int authorizeRetryTimes = 0; //number of Retry times
  55. //===============================
  56. // OCPP other variables
  57. //===============================
  58. static int HeartBeatWaitTime = 10;
  59. static int FirstHeartBeat = 0;
  60. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  61. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  62. static char CurrentChargingProfileScheduleStr[30] = {0};
  63. //========================================
  64. // OCPP status/previous related variables
  65. //========================================
  66. static int GunStatusInterval = 10;
  67. static uint8_t statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  68. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  69. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  70. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  71. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  72. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  73. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  74. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  75. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  76. static int TransactionMessageAttemptsValue = 0;
  77. static int TransactionMessageRetryIntervalValue = 0;
  78. static int TempMeterValueInterval = 0;
  79. static struct OCPPAuthLocalElemet
  80. {
  81. int listVersionInt;
  82. char idTagstr[20];
  83. char parentIdTag[20];
  84. char expiryDate[30];
  85. char idTagstatus[16];
  86. }idTagQuery;
  87. //=============================================
  88. // OCPP HeartBeat Response Not Receive Counts
  89. //============================================
  90. static int HeartBeatWithNOResponse = 0;
  91. static int HeartBeatCountPerHour = 0;
  92. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  93. extern int GetTransactionQueueNum(void);
  94. extern struct Charger_Info Charger;
  95. extern sqlite3 *db;
  96. int TransactionMessageAttemptsGet(void);
  97. int TransactionMessageRetryIntervalGet(void);
  98. int GetOcppConnStatus(void);
  99. void SetOcppConnStatus(uint8_t status);
  100. int setKeyValue(char *key, char *value);
  101. void OCPP_get_TableAuthlocalAllData(void);
  102. void processUnkownKey(void);
  103. struct StructOCPPMeterValue
  104. {
  105. unsigned char TimeStamp[28];
  106. struct StructSampledValue SampledValue[10];
  107. };
  108. struct ClientTime
  109. {
  110. unsigned int Heartbeat;
  111. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  112. unsigned int StartTransaction;
  113. unsigned int StopTransaction;
  114. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  115. }clientTime;
  116. typedef union
  117. {
  118. //Operations Initiated by Central System
  119. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  120. struct
  121. {
  122. //CsMsgValue[0]
  123. unsigned char StatusNotificationReq:1; //bit 0,
  124. unsigned char StatusNotificationConf:1; //bit 1,
  125. unsigned char TriggerMeterValue:1; //bit 2,
  126. unsigned char :5; //bit 5~7
  127. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  128. }CpinitiateMsg;
  129. CpinitiateMsg cpinitateMsg;
  130. //GetConfiguration Array
  131. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  132. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  133. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  134. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  135. #if 0
  136. static char *ChargePointErrorCodeStr[] = {
  137. MACROSTR(ConnectorLockFailure),
  138. MACROSTR(EVCommunicationError),
  139. MACROSTR(GroundFailure),
  140. MACROSTR(HighTemperature),
  141. MACROSTR(InternalError),
  142. MACROSTR(LocalListConflict),
  143. MACROSTR(NoError),
  144. MACROSTR(OtherError),
  145. MACROSTR(OverCurrentFailure),
  146. MACROSTR(OverVoltage),
  147. MACROSTR(PowerMeterFailure),
  148. MACROSTR(PowerSwitchFailure),
  149. MACROSTR(ReaderFailure),
  150. MACROSTR(ResetFailure),
  151. MACROSTR(UnderVoltage),
  152. MACROSTR(WeakSignal)
  153. };
  154. #endif
  155. static char * ChargePointStatusStr[] = {
  156. MACROSTR(Available),
  157. MACROSTR(Preparing),
  158. MACROSTR(Charging),
  159. MACROSTR(SuspendedEVSE),
  160. MACROSTR(SuspendedEV),
  161. MACROSTR(Finishing),
  162. MACROSTR(Reserved),
  163. MACROSTR(Unavailable),
  164. MACROSTR(Faulted)
  165. };
  166. static char *RegistrationStatusStr[] = {
  167. MACROSTR(Accepted),
  168. MACROSTR(Pending),
  169. MACROSTR(Rejected)
  170. };
  171. static char *AvailabilityTypeStr[] = {
  172. MACROSTR(Inoperative),
  173. MACROSTR(Operative)
  174. };
  175. static char *AvailabilityStatusStr[] = {
  176. MACROSTR(Accepted),
  177. MACROSTR(Rejected),
  178. MACROSTR(Scheduled)
  179. };
  180. static char *ConfigurationStatusStr[] = {
  181. MACROSTR(Accepted),
  182. MACROSTR(Rejected),
  183. MACROSTR(RebootRequired),
  184. MACROSTR(NotSupported)
  185. };
  186. static char *ClearCacheStatusStr[] = {
  187. MACROSTR(Accepted),
  188. MACROSTR(Rejected)
  189. };
  190. static char *ChargingProfilePurposeTypeStr[] = {
  191. MACROSTR(ChargePointMaxProfile),
  192. MACROSTR(TxDefaultProfile),
  193. MACROSTR(TxProfile)
  194. };
  195. static char *ChargingProfileStatusStr[] = {
  196. MACROSTR(Accepted),
  197. MACROSTR(Rejected),
  198. MACROSTR(NotSupported)
  199. };
  200. static char *ClearChargingProfileStatusStr[] = {
  201. MACROSTR(Accepted),
  202. MACROSTR(Unknown)
  203. };
  204. static char *GetCompositeScheduleStatusStr[] = {
  205. MACROSTR(Accepted),
  206. MACROSTR(Rejected)
  207. };
  208. static char *UpdateTypeStr[] = {
  209. MACROSTR(Differential),
  210. MACROSTR(Full)
  211. };
  212. static char *UpdateStatusStr[] = {
  213. MACROSTR(Accepted),
  214. MACROSTR(Failed),
  215. MACROSTR(NotSupported),
  216. MACROSTR(VersionMismatch)
  217. };
  218. static char *RemoteStartStopStatusStr[] = {
  219. MACROSTR(Accepted),
  220. MACROSTR(Rejected)
  221. };
  222. static char *ReservationStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Faulted),
  225. MACROSTR(Occupied),
  226. MACROSTR(Rejected),
  227. MACROSTR(Unavailable)
  228. };
  229. static char *ResetTypeStr[] = {
  230. MACROSTR(Hard),
  231. MACROSTR(Soft)
  232. };
  233. static char *ResetStatusStr[] = {
  234. MACROSTR(Accepted),
  235. MACROSTR(Rejected)
  236. };
  237. static char * DiagnosticsStatusStr[] = {
  238. MACROSTR(Idle),
  239. MACROSTR(Uploaded),
  240. MACROSTR(UploadFailed),
  241. MACROSTR(Uploading)
  242. };
  243. static char * FirmwareStatusStr[] = {
  244. MACROSTR(Downloaded),
  245. MACROSTR(DownloadFailed),
  246. MACROSTR(Downloading),
  247. MACROSTR(Idle),
  248. MACROSTR(InstallationFailed),
  249. MACROSTR(Installing),
  250. MACROSTR(Installed)
  251. };
  252. static char * MessageTriggerStr[] = {
  253. MACROSTR(BootNotification),
  254. MACROSTR(DiagnosticsStatusNotification),
  255. MACROSTR(FirmwareStatusNotification),
  256. MACROSTR(Heartbeat),
  257. MACROSTR(MeterValues),
  258. MACROSTR(StatusNotification)
  259. };
  260. static char * TriggerMessageStatusStr[] = {
  261. MACROSTR(Accepted),
  262. MACROSTR(Rejected),
  263. MACROSTR(NotImplemented)
  264. };
  265. static char * UnlockStatusStr[] = {
  266. MACROSTR(Unlocked),
  267. MACROSTR(UnlockFailed),
  268. MACROSTR(NotSupported)
  269. };
  270. #if 0
  271. static char * StopTransactionReasonStr[] = {
  272. MACROSTR(EmergencyStop),
  273. MACROSTR(EVDisconnected),
  274. MACROSTR(HardReset),
  275. MACROSTR(Local),
  276. MACROSTR(Other),
  277. MACROSTR(PowerLoss),
  278. MACROSTR(Reboot),
  279. MACROSTR(Remote),
  280. MACROSTR(SoftReset),
  281. MACROSTR(UnlockCommand),
  282. MACROSTR(DeAuthorized)
  283. };
  284. #endif
  285. static char * CancelReservationStatusStr[] = {
  286. MACROSTR(Accepted),
  287. MACROSTR(Rejected)
  288. };
  289. static char * ReadingContextStr[] = {
  290. MACROSTR(Interruption.Begin),
  291. MACROSTR(Interruption.End),
  292. MACROSTR(Other),
  293. MACROSTR(Sample.Clock),
  294. MACROSTR(Sample.Periodic),
  295. MACROSTR(Transaction.Begin),
  296. MACROSTR(Transaction.End),
  297. MACROSTR(Trigger)
  298. };
  299. static char * ValueFormatStr[] = {
  300. MACROSTR(Raw),
  301. MACROSTR(SignedData)
  302. };
  303. static char * MeasurandStr[] = {
  304. MACROSTR(Current.Export),
  305. MACROSTR(Current.Import),
  306. MACROSTR(Current.Offered),
  307. MACROSTR(Energy.Active.Export.Register),
  308. MACROSTR(Energy.Active.Import.Register),
  309. MACROSTR(Energy.Reactive.Export.Register),
  310. MACROSTR(Energy.Reactive.Import.Register),
  311. MACROSTR(Energy.Active.Export.Interval),
  312. MACROSTR(Energy.Active.Import.Interval),
  313. MACROSTR(Energy.Reactive.Export.Interval),
  314. MACROSTR(Energy.Reactive.Import.Interval),
  315. MACROSTR(Frequency),
  316. MACROSTR(Power.Active.Export),
  317. MACROSTR(Power.Active.Import),
  318. MACROSTR(Power.Factor),
  319. MACROSTR(Power.Offered),
  320. MACROSTR(Power.Reactive.ExportMACROSTR),
  321. MACROSTR(Power.Reactive.Import),
  322. MACROSTR(RPM),
  323. MACROSTR(SoC),
  324. MACROSTR(Temperature),
  325. MACROSTR(Voltage)
  326. };
  327. static char * LocationStr[] = {
  328. MACROSTR(Body),
  329. MACROSTR(Cable),
  330. MACROSTR(EV),
  331. MACROSTR(Inlet),
  332. MACROSTR(Outlet)
  333. };
  334. static char * PhaseStr[] = {
  335. MACROSTR(L1),
  336. MACROSTR(L2),
  337. MACROSTR(L3),
  338. MACROSTR(N),
  339. MACROSTR(L1-N),
  340. MACROSTR(L2-N),
  341. MACROSTR(L3-N),
  342. MACROSTR(L1-L2),
  343. MACROSTR(L2-L3),
  344. MACROSTR(L3-L1)
  345. };
  346. static char * UnitOfMeasureStr[] = {
  347. MACROSTR(Wh),
  348. MACROSTR(kWh),
  349. MACROSTR(varh),
  350. MACROSTR(kvarh),
  351. MACROSTR(W),
  352. MACROSTR(kW),
  353. MACROSTR(VA),
  354. MACROSTR(kVA),
  355. MACROSTR(var),
  356. MACROSTR(kvar),
  357. MACROSTR(A),
  358. MACROSTR(V),
  359. MACROSTR(Celsius),
  360. MACROSTR(Fahrenheit),
  361. MACROSTR(K),
  362. MACROSTR(Percent)
  363. };
  364. //==========================================
  365. // Check time passed since today
  366. //==========================================
  367. long long DiffTimebWithNow(struct timeb ST)
  368. {
  369. //return milli-second
  370. struct timeb ET;
  371. long long StartTime,StopTime;
  372. ftime(&ET);
  373. StartTime=(long long)ST.time;
  374. StopTime=(long long)ET.time;
  375. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  376. }
  377. int getTimePassSinceToday()
  378. {
  379. int result = -1;
  380. time_t t;
  381. struct tm *tmStartToday;
  382. struct timeb tbStartToday;
  383. t=time(NULL);
  384. tmStartToday=localtime(&t);
  385. tmStartToday->tm_hour = 0;
  386. tmStartToday->tm_min = 0;
  387. tmStartToday->tm_sec = 0;
  388. tbStartToday.time = mktime(tmStartToday);
  389. tbStartToday.millitm = 0;
  390. result = DiffTimebWithNow(tbStartToday)/1000;
  391. return result;
  392. }
  393. //==========================================
  394. // GetCompositeSchedule logic related function
  395. //==========================================
  396. int DiffTimebSec(struct timeb ST, struct timeb ET)
  397. {
  398. //return milli-second
  399. unsigned int StartTime,StopTime;
  400. StartTime=(unsigned int)ST.time;
  401. StopTime=(unsigned int)ET.time;
  402. return (StopTime-StartTime);
  403. }
  404. int DiffTimebWithNowSec(struct timeb ST)
  405. {
  406. //return milli-second
  407. struct timeb ET;
  408. unsigned int StartTime,StopTime;
  409. ftime(&ET);
  410. StartTime=(unsigned int)ST.time;
  411. StopTime=(unsigned int)ET.time;
  412. return (StopTime-StartTime);
  413. }
  414. int getStartStop(uint8_t *start, uint8_t *stop)
  415. {
  416. int result = -1;
  417. struct tm tmStart;
  418. struct timeb tbStart;
  419. struct tm tmStop;
  420. struct timeb tbStop;
  421. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  422. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  423. {
  424. tmStart.tm_year -= 1900;
  425. tmStart.tm_mon -= 1;
  426. tbStart.time = mktime(&tmStart);
  427. tbStart.millitm = 0;
  428. tmStop.tm_year -= 1900;
  429. tmStop.tm_mon -= 1;
  430. tbStop.time = mktime(&tmStop);
  431. tbStop.millitm = 0;
  432. result = DiffTimebSec(tbStart, tbStop);
  433. }
  434. else
  435. {
  436. DEBUG_WARN("Start or stop date parsing error.\r\n");
  437. }
  438. return result;
  439. }
  440. int getStartSinceToday(uint8_t *stop)
  441. {
  442. int result = -1;
  443. time_t t;
  444. struct tm *tmStartToday;
  445. struct timeb tbStartToday;
  446. struct tm tmStop;
  447. struct timeb tbStop;
  448. 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))
  449. {
  450. t=time(NULL);
  451. tmStartToday=localtime(&t);
  452. tmStartToday->tm_hour = 0;
  453. tmStartToday->tm_min = 0;
  454. tmStartToday->tm_sec = 0;
  455. tbStartToday.time = mktime(tmStartToday);
  456. tmStop.tm_year -= 1900;
  457. tmStop.tm_mon -= 1;
  458. tbStop.time = mktime(&tmStop);
  459. tbStop.millitm = 0;
  460. result = DiffTimebSec(tbStartToday, tbStop);
  461. }
  462. return result;
  463. }
  464. int getStartSinceWeek(uint8_t *stop)
  465. {
  466. int result = -1;
  467. time_t t;
  468. struct tm *tmStartWeek;
  469. struct timeb tbStartWeek;
  470. struct tm tmStop;
  471. struct timeb tbStop;
  472. 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))
  473. {
  474. t=time(NULL);
  475. tmStartWeek=localtime(&t);
  476. t-=86400*tmStartWeek->tm_wday;
  477. tmStartWeek=localtime(&t);
  478. tmStartWeek->tm_hour = 0;
  479. tmStartWeek->tm_min = 0;
  480. tmStartWeek->tm_sec = 0;
  481. tbStartWeek.time = mktime(tmStartWeek);
  482. tmStop.tm_year -= 1900;
  483. tmStop.tm_mon -= 1;
  484. tbStop.time = mktime(&tmStop);
  485. tbStop.millitm = 0;
  486. result = DiffTimebSec(tbStartWeek, tbStop);
  487. }
  488. return result;
  489. }
  490. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  491. {
  492. FILE *fp;
  493. char profileFileName[128];
  494. char *line = NULL;
  495. size_t len = 0;
  496. time_t CurrentTime;
  497. struct tm *tmComposite;
  498. struct StructChargingProfile maxProfile;
  499. struct StructChargingProfile defaultTxProfile;
  500. struct StructChargingProfile txProfile;
  501. struct StructChargingSchedulePeriod tmpPeriod;
  502. uint8_t limitMax=0;
  503. uint8_t limitDef=0;
  504. uint8_t limitTx=0;
  505. int compositePeriodIdx = 0;
  506. CurrentTime = time(NULL);
  507. tmComposite=localtime(&CurrentTime);
  508. 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);
  509. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  510. compositeProfile->ChargingSchedule.Duration = durationReq;
  511. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  512. {
  513. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  514. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  515. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  516. }
  517. compositeProfile->ChargingProfileId = 0;
  518. compositeProfile->StackLevel = 99 ;
  519. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  520. maxProfile.ChargingProfileId = -1;
  521. defaultTxProfile.ChargingProfileId = -1;
  522. txProfile.ChargingProfileId = -1;
  523. system("yes|rm /tmp/*.json");
  524. system("cp /Storage/OCPP/*.json /tmp");
  525. /*
  526. * Search valid charging profile
  527. */
  528. //DEBUG_INFO("====================================\n");
  529. // Search tx profile
  530. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  531. if((access(profileFileName, F_OK))!=-1)
  532. {
  533. fp = fopen(profileFileName, "r");
  534. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  535. {
  536. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  537. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  538. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  539. }
  540. txProfile.ChargingProfileId = -1;
  541. txProfile.StackLevel = -1;
  542. while(getline(&line, &len, fp) != -1)
  543. {
  544. json_object *obj = NULL;
  545. obj = json_tokener_parse(line);
  546. if(is_error(obj))
  547. {
  548. DEBUG_ERROR("Parse txProfile from file error.\n");
  549. }
  550. else
  551. {
  552. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  553. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  554. )
  555. {
  556. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  557. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  558. )
  559. {
  560. struct tm tmFrom, tmTo;
  561. struct timeb tbFrom, tbTo;
  562. 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) &&
  563. (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))
  564. {
  565. tmFrom.tm_year -= 1900;
  566. tmFrom.tm_mon -= 1;
  567. tbFrom.time = mktime(&tmFrom);
  568. tmTo.tm_year -= 1900;
  569. tmTo.tm_mon -= 1;
  570. tbTo.time = mktime(&tmTo);
  571. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  572. {
  573. if(txProfile.ChargingProfileId == -1)
  574. DEBUG_INFO("TxProfile found.\n");
  575. else
  576. DEBUG_INFO("TxProfile updated.\n");
  577. // Required item
  578. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  579. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  580. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  581. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  582. 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++)
  583. {
  584. 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"));
  585. 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")));
  586. 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?
  587. 3:
  588. 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")));
  589. }
  590. // Optional item
  591. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  592. {
  593. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  594. }
  595. else
  596. {
  597. sprintf((char*)txProfile.ValidFrom, " ");
  598. }
  599. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  600. {
  601. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  602. }
  603. else
  604. {
  605. sprintf((char*)txProfile.ValidTo, " ");
  606. }
  607. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  608. {
  609. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  610. }
  611. else
  612. {
  613. sprintf((char*)txProfile.RecurrencyKind, " ");
  614. }
  615. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  616. {
  617. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  618. }
  619. else
  620. {
  621. txProfile.TransactionId = -1;
  622. }
  623. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  624. {
  625. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  626. }
  627. else
  628. {
  629. txProfile.ChargingSchedule.Duration = 86400;
  630. }
  631. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  632. {
  633. 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")));
  634. }
  635. else
  636. {
  637. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, " ");
  638. }
  639. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  640. {
  641. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  642. }
  643. else
  644. {
  645. txProfile.ChargingSchedule.MinChargingRate = -1;
  646. }
  647. }
  648. }
  649. }
  650. else
  651. {
  652. if(txProfile.ChargingProfileId == -1)
  653. DEBUG_INFO("TxProfile found.\n");
  654. else
  655. DEBUG_INFO("TxProfile updated.\n");
  656. // Required item
  657. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  658. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  659. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  660. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  661. 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++)
  662. {
  663. 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"));
  664. 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")));
  665. 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?
  666. 3:
  667. 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")));
  668. }
  669. // Optional item
  670. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  671. {
  672. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  673. }
  674. else
  675. {
  676. sprintf((char*)txProfile.ValidFrom, " ");
  677. }
  678. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  679. {
  680. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  681. }
  682. else
  683. {
  684. sprintf((char*)txProfile.ValidTo, " ");
  685. }
  686. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  687. {
  688. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  689. }
  690. else
  691. {
  692. sprintf((char*)txProfile.RecurrencyKind, " ");
  693. }
  694. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  695. {
  696. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  697. }
  698. else
  699. {
  700. txProfile.TransactionId = -1;
  701. }
  702. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  703. {
  704. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  705. }
  706. else
  707. {
  708. txProfile.ChargingSchedule.Duration = 86400;
  709. }
  710. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  711. {
  712. 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")));
  713. }
  714. else
  715. {
  716. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, " ");
  717. }
  718. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  719. {
  720. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  721. }
  722. else
  723. {
  724. maxProfile.ChargingSchedule.MinChargingRate = -1;
  725. }
  726. }
  727. }
  728. }
  729. json_object_put(obj);
  730. }
  731. fclose(fp);
  732. /*
  733. if(defaultTxProfile.ChargingProfileId != -1)
  734. {
  735. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  736. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  737. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  738. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  739. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  740. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  741. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  742. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  743. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  744. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  745. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  746. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  747. {
  748. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  749. {
  750. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  751. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  752. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  753. }
  754. }
  755. }
  756. else
  757. DEBUG_INFO("TxProfile not found.\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 = 86400;
  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 = 86400;
  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 max profile
  993. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  994. if((access(profileFileName, F_OK))!=-1)
  995. {
  996. fp = fopen(profileFileName, "r");
  997. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  998. {
  999. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1000. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1001. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1002. }
  1003. maxProfile.ChargingProfileId = -1;
  1004. maxProfile.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 MaxProfile 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")) != maxProfile.ChargingProfileId) &&
  1016. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.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(maxProfile.ChargingProfileId == -1)
  1037. DEBUG_INFO("MaxProfile found.\n");
  1038. else
  1039. DEBUG_INFO("MaxProfile updated.\n");
  1040. // Required item
  1041. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1042. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1043. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1044. sprintf((char*)maxProfile.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. 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"));
  1048. 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")));
  1049. 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?
  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*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1057. }
  1058. else
  1059. {
  1060. sprintf((char*)maxProfile.ValidFrom, " ");
  1061. }
  1062. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1063. {
  1064. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1065. }
  1066. else
  1067. {
  1068. sprintf((char*)maxProfile.ValidTo, " ");
  1069. }
  1070. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1071. {
  1072. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1073. }
  1074. else
  1075. {
  1076. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1077. }
  1078. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1079. {
  1080. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1081. }
  1082. else
  1083. {
  1084. maxProfile.TransactionId = -1;
  1085. }
  1086. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1087. {
  1088. maxProfile.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. maxProfile.ChargingSchedule.Duration = 86400;
  1093. }
  1094. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1095. {
  1096. 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")));
  1097. }
  1098. else
  1099. {
  1100. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, " ");
  1101. }
  1102. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1103. {
  1104. maxProfile.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. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1109. }
  1110. }
  1111. }
  1112. }
  1113. else
  1114. {
  1115. if(maxProfile.ChargingProfileId == -1)
  1116. DEBUG_INFO("MaxProfile found.\n");
  1117. else
  1118. DEBUG_INFO("MaxProfile updated.\n");
  1119. // Required item
  1120. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1121. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1122. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1123. sprintf((char*)maxProfile.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. 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"));
  1127. 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")));
  1128. 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?
  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*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1136. }
  1137. else
  1138. {
  1139. sprintf((char*)maxProfile.ValidFrom, " ");
  1140. }
  1141. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1142. {
  1143. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1144. }
  1145. else
  1146. {
  1147. sprintf((char*)maxProfile.ValidTo, " ");
  1148. }
  1149. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1150. {
  1151. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1152. }
  1153. else
  1154. {
  1155. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1156. }
  1157. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1158. {
  1159. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1160. }
  1161. else
  1162. {
  1163. maxProfile.TransactionId = -1;
  1164. }
  1165. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1166. {
  1167. maxProfile.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. maxProfile.ChargingSchedule.Duration = 86400;
  1172. }
  1173. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1174. {
  1175. 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")));
  1176. }
  1177. else
  1178. {
  1179. sprintf((char*)maxProfile.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(maxProfile.ChargingProfileId !=-1)
  1197. {
  1198. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1199. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1200. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1201. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1202. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1203. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1204. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1205. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1206. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1207. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1208. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1209. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1210. {
  1211. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1212. {
  1213. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1214. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1215. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1216. }
  1217. }
  1218. }
  1219. else
  1220. DEBUG_INFO("MaxProfile not found.\n");
  1221. DEBUG_INFO("------------------------------------\n");*/
  1222. }
  1223. /*
  1224. * Align found profile start schedule & periods
  1225. */
  1226. //DEBUG_INFO("====================================\n");
  1227. /*
  1228. // For local test usage, force modify found profile start schedule info
  1229. 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);
  1230. 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);
  1231. 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);
  1232. */
  1233. if(txProfile.ChargingProfileId != -1)
  1234. {
  1235. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1236. {
  1237. if(txProfile.ChargingSchedule.Duration != -1)
  1238. {
  1239. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1240. 0:
  1241. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1242. }
  1243. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1244. {
  1245. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1246. {
  1247. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1248. 0:
  1249. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1250. if(idxPeriod > 0)
  1251. {
  1252. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1253. {
  1254. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1255. }
  1256. }
  1257. }
  1258. }
  1259. }
  1260. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1261. {
  1262. if(txProfile.ChargingSchedule.Duration != -1)
  1263. {
  1264. 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?
  1265. 0:
  1266. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1267. }
  1268. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1269. {
  1270. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1271. {
  1272. 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?
  1273. 0:
  1274. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1275. if(idxPeriod > 0)
  1276. {
  1277. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1278. {
  1279. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1280. }
  1281. }
  1282. }
  1283. }
  1284. }
  1285. else
  1286. {
  1287. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1288. {
  1289. if(txProfile.ChargingSchedule.Duration != -1)
  1290. {
  1291. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1292. 0:
  1293. (txProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1294. }
  1295. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1296. {
  1297. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1298. {
  1299. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1300. 0:
  1301. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1302. if(idxPeriod > 0)
  1303. {
  1304. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1305. {
  1306. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1307. }
  1308. }
  1309. }
  1310. }
  1311. }
  1312. else
  1313. {
  1314. if(txProfile.ChargingSchedule.Duration != -1)
  1315. {
  1316. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1317. 0:
  1318. (txProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1319. }
  1320. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1321. {
  1322. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1323. {
  1324. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1325. 0:
  1326. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1327. if(idxPeriod > 0)
  1328. {
  1329. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1330. {
  1331. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1332. }
  1333. }
  1334. }
  1335. }
  1336. }
  1337. }
  1338. /*
  1339. DEBUG_INFO("txProfile after align.\n");
  1340. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1341. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1342. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1343. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1344. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1345. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1346. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1347. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1348. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1349. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1350. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1351. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1352. {
  1353. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1354. {
  1355. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1356. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1357. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1358. }
  1359. }*/
  1360. }
  1361. if(defaultTxProfile.ChargingProfileId != -1)
  1362. {
  1363. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1364. {
  1365. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1366. {
  1367. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1368. 0:
  1369. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1370. }
  1371. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1372. {
  1373. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1374. {
  1375. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1376. 0:
  1377. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1378. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1379. {
  1380. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1381. }
  1382. if(idxPeriod > 0)
  1383. {
  1384. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1385. {
  1386. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1387. }
  1388. }
  1389. }
  1390. }
  1391. }
  1392. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1393. {
  1394. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1395. {
  1396. 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?
  1397. 0:
  1398. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1399. }
  1400. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1401. {
  1402. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1403. {
  1404. 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?
  1405. 0:
  1406. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1407. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1408. {
  1409. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1410. }
  1411. if(idxPeriod > 0)
  1412. {
  1413. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1414. {
  1415. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1416. }
  1417. }
  1418. }
  1419. }
  1420. }
  1421. else
  1422. {
  1423. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1424. {
  1425. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1426. {
  1427. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1428. 0:
  1429. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1430. }
  1431. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1432. {
  1433. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1434. {
  1435. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1436. 0:
  1437. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1438. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1439. {
  1440. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1441. }
  1442. if(idxPeriod > 0)
  1443. {
  1444. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1445. {
  1446. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1447. }
  1448. }
  1449. }
  1450. }
  1451. }
  1452. else
  1453. {
  1454. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1455. {
  1456. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1457. 0:
  1458. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1459. }
  1460. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1461. {
  1462. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1463. {
  1464. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1465. 0:
  1466. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1467. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1468. {
  1469. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1470. }
  1471. if(idxPeriod > 0)
  1472. {
  1473. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1474. {
  1475. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1476. }
  1477. }
  1478. }
  1479. }
  1480. }
  1481. }
  1482. /*
  1483. DEBUG_INFO("defaultTxProfile after align.\n");
  1484. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1485. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1486. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1487. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1488. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1489. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1490. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1491. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1492. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1493. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1494. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1495. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1496. {
  1497. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1498. {
  1499. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1500. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1501. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1502. }
  1503. }
  1504. DEBUG_INFO("------------------------------------\n");*/
  1505. }
  1506. if(maxProfile.ChargingProfileId != -1)
  1507. {
  1508. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1509. {
  1510. if(maxProfile.ChargingSchedule.Duration != -1)
  1511. {
  1512. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1513. 0:
  1514. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1515. }
  1516. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1517. {
  1518. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1519. {
  1520. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1521. 0:
  1522. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1523. if(idxPeriod > 0)
  1524. {
  1525. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1526. {
  1527. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1528. }
  1529. }
  1530. }
  1531. }
  1532. }
  1533. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1534. {
  1535. if(maxProfile.ChargingSchedule.Duration != -1)
  1536. {
  1537. 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?
  1538. 0:
  1539. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1540. }
  1541. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1542. {
  1543. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1544. {
  1545. 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?
  1546. 0:
  1547. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1548. if(idxPeriod > 0)
  1549. {
  1550. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1551. {
  1552. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1553. }
  1554. }
  1555. }
  1556. }
  1557. }
  1558. else
  1559. {
  1560. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1561. {
  1562. if(maxProfile.ChargingSchedule.Duration != -1)
  1563. {
  1564. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1565. 0:
  1566. (maxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1567. }
  1568. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1569. {
  1570. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1571. {
  1572. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1573. 0:
  1574. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1575. if(idxPeriod > 0)
  1576. {
  1577. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1578. {
  1579. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1580. }
  1581. }
  1582. }
  1583. }
  1584. }
  1585. else
  1586. {
  1587. if(maxProfile.ChargingSchedule.Duration != -1)
  1588. {
  1589. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1590. 0:
  1591. (maxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1592. }
  1593. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1594. {
  1595. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1596. {
  1597. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1598. 0:
  1599. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1600. if(idxPeriod > 0)
  1601. {
  1602. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1603. {
  1604. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1605. }
  1606. }
  1607. }
  1608. }
  1609. }
  1610. }
  1611. /*
  1612. DEBUG_INFO("MaxProfile after align.\n");
  1613. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1614. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1615. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1616. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1617. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1618. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1619. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1620. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1621. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1622. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1623. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1624. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1625. {
  1626. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1627. {
  1628. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1629. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1630. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1631. }
  1632. }
  1633. DEBUG_INFO("------------------------------------\n");*/
  1634. }
  1635. /*
  1636. * Merge to conposite schedule
  1637. */
  1638. //DEBUG_INFO("====================================\n");
  1639. // Find each profile period quantity
  1640. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1641. {
  1642. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1643. limitMax = idx+1;
  1644. }
  1645. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1646. {
  1647. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1648. limitDef = idx+1;
  1649. }
  1650. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1651. {
  1652. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1653. limitTx = idx+1;
  1654. }
  1655. // TxProfile found, composite schedule based on it
  1656. if(txProfile.ChargingProfileId != -1)
  1657. {
  1658. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1659. {
  1660. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1661. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  1662. (txProfile.ChargingSchedule.Duration > 0))
  1663. {
  1664. if(maxProfile.ChargingProfileId != -1)
  1665. {
  1666. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1667. {
  1668. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  1669. {
  1670. if((maxProfile.ChargingSchedule.Duration > 0))
  1671. {
  1672. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1673. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1674. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1675. }
  1676. else
  1677. {
  1678. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1679. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1680. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  1681. }
  1682. }
  1683. if(idxMaxPeriod == (limitMax-1))
  1684. {
  1685. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1686. {
  1687. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1688. {
  1689. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1690. compositePeriodIdx++;
  1691. }
  1692. else
  1693. {
  1694. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1695. }
  1696. }
  1697. }
  1698. }
  1699. }
  1700. else
  1701. {
  1702. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1703. {
  1704. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1705. compositePeriodIdx++;
  1706. }
  1707. else
  1708. {
  1709. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1710. }
  1711. }
  1712. }
  1713. if(idxTxPeriod == (limitTx-1))
  1714. {
  1715. if(defaultTxProfile.ChargingProfileId != -1)
  1716. {
  1717. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1718. {
  1719. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  1720. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1721. (defaultTxProfile.ChargingSchedule.Duration>0))
  1722. {
  1723. if(maxProfile.ChargingProfileId != -1)
  1724. {
  1725. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1726. {
  1727. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1728. {
  1729. if((maxProfile.ChargingSchedule.Duration > 0))
  1730. {
  1731. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1732. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1733. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1734. }
  1735. else
  1736. {
  1737. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1738. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1739. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1740. }
  1741. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1742. {
  1743. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1744. {
  1745. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1746. compositePeriodIdx++;
  1747. }
  1748. else
  1749. {
  1750. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1751. }
  1752. }
  1753. break;
  1754. }
  1755. }
  1756. }
  1757. else
  1758. {
  1759. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1760. {
  1761. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1762. compositePeriodIdx++;
  1763. }
  1764. else
  1765. {
  1766. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1767. }
  1768. }
  1769. }
  1770. }
  1771. }
  1772. }
  1773. }
  1774. }
  1775. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1776. else if(defaultTxProfile.ChargingProfileId != -1)
  1777. {
  1778. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1779. {
  1780. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1781. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1782. (defaultTxProfile.ChargingSchedule.Duration > 0))
  1783. {
  1784. if(maxProfile.ChargingProfileId != -1)
  1785. {
  1786. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1787. {
  1788. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1789. {
  1790. if((maxProfile.ChargingSchedule.Duration > 0))
  1791. {
  1792. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1793. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1794. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1795. }
  1796. else
  1797. {
  1798. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1799. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1800. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1801. }
  1802. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1803. {
  1804. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1805. {
  1806. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1807. compositePeriodIdx++;
  1808. }
  1809. else
  1810. {
  1811. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1812. }
  1813. }
  1814. break;
  1815. }
  1816. }
  1817. }
  1818. else
  1819. {
  1820. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1821. {
  1822. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1823. compositePeriodIdx++;
  1824. }
  1825. else
  1826. {
  1827. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1828. }
  1829. }
  1830. }
  1831. }
  1832. }
  1833. // Fill other period by MaxProfile
  1834. if(maxProfile.ChargingProfileId != -1)
  1835. {
  1836. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1837. {
  1838. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1839. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1840. (maxProfile.ChargingSchedule.Duration > 0))
  1841. {
  1842. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  1843. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1844. {
  1845. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  1846. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  1847. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1848. }
  1849. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1850. {
  1851. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  1852. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  1853. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1854. }
  1855. if(tmpPeriod.Limit != -1)
  1856. {
  1857. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1858. {
  1859. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1860. {
  1861. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1862. compositePeriodIdx++;
  1863. }
  1864. else
  1865. {
  1866. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1867. }
  1868. }
  1869. }
  1870. }
  1871. }
  1872. }
  1873. DEBUG_INFO("Composite schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1874. DEBUG_INFO("Composite schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1875. DEBUG_INFO("Composite rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1876. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1877. {
  1878. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1879. {
  1880. compositeProfile->ChargingProfileId = 1;
  1881. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1882. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1883. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1884. }
  1885. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1886. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1887. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1888. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1889. }
  1890. if(line)
  1891. free(line);
  1892. }
  1893. //==========================================
  1894. // Init all share memory
  1895. //==========================================
  1896. int InitShareMemory()
  1897. {
  1898. int result = PASS;
  1899. int MeterSMId;
  1900. //creat ShmSysConfigAndInfo
  1901. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1902. {
  1903. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1904. result = FAIL;
  1905. }
  1906. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1907. {
  1908. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  1909. result = FAIL;
  1910. }
  1911. else
  1912. {}
  1913. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1914. {
  1915. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1916. result = FAIL;
  1917. }
  1918. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1919. {
  1920. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1921. result = FAIL;
  1922. }
  1923. else
  1924. {}
  1925. //creat ShmPsuData
  1926. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  1927. {
  1928. DEBUG_ERROR("shmget ShmPsuData NG\n");
  1929. result = FAIL;
  1930. }
  1931. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1932. {
  1933. DEBUG_ERROR("shmat ShmPsuData NG\n");
  1934. result = FAIL;
  1935. }
  1936. else
  1937. {}
  1938. //creat ShmOCPP16Data
  1939. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1940. {
  1941. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  1942. result = FAIL;
  1943. }
  1944. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1945. {
  1946. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  1947. result = FAIL;
  1948. }
  1949. else
  1950. {}
  1951. /****************************** For Initial Settings************************************************/
  1952. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  1953. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  1954. // allocate Configuration memory address
  1955. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  1956. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  1957. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  1958. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  1959. //offline MeterValue Interval
  1960. TempMeterValueInterval = 0;
  1961. return result;
  1962. }
  1963. int ProcessShareMemory()
  1964. {
  1965. if(InitShareMemory() == FAIL)
  1966. {
  1967. DEBUG_ERROR("InitShareMemory NG\n");
  1968. if(ShmStatusCodeData!=NULL)
  1969. {
  1970. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1971. }
  1972. sleep(5);
  1973. return FAIL;
  1974. }
  1975. return PASS;
  1976. }
  1977. //---------------------common routine---------------------------//
  1978. int isOFFline(void)
  1979. {
  1980. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  1981. {
  1982. if(TempMeterValueInterval >= 2 )
  1983. {
  1984. TempMeterValueInterval = 0;
  1985. return TRUE;
  1986. }
  1987. else
  1988. {
  1989. TempMeterValueInterval = TempMeterValueInterval+ 1;
  1990. return FALSE;
  1991. }
  1992. }
  1993. else
  1994. {
  1995. return FALSE;
  1996. }
  1997. }
  1998. //---------------------------------------------
  1999. // new:
  2000. // enum SYSTEM_STATUS
  2001. // {
  2002. // SYS_MODE_BOOTING = 0,
  2003. // SYS_MODE_IDLE = 1,
  2004. // SYS_MODE_AUTHORIZING = 2,
  2005. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  2006. // SYS_MODE_REASSIGN = 4,
  2007. // SYS_MODE_PREPARING = 5,
  2008. // SYS_MODE_PREPARE_FOR_EV = 6,
  2009. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  2010. // SYS_MODE_CHARGING = 8,
  2011. // SYS_MODE_TERMINATING = 9,
  2012. // SYS_MODE_COMPLETE = 10,
  2013. // SYS_MODE_ALARM = 11,
  2014. // SYS_MODE_FAULT = 12,
  2015. // SYS_MODE_RESERVATION = 13,
  2016. // SYS_MODE_BOOKING = 14,
  2017. // SYS_MODE_MAINTAIN = 15,
  2018. // SYS_MODE_DEBUG = 16,
  2019. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  2020. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  2021. // SYS_MODE_UPDATE = 19
  2022. // };
  2023. //
  2024. //
  2025. //-----------------------------------------
  2026. void CheckSystemValue(void)
  2027. {
  2028. uint8_t reqSampleMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2029. uint8_t reqClockAlignMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2030. char filenmae[100]={0};
  2031. char str[100]={0};
  2032. int tempIndex = 0;
  2033. //===============================
  2034. // send Heartbeat
  2035. //===============================
  2036. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2037. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2038. {
  2039. clientTime.Heartbeat=time((time_t*)NULL);
  2040. if(server_sign == TRUE)
  2041. {
  2042. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2043. }
  2044. else
  2045. {
  2046. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2047. }
  2048. }
  2049. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  2050. {
  2051. //parameter for test
  2052. sendHeartbeatRequest(0);
  2053. //==============================================
  2054. // Reset Waiting Time
  2055. //==============================================
  2056. clientTime.Heartbeat=time((time_t*)NULL);
  2057. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  2058. }
  2059. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2060. {
  2061. //===============================
  2062. // CSU Trigger Reset Conf
  2063. //===============================
  2064. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2065. {
  2066. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2067. }
  2068. //===============================
  2069. // CSU Trigger Authorize Request
  2070. //===============================
  2071. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2072. {
  2073. sendAuthorizeRequest(0);
  2074. authorizeRetryTimes = authorizeRetryTimes + 1;
  2075. if(authorizeRetryTimes < 3)
  2076. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2077. }
  2078. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2079. {
  2080. authorizeRetryTimes = 0;
  2081. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  2082. server_sign = FALSE;
  2083. }
  2084. 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))
  2085. {
  2086. sendAuthorizeRequest(0);
  2087. }
  2088. //===============================
  2089. // CSU Trigger Smart Charging Profilw
  2090. //===============================
  2091. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2092. {
  2093. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2094. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  2095. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  2096. }
  2097. //==============================================
  2098. // Charger start transaction
  2099. //==============================================
  2100. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2101. {
  2102. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  2103. sendStartTransactionRequest(gun_index);
  2104. clientTime.StartTransaction = time((time_t*)NULL);
  2105. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2106. }
  2107. //==============================================
  2108. // Charger stop transaction
  2109. //==============================================
  2110. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2111. {
  2112. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  2113. sendStopTransactionRequest(gun_index);
  2114. clientTime.StopTransaction = time((time_t*)NULL);
  2115. }
  2116. //==============================================
  2117. // Charger status report
  2118. //==============================================
  2119. //--- Check Mode Change ---//
  2120. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2121. if(gunType[gun_index] == 'J')
  2122. {
  2123. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2124. {
  2125. tempIndex = ((gun_index==2) ? 1: 0);
  2126. }
  2127. else
  2128. {
  2129. tempIndex = gun_index;
  2130. }
  2131. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2132. {
  2133. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2134. {
  2135. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2136. {
  2137. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2138. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2139. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2140. statusModeChage[gun_index] = TRUE;
  2141. }
  2142. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2143. {
  2144. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2145. if((access(filenmae,F_OK))!=-1)
  2146. {
  2147. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2148. sprintf(str,"rm -f %s",filenmae);
  2149. system(str);
  2150. }
  2151. }
  2152. #if 1 // for TempStopTransaction
  2153. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2154. {
  2155. checkTempStopTransaction(gun_index);
  2156. }
  2157. #endif
  2158. }
  2159. }
  2160. }
  2161. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2162. {
  2163. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2164. {
  2165. tempIndex = ((gun_index==2) ? 1: 0);
  2166. }
  2167. else
  2168. {
  2169. tempIndex = gun_index;
  2170. }
  2171. for (int index = 0; index < CCS_QUANTITY; index++)
  2172. {
  2173. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2174. {
  2175. 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]*/ )
  2176. {
  2177. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2178. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2179. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2180. statusModeChage[gun_index] = TRUE;
  2181. }
  2182. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2183. {
  2184. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2185. if((access(filenmae,F_OK))!=-1)
  2186. {
  2187. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2188. sprintf(str,"rm -f %s",filenmae);
  2189. system(str);
  2190. }
  2191. }
  2192. #if 1 // for TempStopTransaction
  2193. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2194. {
  2195. checkTempStopTransaction(gun_index);
  2196. }
  2197. #endif
  2198. }
  2199. }
  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. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2214. {
  2215. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2216. {
  2217. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2218. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2219. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2220. statusModeChage[gun_index] = TRUE;
  2221. }
  2222. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2223. {
  2224. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2225. if((access(filenmae,F_OK))!=-1)
  2226. {
  2227. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2228. sprintf(str,"rm -f %s",filenmae);
  2229. system(str);
  2230. }
  2231. }
  2232. #if 1 // for TempStopTransaction
  2233. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2234. {
  2235. checkTempStopTransaction(gun_index);
  2236. }
  2237. #endif
  2238. }
  2239. }
  2240. }
  2241. else
  2242. {
  2243. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2244. {
  2245. tempIndex = 2;
  2246. }
  2247. else
  2248. {
  2249. tempIndex = gun_index;
  2250. }
  2251. for (int index = 0; index < AC_QUANTITY; index++)
  2252. {
  2253. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2254. {
  2255. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2256. {
  2257. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2258. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2259. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2260. statusModeChage[gun_index] = TRUE;
  2261. }
  2262. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2263. {
  2264. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2265. if((access(filenmae,F_OK))!=-1)
  2266. {
  2267. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2268. sprintf(str,"rm -f %s",filenmae);
  2269. system(str);
  2270. }
  2271. }
  2272. #if 1 // for TempStopTransaction
  2273. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2274. {
  2275. checkTempStopTransaction(gun_index);
  2276. }
  2277. #endif
  2278. }
  2279. }// END
  2280. }
  2281. if(isWebsocketSendable &&
  2282. ((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)))) )
  2283. {
  2284. if(SystemInitial > 0)
  2285. SystemInitial -= 1;
  2286. sendStatusNotificationRequest(gun_index);
  2287. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2288. statusModeChage[gun_index] = FALSE;
  2289. }
  2290. //==============================================
  2291. // Meter report
  2292. //==============================================
  2293. if(cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2294. {
  2295. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2296. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2297. }
  2298. if(/*(server_sign == TRUE) &&(isOFFline() == TRUE) ||*/
  2299. (((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)))
  2300. {
  2301. //check Transaction active
  2302. if(gunType[gun_index] == 'J')
  2303. {
  2304. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2305. {
  2306. tempIndex = ((gun_index==2) ? 1: 0);
  2307. }
  2308. else
  2309. {
  2310. tempIndex = gun_index;
  2311. }
  2312. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2313. {
  2314. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2315. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2316. {
  2317. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2318. {
  2319. reqSampleMeter[gun_index] = 1;
  2320. }
  2321. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2322. {
  2323. reqClockAlignMeter[gun_index] = 1;
  2324. }
  2325. }
  2326. }// End for CHAdeMO
  2327. }
  2328. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2329. {
  2330. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2331. {
  2332. tempIndex = ((gun_index==2) ? 1: 0);
  2333. }
  2334. else
  2335. {
  2336. tempIndex = gun_index;
  2337. }
  2338. for (int index = 0; index < CCS_QUANTITY; index++)
  2339. {
  2340. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2341. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2342. {
  2343. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2344. {
  2345. reqSampleMeter[gun_index] = 1;
  2346. }
  2347. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2348. {
  2349. reqClockAlignMeter[gun_index] = 1;
  2350. }
  2351. }
  2352. } // End for CCS
  2353. }
  2354. else if(gunType[gun_index] == 'G')
  2355. {
  2356. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2357. {
  2358. tempIndex = ((gun_index==2) ? 1: 0);
  2359. }
  2360. else
  2361. {
  2362. tempIndex = gun_index;
  2363. }
  2364. for (int index = 0; index < GB_QUANTITY; index++)
  2365. {
  2366. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2367. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2368. {
  2369. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2370. {
  2371. reqSampleMeter[gun_index] = 1;
  2372. }
  2373. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2374. {
  2375. reqClockAlignMeter[gun_index] = 1;
  2376. }
  2377. }
  2378. }// End for GB
  2379. }
  2380. else
  2381. {
  2382. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2383. {
  2384. tempIndex = 2;
  2385. }
  2386. else
  2387. {
  2388. tempIndex = gun_index;
  2389. }
  2390. for (int index = 0; index < AC_QUANTITY; index++)
  2391. {
  2392. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2393. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2394. {
  2395. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2396. {
  2397. reqSampleMeter[gun_index] = 1;
  2398. }
  2399. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2400. {
  2401. reqClockAlignMeter[gun_index] = 1;
  2402. }
  2403. }
  2404. }//End for AC
  2405. }
  2406. if(reqSampleMeter[gun_index] == 1)
  2407. {
  2408. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2409. storeTempStopTransaction(gun_index);
  2410. }
  2411. else if(reqClockAlignMeter[gun_index] == 1)
  2412. {
  2413. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2414. }
  2415. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2416. sleep(1);
  2417. }
  2418. //==============================================
  2419. // Check Connector reserved
  2420. //==============================================
  2421. //===============================
  2422. // Check if Reserve is expired
  2423. //===============================
  2424. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2425. {
  2426. double diff_t;
  2427. struct tm tp;
  2428. // current time
  2429. time_t t = time(NULL);
  2430. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2431. tp.tm_isdst = -1;
  2432. time_t utc = mktime(&tp);
  2433. diff_t = difftime(utc, t);
  2434. if(diff_t <= 0)
  2435. {
  2436. DEBUG_INFO("reserve expired.\n");
  2437. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2438. }
  2439. }//END OF Check if Reserve is expired
  2440. //==========================================
  2441. // csu trigger FirmwareStatusNotificationReq
  2442. //==========================================
  2443. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2444. {
  2445. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2446. }
  2447. //==========================================
  2448. // csu trigger CancelReservationConf
  2449. //==========================================
  2450. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2451. {
  2452. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2453. }
  2454. //==========================================
  2455. // csu trigger ChangeAvailabilityConf
  2456. //==========================================
  2457. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2458. {
  2459. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2460. }
  2461. //==========================================
  2462. // csu trigger UnlockConnectorConf
  2463. //==========================================
  2464. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2465. {
  2466. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2467. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2468. }
  2469. //==========================================
  2470. // csu trigger ReserveNowConf
  2471. //==========================================
  2472. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2473. {
  2474. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2475. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2476. }
  2477. //==========================================
  2478. // csu trigger DataTransferReq
  2479. //==========================================
  2480. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2481. {
  2482. sendDataTransferRequest(gun_index);
  2483. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2484. }
  2485. }
  2486. }
  2487. //==========================================
  2488. // send request routine
  2489. //==========================================
  2490. int sendAuthorizeRequest(int gun_index)
  2491. {
  2492. mtrace();
  2493. int result = FAIL;
  2494. char message[100]={0};
  2495. char guid[37];
  2496. char tempdata[65]={0};
  2497. DEBUG_INFO("sendAuthorizeRequest...\n");
  2498. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2499. //Local Authorize
  2500. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2501. {
  2502. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2503. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2504. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2505. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2506. result = PASS;
  2507. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2508. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2509. authorizeRetryTimes = 0;
  2510. return result;
  2511. }
  2512. 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))||
  2513. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2514. {
  2515. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2516. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2517. {
  2518. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2519. {
  2520. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2521. }
  2522. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2523. {
  2524. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2525. }
  2526. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  2527. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2528. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2529. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2530. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2531. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2532. authorizeRetryTimes = 0;
  2533. return result;
  2534. }
  2535. else
  2536. {
  2537. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  2538. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2539. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2540. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2541. result = PASS;
  2542. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2543. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2544. authorizeRetryTimes = 0;
  2545. return result;
  2546. }
  2547. }
  2548. //initailize struct Authorize
  2549. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2550. //get data from shared memory
  2551. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2552. random_uuid(guid);
  2553. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2554. LWS_Send(message);
  2555. sprintf(tempdata, "Authorize,%d", gun_index);
  2556. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2557. {
  2558. result = PASS;
  2559. DEBUG_INFO("Authorize mapItem pass\n");
  2560. }
  2561. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2562. return result;
  2563. }
  2564. int sendBootNotificationRequest(void)
  2565. {
  2566. mtrace();
  2567. int result = FAIL;
  2568. char message[500]={0}, payload[700]={0};
  2569. char guid[37]={0};
  2570. char tempdata[65]={0};
  2571. /*
  2572. int IsGunCharging = FALSE;
  2573. //check Transaction active
  2574. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2575. {
  2576. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2577. {
  2578. IsGunCharging = TRUE;
  2579. }
  2580. }
  2581. for (int index = 0; index < CCS_QUANTITY; index++)
  2582. {
  2583. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2584. {
  2585. IsGunCharging = TRUE;
  2586. }
  2587. }
  2588. for (int index = 0; index < GB_QUANTITY; index++)
  2589. {
  2590. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2591. {
  2592. IsGunCharging = TRUE;
  2593. }
  2594. }
  2595. for (int index = 0; index < AC_QUANTITY; index++)
  2596. {
  2597. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2598. {
  2599. IsGunCharging = TRUE;
  2600. }
  2601. }
  2602. if(IsGunCharging == TRUE)
  2603. {
  2604. server_sign = TRUE;
  2605. return result;
  2606. }
  2607. */
  2608. // Fill BootNotification fields
  2609. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2610. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2611. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2612. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2613. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2614. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2615. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2616. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2617. ShmOCPP16Data->ChargeBoxId
  2618. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2619. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2620. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2621. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2622. ,ShmOCPP16Data->BootNotification.CpIccid
  2623. ,ShmOCPP16Data->BootNotification.CpImsi);
  2624. random_uuid(guid);
  2625. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2626. LWS_Send(message);
  2627. sprintf(tempdata, "BootNotification,0");
  2628. 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*/)
  2629. {
  2630. result = PASS;
  2631. }
  2632. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2633. strcpy(queuedata,message);
  2634. return result;
  2635. }
  2636. int sendDataTransferRequest(int gun_index)
  2637. {
  2638. mtrace();
  2639. char message[1000]={0};
  2640. char guid[37]={0};
  2641. char tempdata[65]={0};
  2642. int result = FAIL;
  2643. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2644. random_uuid(guid);
  2645. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2646. MESSAGE_TYPE_CALL,
  2647. guid,
  2648. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2649. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2650. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2651. LWS_Send(message);
  2652. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2653. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2654. {
  2655. result = PASS;
  2656. DEBUG_INFO("DataTransfer mapItem pass\n");
  2657. }
  2658. return result;
  2659. }
  2660. int sendDiagnosticsStatusNotificationRequest(char *status)
  2661. {
  2662. mtrace();
  2663. int result = FAIL;
  2664. char message[110]={0};
  2665. char guid[37]={0};
  2666. char tempdata[65]={0};
  2667. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2668. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2669. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2670. random_uuid(guid);
  2671. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2672. LWS_Send(message);
  2673. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2674. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2675. {
  2676. result = PASS;
  2677. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2678. }
  2679. //#ifdef SystemLogMessage
  2680. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2681. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2682. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2683. //#endif
  2684. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2685. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2686. //record status
  2687. if(strcmp(status,"Idle")==0)
  2688. {
  2689. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2690. }
  2691. else if(strcmp(status,"Uploaded")==0)
  2692. {
  2693. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2694. }
  2695. else if(strcmp(status,"UploadFailed")==0)
  2696. {
  2697. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2698. }
  2699. else if(strcmp(status,"Uploading")==0)
  2700. {
  2701. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2702. }
  2703. return result;
  2704. }
  2705. int sendFirmwareStatusNotificationRequest(char *status)
  2706. {
  2707. mtrace();
  2708. int result = FAIL;
  2709. char message[110]={0};
  2710. char guid[37]={0};
  2711. char tempdata[65]={0};
  2712. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2713. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2714. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2715. random_uuid(guid);
  2716. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2717. LWS_Send(message);
  2718. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2719. 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*/)
  2720. {
  2721. result = PASS;
  2722. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2723. }
  2724. //#ifdef SystemLogMessage
  2725. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2726. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2727. //#endif
  2728. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2729. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2730. //record status
  2731. if(strcmp(status,"Downloaded")==0)
  2732. {
  2733. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2734. }
  2735. else if(strcmp(status,"DownloadFailed")==0)
  2736. {
  2737. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  2738. }
  2739. else if(strcmp(status,"Downloading")==0)
  2740. {
  2741. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2742. }
  2743. else if(strcmp(status,"Idle")==0)
  2744. {
  2745. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2746. }
  2747. else if(strcmp(status,"InstallationFailed")==0)
  2748. {
  2749. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2750. }
  2751. else if(strcmp(status,"Installing")==0)
  2752. {
  2753. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2754. }
  2755. else if(strcmp(status,"Installed")==0)
  2756. {
  2757. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2758. }
  2759. return result;
  2760. }
  2761. int sendHeartbeatRequest(int gun_index)
  2762. {
  2763. mtrace();
  2764. int result = FAIL;
  2765. char message[80]={0};
  2766. char guid[37]={0};
  2767. char tempdata[65]={0};
  2768. random_uuid(guid);
  2769. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2770. , MESSAGE_TYPE_CALL
  2771. , guid );
  2772. LWS_Send(message);
  2773. sprintf(tempdata, "Heartbeat,%d", 0);
  2774. 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*/)
  2775. {
  2776. result = PASS;
  2777. }
  2778. return result;
  2779. }
  2780. int sendStartTransactionRequest(int gun_index)
  2781. {
  2782. mtrace();
  2783. int result = FAIL;
  2784. char message[250]={0};
  2785. char guid[37]={0};
  2786. struct timeval tmnow;
  2787. struct tm *tm;
  2788. char buf[28];//, usec_buf[6];
  2789. char tempdata[65]={0};
  2790. int tempIndex = 0;
  2791. DEBUG_INFO("sendStartTransactionRequest...\n");
  2792. gettimeofday(&tmnow, NULL);
  2793. time_t t;
  2794. t = time(NULL);
  2795. /*UTC time and date*/
  2796. tm = gmtime(&t);
  2797. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2798. #if 0 // remove temporally
  2799. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2800. strcat(buf,".");
  2801. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2802. strcat(buf,usec_buf);
  2803. #endif
  2804. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2805. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2806. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2807. // clear StartTransaction Response
  2808. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2809. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2810. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2811. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2812. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2813. if(gunType[gun_index] == 'J')
  2814. {
  2815. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2816. {
  2817. tempIndex = ((gun_index==2) ? 1: 0);
  2818. }
  2819. else
  2820. {
  2821. tempIndex = gun_index;
  2822. }
  2823. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2824. {
  2825. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2826. {
  2827. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  2828. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2829. }
  2830. }
  2831. }
  2832. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2833. {
  2834. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2835. {
  2836. tempIndex = ((gun_index==2) ? 1: 0);
  2837. }
  2838. else
  2839. {
  2840. tempIndex = gun_index;
  2841. }
  2842. for (int index = 0; index < CCS_QUANTITY; index++)
  2843. {
  2844. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2845. {
  2846. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  2847. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  2848. }
  2849. }
  2850. }
  2851. else if(gunType[gun_index] == 'G')
  2852. {
  2853. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2854. {
  2855. tempIndex = ((gun_index==2) ? 1: 0);
  2856. }
  2857. else
  2858. {
  2859. tempIndex = gun_index;
  2860. }
  2861. for (int index = 0; index < GB_QUANTITY; index++)
  2862. {
  2863. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2864. {
  2865. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  2866. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  2867. }
  2868. }
  2869. }
  2870. else
  2871. {
  2872. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2873. {
  2874. tempIndex = 2;
  2875. }
  2876. else
  2877. {
  2878. tempIndex = gun_index;
  2879. }
  2880. for (int index = 0; index < AC_QUANTITY; index++)
  2881. {
  2882. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2883. {
  2884. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  2885. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  2886. }
  2887. }
  2888. }
  2889. random_uuid(guid);
  2890. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  2891. {
  2892. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  2893. , gun_index +1
  2894. , MESSAGE_TYPE_CALL
  2895. , guid
  2896. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2897. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2898. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2899. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2900. }
  2901. else
  2902. {
  2903. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  2904. , gun_index +1
  2905. , MESSAGE_TYPE_CALL
  2906. , guid
  2907. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2908. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2909. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2910. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  2911. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2912. }
  2913. #if 1
  2914. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  2915. 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*/)
  2916. {
  2917. result = PASS;
  2918. }
  2919. #endif
  2920. strcpy(queuedata, message);
  2921. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2922. /*
  2923. if(GetTransactionQueueNum() == 1)
  2924. {
  2925. LWS_Send(message + 2);
  2926. }*/
  2927. return result;
  2928. }
  2929. int sendStatusNotificationRequest(int gun_index)
  2930. {
  2931. mtrace();
  2932. int result = FAIL;
  2933. char message[600]={0};
  2934. char guid[37];
  2935. int currentStatus = 0;
  2936. struct timeval tmnow;
  2937. struct tm *tm;
  2938. char buf[28];//, usec_buf[6];
  2939. char tempdata[65]={0};
  2940. int tempIndex = 0;
  2941. gettimeofday(&tmnow, NULL);
  2942. time_t t;
  2943. t = time(NULL);
  2944. /*UTC time and date*/
  2945. tm = gmtime(&t);
  2946. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2947. #if 0 // remove temporally
  2948. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2949. strcat(buf,".");
  2950. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2951. strcat(buf,usec_buf);
  2952. #endif
  2953. printf("%s",buf);
  2954. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  2955. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  2956. // it's option
  2957. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  2958. /*
  2959. enum _SYSTEM_STATUS
  2960. {
  2961. S_BOOTING = 0,
  2962. S_IDLE, = 1
  2963. S_AUTHORIZING, =2
  2964. S_REASSIGN_CHECK, =3
  2965. S_REASSIGN, =4
  2966. S_PRECHARGE, =5
  2967. S_PREPARING_FOR_EV, =6
  2968. S_PREPARING_FOR_EVSE, =7
  2969. S_CHARGING, =8
  2970. S_TERMINATING, =9
  2971. S_COMPLETE, =10
  2972. S_ALARM, =11
  2973. S_FAULT =12
  2974. }
  2975. */
  2976. //check Transaction active
  2977. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2978. if(gunType[gun_index] == 'J')
  2979. {
  2980. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2981. {
  2982. tempIndex = ((gun_index==2) ? 1: 0);
  2983. }
  2984. else
  2985. {
  2986. tempIndex = gun_index;
  2987. }
  2988. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2989. {
  2990. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  2991. {
  2992. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  2993. {
  2994. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  2995. {
  2996. currentStatus = 1; //OCPP Status: Preparing
  2997. }
  2998. else
  2999. {
  3000. currentStatus = 0; //OCPP Status: Available
  3001. }
  3002. }
  3003. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3004. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3005. ) //S_PRECHARGE
  3006. {
  3007. currentStatus = 1; //OCPP Status: Preparing
  3008. }
  3009. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3010. {
  3011. currentStatus = 2; //OCPP Status: Charging
  3012. }
  3013. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3014. {
  3015. currentStatus = 5; //OCPP Status: Finishing
  3016. }
  3017. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3018. {
  3019. currentStatus = 4; //OCPP Status: SuspendedEV
  3020. }
  3021. 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
  3022. {
  3023. currentStatus = 7; //OCPP Status: Unavailable
  3024. }
  3025. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3026. {
  3027. currentStatus = 8; //OCPP Status: Faulted
  3028. }
  3029. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3030. {
  3031. currentStatus = 6; //OCPP Status: Reserved
  3032. }
  3033. } //end of the same index
  3034. }//end of for CHAdeMO_QUANTITY
  3035. }
  3036. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3037. {
  3038. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3039. {
  3040. tempIndex = ((gun_index==2) ? 1: 0);
  3041. }
  3042. else
  3043. {
  3044. tempIndex = gun_index;
  3045. }
  3046. for (int index = 0; index < CCS_QUANTITY; index++)
  3047. {
  3048. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3049. {
  3050. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3051. {
  3052. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3053. {
  3054. currentStatus = 1; //OCPP Status: Preparing
  3055. }
  3056. else
  3057. {
  3058. currentStatus = 0; //OCPP Status: Available
  3059. }
  3060. }
  3061. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3062. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3063. ) //S_PRECHARGE
  3064. {
  3065. currentStatus = 1; //OCPP Status: Preparing
  3066. }
  3067. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3068. {
  3069. currentStatus = 2; //OCPP Status: Charging
  3070. }
  3071. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3072. {
  3073. currentStatus = 5; //OCPP Status: Finishing
  3074. }
  3075. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3076. {
  3077. currentStatus = 4; //OCPP Status: SuspendedEV
  3078. }
  3079. 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
  3080. {
  3081. currentStatus = 7; //OCPP Status : Unavailable
  3082. }
  3083. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3084. {
  3085. currentStatus = 8; //OCPP Status: Faulted
  3086. }
  3087. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3088. {
  3089. currentStatus = 6; //OCPP Status: Reserved
  3090. }
  3091. } //end of the same index
  3092. } // end of for CCS_QUANTITY
  3093. }
  3094. else if(gunType[gun_index] == 'G')
  3095. {
  3096. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3097. {
  3098. tempIndex = ((gun_index==2) ? 1: 0);
  3099. }
  3100. else
  3101. {
  3102. tempIndex = gun_index;
  3103. }
  3104. for (int index = 0; index < GB_QUANTITY; index++)
  3105. {
  3106. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3107. {
  3108. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3109. {
  3110. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3111. {
  3112. currentStatus = 1; //OCPP Status: Preparing
  3113. }
  3114. else
  3115. {
  3116. currentStatus = 0; //OCPP Status: Available
  3117. }
  3118. }
  3119. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3120. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3121. ) //S_PRECHARGE
  3122. {
  3123. currentStatus = 1; //OCPP Status: Preparing
  3124. }
  3125. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3126. {
  3127. currentStatus = 2; //OCPP Status: Charging
  3128. }
  3129. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3130. {
  3131. currentStatus = 5; //OCPP Status: Finishing
  3132. }
  3133. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3134. {
  3135. currentStatus = 4; //OCPP Status: SuspendedEV
  3136. }
  3137. 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
  3138. {
  3139. currentStatus = 7; //OCPP Status: Unavailable
  3140. }
  3141. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3142. {
  3143. currentStatus = 8; //OCPP Status: Faulted
  3144. }
  3145. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3146. {
  3147. currentStatus = 6; //OCPP Status: Reserved
  3148. }
  3149. } //end of the same index
  3150. } // end of for GB_QUANTITY
  3151. }
  3152. else
  3153. {
  3154. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3155. {
  3156. tempIndex = 2;
  3157. }
  3158. else
  3159. {
  3160. tempIndex = gun_index;
  3161. }
  3162. for (int index = 0; index < AC_QUANTITY; index++)
  3163. {
  3164. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3165. {
  3166. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3167. {
  3168. 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))
  3169. {
  3170. currentStatus = 1; //OCPP Status: Preparing
  3171. }
  3172. else
  3173. {
  3174. currentStatus = 0; //OCPP Status: Available
  3175. }
  3176. }
  3177. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3178. {
  3179. currentStatus = 1; //OCPP Status: Preparing
  3180. }
  3181. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3182. {
  3183. currentStatus = 2; //OCPP Status: Charging
  3184. }
  3185. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3186. {
  3187. currentStatus = 5; //OCPP Status: Finishing
  3188. }
  3189. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3190. {
  3191. currentStatus = 4; //OCPP Status: SuspendedEV
  3192. }
  3193. 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
  3194. {
  3195. currentStatus = 7; //OCPP Status: Unavailable
  3196. }
  3197. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3198. {
  3199. currentStatus = 8; //OCPP Status: Faulted
  3200. }
  3201. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3202. {
  3203. currentStatus = 6; //OCPP Status: Reserved
  3204. }
  3205. }//end of the same index
  3206. }//end of for AC_QUANTITY
  3207. }
  3208. //it's option
  3209. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3210. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3211. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3212. random_uuid(guid);
  3213. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3214. , MESSAGE_TYPE_CALL
  3215. , guid
  3216. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3217. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3218. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3219. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3220. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3221. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3222. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3223. LWS_Send(message);
  3224. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3225. 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*/)
  3226. {
  3227. //DEBUG_ERROR("statusNotification mapitem pass");
  3228. result = PASS;
  3229. }
  3230. return result;
  3231. }
  3232. int sendStopTransactionRequest(int gun_index)
  3233. {
  3234. mtrace();
  3235. int result = FAIL;
  3236. //char message[1500]={0};
  3237. char guid[37]={0};
  3238. char tempdata[65]={0};
  3239. int tempIndex = 0;
  3240. //int idx_sample=0;
  3241. DEBUG_ERROR("sendStopTransactionRequest \n");
  3242. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3243. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3244. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3245. if(gunType[gun_index] == 'J')
  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 < CHAdeMO_QUANTITY; index++)
  3256. {
  3257. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3258. {
  3259. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3260. }
  3261. }// END OF CHAdeMO_QUANTITY
  3262. }
  3263. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3264. {
  3265. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3266. {
  3267. tempIndex = ((gun_index==2) ? 1: 0);
  3268. }
  3269. else
  3270. {
  3271. tempIndex = gun_index;
  3272. }
  3273. for (int index = 0; index < CCS_QUANTITY; index++)
  3274. {
  3275. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3276. {
  3277. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3278. }
  3279. }// END OF CCS_QUANTITY
  3280. }
  3281. else if(gunType[gun_index] == 'G')
  3282. {
  3283. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3284. {
  3285. tempIndex = ((gun_index==2) ? 1: 0);
  3286. }
  3287. else
  3288. {
  3289. tempIndex = gun_index;
  3290. }
  3291. for (int index = 0; index < GB_QUANTITY; index++)
  3292. {
  3293. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3294. {
  3295. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3296. }
  3297. }// END OF GB_QUANTITY
  3298. }
  3299. else
  3300. {
  3301. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3302. {
  3303. tempIndex = 2;
  3304. }
  3305. else
  3306. {
  3307. tempIndex = gun_index;
  3308. }
  3309. for (int index = 0; index < AC_QUANTITY; index++)
  3310. {
  3311. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3312. {
  3313. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3314. }
  3315. }// END OF AC_QUANTITY
  3316. }
  3317. //====================================== Stop Transaction Time =====================================================
  3318. struct timeval tmnow;
  3319. struct tm *tm;
  3320. char buf[28];//, usec_buf[6];
  3321. gettimeofday(&tmnow, NULL);
  3322. time_t t;
  3323. t = time(NULL);
  3324. /*UTC time and date*/
  3325. tm = gmtime(&t);
  3326. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3327. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3328. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3329. random_uuid(guid);
  3330. /***********************************transactionData******************************************************/
  3331. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3332. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3333. //=================================
  3334. // Transaction_Begin
  3335. //=================================
  3336. //============================================ Energy.Active.Import.Interval ================================
  3337. //idx_sample=0;
  3338. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  3339. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3340. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3341. 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*/]);
  3342. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3343. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3344. {
  3345. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3346. }
  3347. else
  3348. {
  3349. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3350. }
  3351. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3352. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3353. //=================================
  3354. // Transaction_End
  3355. //=================================
  3356. // ================================= Current.Import L1 ===============================================
  3357. //idx_sample=1;
  3358. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3359. if(gunType[gun_index] == 'J')
  3360. {
  3361. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3362. {
  3363. tempIndex = ((gun_index==2) ? 1: 0);
  3364. }
  3365. else
  3366. {
  3367. tempIndex = gun_index;
  3368. }
  3369. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3370. {
  3371. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3372. {
  3373. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3374. }
  3375. }// End of for CHAdeMO_QUANTITY
  3376. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3377. }
  3378. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3379. {
  3380. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3381. {
  3382. tempIndex = ((gun_index==2) ? 1: 0);
  3383. }
  3384. else
  3385. {
  3386. tempIndex = gun_index;
  3387. }
  3388. for (int index = 0; index < CCS_QUANTITY; index++)
  3389. {
  3390. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3391. {
  3392. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3393. }
  3394. }// End of for CCS_QUANTITY
  3395. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3396. }
  3397. else if(gunType[gun_index] == 'G')
  3398. {
  3399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3400. {
  3401. tempIndex = ((gun_index==2) ? 1: 0);
  3402. }
  3403. else
  3404. {
  3405. tempIndex = gun_index;
  3406. }
  3407. for (int index = 0; index < GB_QUANTITY; index++)
  3408. {
  3409. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3410. {
  3411. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3412. }
  3413. }// End of for GB_QUANTITY
  3414. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3415. }
  3416. else
  3417. {
  3418. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3419. {
  3420. tempIndex = 2;
  3421. }
  3422. else
  3423. {
  3424. tempIndex = gun_index;
  3425. }
  3426. for (int index = 0; index < AC_QUANTITY; index++)
  3427. {
  3428. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3429. {
  3430. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3431. }
  3432. }// End of for AC_QUANTITY
  3433. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3434. }
  3435. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3436. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3437. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3438. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3439. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3440. // ================================= Energy.Active.Import.Interval ==============================================
  3441. //idx_sample=2;
  3442. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3443. if(gunType[gun_index] == 'J')
  3444. {
  3445. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3446. {
  3447. tempIndex = ((gun_index==2) ? 1: 0);
  3448. }
  3449. else
  3450. {
  3451. tempIndex = gun_index;
  3452. }
  3453. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3454. {
  3455. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3456. {
  3457. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3458. }
  3459. }// END OF CHAdeMO_QUANTITY
  3460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3461. }
  3462. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3463. {
  3464. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3465. {
  3466. tempIndex = ((gun_index==2) ? 1: 0);
  3467. }
  3468. else
  3469. {
  3470. tempIndex = gun_index;
  3471. }
  3472. for (int index = 0; index < CCS_QUANTITY; index++)
  3473. {
  3474. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3475. {
  3476. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3477. }
  3478. }// END OF CCS_QUANTITY
  3479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3480. }
  3481. else if(gunType[gun_index] == 'G')
  3482. {
  3483. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3484. {
  3485. tempIndex = ((gun_index==2) ? 1: 0);
  3486. }
  3487. else
  3488. {
  3489. tempIndex = gun_index;
  3490. }
  3491. for (int index = 0; index < GB_QUANTITY; index++)
  3492. {
  3493. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3494. {
  3495. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3496. }
  3497. }// END OF GB_QUANTITY
  3498. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3499. }
  3500. else
  3501. {
  3502. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3503. {
  3504. tempIndex = 2;
  3505. }
  3506. else
  3507. {
  3508. tempIndex = gun_index;
  3509. }
  3510. for (int index = 0; index < AC_QUANTITY; index++)
  3511. {
  3512. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3513. {
  3514. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3515. }
  3516. }// END OF AC_QUANTITY
  3517. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3518. }
  3519. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3520. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3521. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3522. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3523. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3524. //=================================== Power.Active.Import ==================================================
  3525. //idx_sample=3;
  3526. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3527. if(gunType[gun_index] == 'J')
  3528. {
  3529. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3530. {
  3531. tempIndex = ((gun_index==2) ? 1: 0);
  3532. }
  3533. else
  3534. {
  3535. tempIndex = gun_index;
  3536. }
  3537. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3538. {
  3539. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3540. {
  3541. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3542. }
  3543. } // End for CHAdeMO_QUANTITY
  3544. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3545. }
  3546. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3547. {
  3548. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3549. {
  3550. tempIndex = ((gun_index==2) ? 1: 0);
  3551. }
  3552. else
  3553. {
  3554. tempIndex = gun_index;
  3555. }
  3556. for (int index = 0; index < CCS_QUANTITY; index++)
  3557. {
  3558. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3559. {
  3560. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3561. }
  3562. } // END for CCS_QUANTITY
  3563. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3564. }
  3565. else if(gunType[gun_index] == 'G')
  3566. {
  3567. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3568. {
  3569. tempIndex = ((gun_index==2) ? 1: 0);
  3570. }
  3571. else
  3572. {
  3573. tempIndex = gun_index;
  3574. }
  3575. for (int index = 0; index < GB_QUANTITY; index++)
  3576. {
  3577. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3578. {
  3579. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3580. }
  3581. }// END for GB_QUANTITY
  3582. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3583. }
  3584. else
  3585. {
  3586. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3587. {
  3588. tempIndex = 2;
  3589. }
  3590. else
  3591. {
  3592. tempIndex = gun_index;
  3593. }
  3594. for (int index = 0; index < AC_QUANTITY; index++)
  3595. {
  3596. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3597. {
  3598. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3599. }
  3600. } // END for AC_QUANTITY
  3601. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3602. }
  3603. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3604. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3605. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3606. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3607. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3608. //============================ Voltage L1 ====================================
  3609. //idx_sample=4;
  3610. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3611. if(gunType[gun_index] == 'J')
  3612. {
  3613. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3614. {
  3615. tempIndex = ((gun_index==2) ? 1: 0);
  3616. }
  3617. else
  3618. {
  3619. tempIndex = gun_index;
  3620. }
  3621. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3622. {
  3623. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3624. {
  3625. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3626. }
  3627. } // END OF FOR CHAdeMO_QUANTITY
  3628. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3629. }
  3630. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3631. {
  3632. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3633. {
  3634. tempIndex = ((gun_index==2) ? 1: 0);
  3635. }
  3636. else
  3637. {
  3638. tempIndex = gun_index;
  3639. }
  3640. for (int index = 0; index < CCS_QUANTITY; index++)
  3641. {
  3642. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3643. {
  3644. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3645. }
  3646. } // END OF FOR CCS_QUANTITY
  3647. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3648. }
  3649. else if(gunType[gun_index] == 'G')
  3650. {
  3651. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3652. {
  3653. tempIndex = ((gun_index==2) ? 1: 0);
  3654. }
  3655. else
  3656. {
  3657. tempIndex = gun_index;
  3658. }
  3659. for (int index = 0; index < GB_QUANTITY; index++)
  3660. {
  3661. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3662. {
  3663. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3664. }
  3665. } // END OF FOR GB_QUANTITY
  3666. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3667. }
  3668. else
  3669. {
  3670. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3671. {
  3672. tempIndex = 2;
  3673. }
  3674. else
  3675. {
  3676. tempIndex = gun_index;
  3677. }
  3678. for (int index = 0; index < AC_QUANTITY; index++)
  3679. {
  3680. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3681. {
  3682. 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
  3683. }
  3684. } // END OF FOR AC_QUANTITY
  3685. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3686. }
  3687. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3688. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3689. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3690. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3691. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3692. //====================== SoC ================================
  3693. //idx_sample=5;
  3694. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3695. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3696. {
  3697. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3698. {
  3699. tempIndex = ((gun_index==2) ? 1: 0);
  3700. }
  3701. else
  3702. {
  3703. tempIndex = gun_index;
  3704. }
  3705. if(gunType[gun_index] == 'J')
  3706. {
  3707. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3708. {
  3709. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3710. {
  3711. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3712. }
  3713. }
  3714. }
  3715. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3716. {
  3717. for (int index = 0; index < CCS_QUANTITY; index++)
  3718. {
  3719. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3720. {
  3721. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3722. }
  3723. }
  3724. }
  3725. else if(gunType[gun_index] == 'G')
  3726. {
  3727. for (int index = 0; index < GB_QUANTITY; index++)
  3728. {
  3729. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3730. {
  3731. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  3732. }
  3733. }
  3734. }
  3735. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3736. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  3737. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  3738. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  3739. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  3740. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  3741. } // END FOR DC CASE
  3742. // ================================= Current.Import L2 ===============================================
  3743. //idx_sample=6;
  3744. // AC 3 phse L2 current
  3745. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3746. {
  3747. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3748. {
  3749. tempIndex = 2;
  3750. }
  3751. else
  3752. {
  3753. tempIndex = gun_index;
  3754. }
  3755. for (int index = 0; index < AC_QUANTITY; index++)
  3756. {
  3757. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3758. {
  3759. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  3760. }
  3761. }// End of for AC_QUANTITY
  3762. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  3763. }
  3764. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3765. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  3766. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  3767. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  3768. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3769. // ================================= Current.Import L3 ===============================================
  3770. //idx_sample=7;
  3771. // AC 3 phse L3 current
  3772. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3773. {
  3774. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3775. {
  3776. tempIndex = 2;
  3777. }
  3778. else
  3779. {
  3780. tempIndex = gun_index;
  3781. }
  3782. for (int index = 0; index < AC_QUANTITY; index++)
  3783. {
  3784. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3785. {
  3786. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  3787. }
  3788. }// End of for AC_QUANTITY
  3789. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  3790. }
  3791. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3792. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  3793. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  3794. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  3795. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3796. //============================ Voltage L2 ====================================
  3797. //idx_sample=8;
  3798. // AC 3 phse L2 voltage
  3799. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3800. {
  3801. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3802. {
  3803. tempIndex = 2;
  3804. }
  3805. else
  3806. {
  3807. tempIndex = gun_index;
  3808. }
  3809. for (int index = 0; index < AC_QUANTITY; index++)
  3810. {
  3811. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3812. {
  3813. 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
  3814. }
  3815. } // END OF FOR AC_QUANTITY
  3816. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  3817. }
  3818. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3819. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  3820. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  3821. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  3822. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3823. //============================ Voltage L3 ====================================
  3824. //idx_sample=8;
  3825. // AC 3 phse L3 voltage
  3826. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3827. {
  3828. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3829. {
  3830. tempIndex = 2;
  3831. }
  3832. else
  3833. {
  3834. tempIndex = gun_index;
  3835. }
  3836. for (int index = 0; index < AC_QUANTITY; index++)
  3837. {
  3838. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3839. {
  3840. 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
  3841. }
  3842. } // END OF FOR AC_QUANTITY
  3843. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  3844. }
  3845. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3846. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  3847. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  3848. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  3849. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3850. //================================================ Message create ====================================================
  3851. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3852. {
  3853. 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\"}]}]}]"
  3854. ,gun_index+1
  3855. ,MESSAGE_TYPE_CALL
  3856. ,guid
  3857. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3858. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3859. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3860. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3861. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3862. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3863. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3864. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3865. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3866. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3867. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3868. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3869. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3870. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3871. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3890. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3894. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3895. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3896. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3897. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3898. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  3899. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  3900. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  3901. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  3902. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  3903. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  3904. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  3905. );
  3906. }
  3907. else
  3908. {
  3909. if((ShmSysConfigAndInfo->SysConfig.ModelName[2]!='Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2]!='W'))
  3910. {
  3911. 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\"}]}]}]"
  3912. ,gun_index+1
  3913. ,MESSAGE_TYPE_CALL
  3914. ,guid
  3915. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3916. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3917. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3918. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3919. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3920. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3921. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3922. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3923. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3924. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3925. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3926. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3927. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3928. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3929. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3930. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3931. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3932. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3933. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3934. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3935. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3936. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3937. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3938. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3939. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3940. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3941. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3942. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3943. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3944. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3945. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3946. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3947. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3948. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3949. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3950. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3951. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3952. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3953. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3954. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3955. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3956. );
  3957. }
  3958. else
  3959. {
  3960. 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\"}]}]}]"
  3961. ,gun_index+1
  3962. ,MESSAGE_TYPE_CALL
  3963. ,guid
  3964. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3965. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3966. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3967. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3968. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3969. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3970. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3971. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3972. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3973. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3974. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3975. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3976. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3977. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3978. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3979. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3980. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3981. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3982. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3983. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3984. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3985. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3986. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3987. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3988. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3989. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3990. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3991. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3992. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3993. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3994. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3995. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3996. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3997. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3998. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3999. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  4000. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  4001. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  4002. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  4003. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  4004. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  4005. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  4006. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  4007. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  4008. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  4009. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  4010. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  4011. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  4012. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  4013. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  4014. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  4015. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  4016. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  4017. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  4018. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  4019. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  4020. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  4021. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  4022. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  4023. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  4024. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  4025. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  4026. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  4027. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  4028. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  4029. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  4030. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  4031. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  4032. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  4033. );
  4034. }
  4035. }
  4036. #if 1 // for TempStopTransaction
  4037. //Delete TempStopTransaction
  4038. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  4039. {
  4040. remove("/Storage/OCPP/TempStopTransaction"); // remove file "TempStopTransaction"
  4041. }
  4042. #endif
  4043. #if 1
  4044. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4045. if(hashmap_operation(0, guid, tempdata) == 1)
  4046. {
  4047. result = PASS;
  4048. DEBUG_INFO("StopTransaction mapitem pass\n");
  4049. }
  4050. #endif
  4051. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4052. /*
  4053. if(GetTransactionQueueNum() == 1)
  4054. {
  4055. LWS_Send(queuedata+2);
  4056. }*/
  4057. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4058. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4059. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4060. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4061. {
  4062. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4063. }
  4064. //for test
  4065. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4066. return result;
  4067. }
  4068. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4069. {
  4070. mtrace();
  4071. int result = FAIL;
  4072. char guid[37]={0};
  4073. char tempdata[65]={0};
  4074. int tempIndex = 0;
  4075. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4076. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4077. //set value
  4078. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4079. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) ? ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId : 0);
  4080. random_uuid(guid);
  4081. //UTC Date time
  4082. struct timeval tmnow;
  4083. struct tm *tm;
  4084. char buf[28];//, usec_buf[6];
  4085. gettimeofday(&tmnow, NULL);
  4086. time_t t;
  4087. t = time(NULL);
  4088. /*UTC time and date*/
  4089. tm = gmtime(&t);
  4090. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4091. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4092. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4093. //idx_sample=0;
  4094. //********************************(1)Current.Import L1************************************************/
  4095. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4096. if(gunType[gun_index] == 'J')
  4097. {
  4098. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4099. {
  4100. tempIndex = ((gun_index==2) ? 1: 0);
  4101. }
  4102. else
  4103. {
  4104. tempIndex = gun_index;
  4105. }
  4106. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4107. {
  4108. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4109. {
  4110. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4111. }
  4112. }
  4113. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4114. }
  4115. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4116. {
  4117. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4118. {
  4119. tempIndex = ((gun_index==2) ? 1: 0);
  4120. }
  4121. else
  4122. {
  4123. tempIndex = gun_index;
  4124. }
  4125. for (int index = 0; index < CCS_QUANTITY; index++)
  4126. {
  4127. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4128. {
  4129. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4130. }
  4131. }
  4132. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4133. }
  4134. else if(gunType[gun_index] == 'G')
  4135. {
  4136. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4137. {
  4138. tempIndex = ((gun_index==2) ? 1: 0);
  4139. }
  4140. else
  4141. {
  4142. tempIndex = gun_index;
  4143. }
  4144. for (int index = 0; index < GB_QUANTITY; index++)
  4145. {
  4146. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4147. {
  4148. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4149. }
  4150. }
  4151. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4152. }
  4153. else
  4154. {
  4155. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4156. {
  4157. tempIndex = 2;
  4158. }
  4159. else
  4160. {
  4161. tempIndex = gun_index;
  4162. }
  4163. for (int index = 0; index < AC_QUANTITY; index++)
  4164. {
  4165. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4166. {
  4167. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4168. }
  4169. }
  4170. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4171. }
  4172. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4173. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4174. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4175. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4176. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4177. //idx_sample=1;
  4178. //********************************(2)Energy.Active.Import.Register ************************************************/
  4179. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4180. if(gunType[gun_index] == 'J')
  4181. {
  4182. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4183. {
  4184. tempIndex = ((gun_index==2) ? 1: 0);
  4185. }
  4186. else
  4187. {
  4188. tempIndex = gun_index;
  4189. }
  4190. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4191. {
  4192. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4193. {
  4194. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4195. }
  4196. }
  4197. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4198. }
  4199. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4200. {
  4201. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4202. {
  4203. tempIndex = ((gun_index==2) ? 1: 0);
  4204. }
  4205. else
  4206. {
  4207. tempIndex = gun_index;
  4208. }
  4209. for (int index = 0; index < CCS_QUANTITY; index++)
  4210. {
  4211. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4212. {
  4213. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4214. }
  4215. }
  4216. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4217. }
  4218. else if(gunType[gun_index] == 'G')
  4219. {
  4220. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4221. {
  4222. tempIndex = ((gun_index==2) ? 1: 0);
  4223. }
  4224. else
  4225. {
  4226. tempIndex = gun_index;
  4227. }
  4228. for (int index = 0; index < GB_QUANTITY; index++)
  4229. {
  4230. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4231. {
  4232. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4233. }
  4234. }
  4235. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4236. }
  4237. else
  4238. {
  4239. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4240. {
  4241. tempIndex = 2;
  4242. }
  4243. else
  4244. {
  4245. tempIndex = gun_index;
  4246. }
  4247. for (int index = 0; index < AC_QUANTITY; index++)
  4248. {
  4249. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4250. {
  4251. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4252. }
  4253. }
  4254. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4255. }
  4256. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4257. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4258. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4259. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4260. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4261. //idx_sample=2;
  4262. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4263. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4264. if(gunType[gun_index] == 'J')
  4265. {
  4266. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4267. {
  4268. tempIndex = ((gun_index==2) ? 1: 0);
  4269. }
  4270. else
  4271. {
  4272. tempIndex = gun_index;
  4273. }
  4274. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4275. {
  4276. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4277. {
  4278. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4279. }
  4280. } // END OF FOR CHAdeMO_QUANTITY
  4281. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4282. }
  4283. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4284. {
  4285. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4286. {
  4287. tempIndex = ((gun_index==2) ? 1: 0);
  4288. }
  4289. else
  4290. {
  4291. tempIndex = gun_index;
  4292. }
  4293. for (int index = 0; index < CCS_QUANTITY; index++)
  4294. {
  4295. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4296. {
  4297. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4298. }
  4299. } // END OF CCS_QUANTITY
  4300. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4301. }
  4302. else if(gunType[gun_index] == 'G')
  4303. {
  4304. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4305. {
  4306. tempIndex = ((gun_index==2) ? 1: 0);
  4307. }
  4308. else
  4309. {
  4310. tempIndex = gun_index;
  4311. }
  4312. for (int index = 0; index < GB_QUANTITY; index++)
  4313. {
  4314. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4315. {
  4316. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4317. }
  4318. } // END OF GB_QUANTITY
  4319. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4320. }
  4321. else
  4322. {
  4323. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4324. {
  4325. tempIndex = 2;
  4326. }
  4327. else
  4328. {
  4329. tempIndex = gun_index;
  4330. }
  4331. for (int index = 0; index < AC_QUANTITY; index++)
  4332. {
  4333. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4334. {
  4335. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4336. }
  4337. }
  4338. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4339. }
  4340. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4341. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4342. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4343. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4344. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4345. //idx_sample=3;
  4346. //********************************(4)Power.Active.Import************************************************/
  4347. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4348. if(gunType[gun_index] == 'J')
  4349. {
  4350. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4351. {
  4352. tempIndex = ((gun_index==2) ? 1: 0);
  4353. }
  4354. else
  4355. {
  4356. tempIndex = gun_index;
  4357. }
  4358. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4359. {
  4360. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4361. {
  4362. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4363. }
  4364. } // END OF FOR
  4365. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4366. }
  4367. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4368. {
  4369. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4370. {
  4371. tempIndex = ((gun_index==2) ? 1: 0);
  4372. }
  4373. else
  4374. {
  4375. tempIndex = gun_index;
  4376. }
  4377. for (int index = 0; index < CCS_QUANTITY; index++)
  4378. {
  4379. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4380. {
  4381. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4382. }
  4383. }
  4384. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4385. }
  4386. else if(gunType[gun_index] == 'G')
  4387. {
  4388. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4389. {
  4390. tempIndex = ((gun_index==2) ? 1: 0);
  4391. }
  4392. else
  4393. {
  4394. tempIndex = gun_index;
  4395. }
  4396. for (int index = 0; index < GB_QUANTITY; index++)
  4397. {
  4398. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4399. {
  4400. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4401. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4402. }
  4403. }
  4404. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4405. }
  4406. else
  4407. {
  4408. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4409. {
  4410. tempIndex = 2;
  4411. }
  4412. else
  4413. {
  4414. tempIndex = gun_index;
  4415. }
  4416. for (int index = 0; index < AC_QUANTITY; index++)
  4417. {
  4418. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4419. {
  4420. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4421. }
  4422. }
  4423. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4424. }
  4425. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4426. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4427. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4428. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4429. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4430. //idx_sample=4;
  4431. //***********************************************(5)VOLTAGE L1******************************************************/
  4432. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4433. if(gunType[gun_index] == 'J')
  4434. {
  4435. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4436. {
  4437. tempIndex = ((gun_index==2) ? 1: 0);
  4438. }
  4439. else
  4440. {
  4441. tempIndex = gun_index;
  4442. }
  4443. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4444. {
  4445. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4446. {
  4447. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4448. }
  4449. }
  4450. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4451. }
  4452. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4453. {
  4454. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4455. {
  4456. tempIndex = ((gun_index==2) ? 1: 0);
  4457. }
  4458. else
  4459. {
  4460. tempIndex = gun_index;
  4461. }
  4462. for (int index = 0; index < CCS_QUANTITY; index++)
  4463. {
  4464. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4465. {
  4466. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4467. }
  4468. }
  4469. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4470. }
  4471. else if(gunType[gun_index] == 'G')
  4472. {
  4473. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4474. {
  4475. tempIndex = ((gun_index==2) ? 1: 0);
  4476. }
  4477. else
  4478. {
  4479. tempIndex = gun_index;
  4480. }
  4481. for (int index = 0; index < GB_QUANTITY; index++)
  4482. {
  4483. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4484. {
  4485. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4486. }
  4487. }
  4488. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4489. }
  4490. else
  4491. {
  4492. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4493. {
  4494. tempIndex = 2;
  4495. }
  4496. else
  4497. {
  4498. tempIndex = gun_index;
  4499. }
  4500. for (int index = 0; index < AC_QUANTITY; index++)
  4501. {
  4502. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4503. {
  4504. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4505. }
  4506. }
  4507. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4508. }
  4509. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4510. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4511. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4512. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4513. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4514. //***********************************************(6)SOC******************************************************/
  4515. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4516. {
  4517. //idx_sample=5;
  4518. //sampledValue = NULL;
  4519. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4520. {
  4521. tempIndex = ((gun_index==2) ? 1: 0);
  4522. }
  4523. else
  4524. {
  4525. tempIndex = gun_index;
  4526. }
  4527. if(gunType[gun_index] == 'J')
  4528. {
  4529. //tempIndex = ((gun_index==2) ? 1: 0);
  4530. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4531. {
  4532. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4533. {
  4534. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4535. }
  4536. }
  4537. }
  4538. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4539. {
  4540. //tempIndex = ((gun_index==2) ? 1: 0);
  4541. for (int index = 0; index < CCS_QUANTITY; index++)
  4542. {
  4543. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4544. {
  4545. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4546. }
  4547. }
  4548. }
  4549. else if(gunType[gun_index] == 'G')
  4550. {
  4551. //tempIndex = ((gun_index==2) ? 1: 0);
  4552. for (int index = 0; index < GB_QUANTITY; index++)
  4553. {
  4554. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4555. {
  4556. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4557. }
  4558. }
  4559. }
  4560. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4561. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4562. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4563. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4564. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_Outlet]);
  4565. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4566. }
  4567. //********************************(7)Current.Import L2************************************************/
  4568. // Only for AC 3 phase
  4569. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4570. {
  4571. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4572. {
  4573. tempIndex = 2;
  4574. }
  4575. else
  4576. {
  4577. tempIndex = gun_index;
  4578. }
  4579. for (int index = 0; index < AC_QUANTITY; index++)
  4580. {
  4581. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4582. {
  4583. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  4584. }
  4585. }
  4586. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  4587. }
  4588. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  4589. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  4590. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  4591. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  4592. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4593. //********************************(8)Current.Import L3************************************************/
  4594. // Only for AC 3 phase
  4595. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4596. {
  4597. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4598. {
  4599. tempIndex = 2;
  4600. }
  4601. else
  4602. {
  4603. tempIndex = gun_index;
  4604. }
  4605. for (int index = 0; index < AC_QUANTITY; index++)
  4606. {
  4607. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4608. {
  4609. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  4610. }
  4611. }
  4612. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  4613. }
  4614. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  4615. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  4616. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  4617. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  4618. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4619. //***********************************************(9)VOLTAGE L2******************************************************/
  4620. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4621. {
  4622. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4623. {
  4624. tempIndex = 2;
  4625. }
  4626. else
  4627. {
  4628. tempIndex = gun_index;
  4629. }
  4630. for (int index = 0; index < AC_QUANTITY; index++)
  4631. {
  4632. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4633. {
  4634. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  4635. }
  4636. }
  4637. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  4638. }
  4639. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  4640. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  4641. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  4642. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  4643. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4644. //***********************************************(10)VOLTAGE L3******************************************************/
  4645. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4646. {
  4647. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4648. {
  4649. tempIndex = 2;
  4650. }
  4651. else
  4652. {
  4653. tempIndex = gun_index;
  4654. }
  4655. for (int index = 0; index < AC_QUANTITY; index++)
  4656. {
  4657. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4658. {
  4659. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  4660. }
  4661. }
  4662. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  4663. }
  4664. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  4665. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  4666. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  4667. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  4668. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4669. // Message create ====================================================================================================
  4670. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4671. {
  4672. 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\"}]}]}]"
  4673. ,gun_index + 1
  4674. ,MESSAGE_TYPE_CALL
  4675. ,guid
  4676. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4677. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4678. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4679. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4680. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4681. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4682. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4683. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4684. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4685. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4686. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4687. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4688. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4689. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4690. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4691. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4692. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4693. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4694. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4695. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4696. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4697. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4698. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4699. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4700. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4701. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4702. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4703. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4704. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4705. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4706. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4707. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4708. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4709. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4710. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4711. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4712. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4713. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4714. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value
  4715. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context
  4716. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format
  4717. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand
  4718. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase
  4719. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location
  4720. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit
  4721. );
  4722. }
  4723. else
  4724. {
  4725. if((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W'))
  4726. {
  4727. 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\"}]}]}]"
  4728. ,gun_index + 1
  4729. ,MESSAGE_TYPE_CALL
  4730. ,guid
  4731. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4732. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4733. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4734. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4735. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4736. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4737. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4738. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4739. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4740. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4741. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4742. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4743. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4744. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4745. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4746. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4747. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4748. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4749. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4750. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4751. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4752. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4753. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4754. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4755. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4756. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4757. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4758. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4759. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4760. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4761. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4762. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4763. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4764. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4765. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4766. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4767. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4768. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4769. );
  4770. }
  4771. else
  4772. {
  4773. 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\"}]}]}]"
  4774. ,gun_index + 1
  4775. ,MESSAGE_TYPE_CALL
  4776. ,guid
  4777. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4778. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4779. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4780. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4781. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4782. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4783. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4784. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4785. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4786. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4787. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4788. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4789. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4790. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4791. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4792. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4793. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4794. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4795. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4796. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4797. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4798. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4799. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4800. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4801. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4802. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4803. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4804. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4805. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4806. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4807. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4808. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4809. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4810. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4811. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4812. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4813. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4814. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4815. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value
  4816. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context
  4817. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format
  4818. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand
  4819. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase
  4820. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location
  4821. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit
  4822. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value
  4823. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context
  4824. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format
  4825. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand
  4826. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase
  4827. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location
  4828. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit
  4829. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value
  4830. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context
  4831. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format
  4832. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand
  4833. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase
  4834. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location
  4835. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit
  4836. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value
  4837. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context
  4838. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format
  4839. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand
  4840. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase
  4841. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location
  4842. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit
  4843. );
  4844. }
  4845. }
  4846. // Put request guid to hash map
  4847. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4848. 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*/)
  4849. {
  4850. result = PASS;
  4851. DEBUG_INFO("MeterValues mapitem pass\n");
  4852. }
  4853. if(dataType != ReadingContext_Trigger)
  4854. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4855. else
  4856. LWS_Send(queuedata +2);
  4857. /*
  4858. if(GetTransactionQueueNum() == 1)
  4859. {
  4860. LWS_Send(queuedata +2);
  4861. }*/
  4862. return result;
  4863. }
  4864. //==========================================
  4865. // send confirm routine
  4866. //==========================================
  4867. int sendCancelReservationConfirmation(char *uuid,char *payload)
  4868. {
  4869. mtrace();
  4870. int result = FAIL;
  4871. char message[100]={0};
  4872. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  4873. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4874. LWS_Send(message);
  4875. result = TRUE;
  4876. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  4877. return result;
  4878. }
  4879. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  4880. {
  4881. mtrace();
  4882. int result = FAIL;
  4883. char message[100]={0};
  4884. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  4885. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4886. LWS_Send(message);
  4887. result = TRUE;
  4888. return result;
  4889. }
  4890. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  4891. {
  4892. mtrace();
  4893. int result = FAIL;
  4894. char message[100]={0};
  4895. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  4896. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4897. LWS_Send(message);
  4898. result = TRUE;
  4899. return result;
  4900. }
  4901. int sendClearCacheConfirmation(char *uuid,char *payload)
  4902. {
  4903. mtrace();
  4904. int result = FAIL;
  4905. char message[500]={0};
  4906. DEBUG_INFO("sendClearCacheConfirmation...\n");
  4907. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4908. LWS_Send(message);
  4909. return result;
  4910. }
  4911. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  4912. {
  4913. mtrace();
  4914. int result = FAIL;
  4915. char message[500]={0};
  4916. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  4917. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4918. LWS_Send(message);
  4919. return result;
  4920. }
  4921. int sendDataTransferConfirmation(char *uuid,char *payload)
  4922. {
  4923. mtrace();
  4924. char statusStr[20]={0};
  4925. char dataStr[10]={0};
  4926. char sstr[20]={0};
  4927. int c = 0;
  4928. char *loc;
  4929. int result = FAIL;
  4930. DEBUG_INFO("sendDataTransferConfirmation...\n");
  4931. /**********************status**************************/
  4932. loc = strstr(payload, "status");
  4933. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4934. c = 0;
  4935. while (loc[3+strlen("status")+c] != '\"')
  4936. {
  4937. sstr[c] = loc[3+strlen("status")+c];
  4938. c++;
  4939. }
  4940. sstr[c] = '\0';
  4941. strcpy(statusStr, sstr);
  4942. /**********************data**************************/
  4943. loc = strstr(payload, "data");
  4944. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4945. c = 0;
  4946. while (loc[3+strlen("data")+c] != '\"')
  4947. {
  4948. sstr[c] = loc[3+strlen("data")+c];
  4949. c++;
  4950. }
  4951. sstr[c] = '\0';
  4952. strcpy(dataStr, sstr);
  4953. return result;
  4954. }
  4955. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  4956. {
  4957. mtrace();
  4958. int result = FAIL;
  4959. char message[1000]={0};
  4960. int CompositeScheduleIndex = 0;
  4961. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  4962. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  4963. if(nPeriod == 0)
  4964. {
  4965. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  4966. {
  4967. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  4968. ,MESSAGE_TYPE_CALLRESULT
  4969. ,uuid
  4970. ,payload
  4971. ,connectorIdInt);
  4972. }
  4973. else
  4974. {
  4975. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  4976. ,MESSAGE_TYPE_CALLRESULT
  4977. ,uuid
  4978. ,payload
  4979. ,connectorIdInt
  4980. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4981. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4982. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4983. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  4984. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  4985. }
  4986. }
  4987. else
  4988. {
  4989. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  4990. ,MESSAGE_TYPE_CALLRESULT
  4991. ,uuid
  4992. ,payload
  4993. ,connectorIdInt
  4994. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4995. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4996. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4997. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  4998. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  4999. {
  5000. if (idx_sample == 0)
  5001. {
  5002. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5003. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5004. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5005. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5006. }
  5007. else
  5008. {
  5009. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5010. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5011. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5012. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5013. }
  5014. }
  5015. sprintf(message + strlen(message), "]}}]");
  5016. }
  5017. LWS_Send(message);
  5018. result = TRUE;
  5019. return result;
  5020. }
  5021. int sendGetConfigurationConfirmation(char *uuid)
  5022. {
  5023. mtrace();
  5024. int result = FAIL;
  5025. int MaxKeySupported = 0;
  5026. int sentConfigurationNumber= 0;
  5027. int sentunConfigurationNumber= 0;
  5028. char message[4000]={0};
  5029. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5030. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5031. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5032. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5033. ,MESSAGE_TYPE_CALLRESULT
  5034. ,uuid );
  5035. //configuration key
  5036. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5037. {
  5038. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5039. {
  5040. if (sentConfigurationNumber == 0)
  5041. {
  5042. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5043. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5044. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5045. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5046. }
  5047. else
  5048. {
  5049. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5050. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5051. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5052. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5053. }
  5054. sentConfigurationNumber = sentConfigurationNumber + 1;
  5055. }
  5056. }
  5057. sprintf(message + strlen(message), "]");
  5058. if(UnknownKeynum != 0)
  5059. {
  5060. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5061. //unkown key
  5062. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5063. {
  5064. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5065. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5066. if(sentunConfigurationNumber == 0)
  5067. {
  5068. sprintf(message + strlen(message), "\"%s\""
  5069. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5070. }
  5071. else
  5072. {
  5073. sprintf(message + strlen(message), ",\"%s\""
  5074. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5075. }
  5076. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5077. }
  5078. sprintf(message + strlen(message), "]");
  5079. }
  5080. sprintf(message + strlen(message), "}]");
  5081. LWS_Send(message);
  5082. return result;
  5083. }
  5084. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5085. {
  5086. mtrace();
  5087. int result = FAIL;
  5088. char message[400]={0};
  5089. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5090. if(strcmp(payload,"")==0)
  5091. {
  5092. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5093. }
  5094. else
  5095. {
  5096. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5097. }
  5098. LWS_Send(message);
  5099. result = TRUE;
  5100. return result;
  5101. }
  5102. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5103. {
  5104. mtrace();
  5105. int result = FAIL;
  5106. char message[80]={0};
  5107. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5108. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5109. LWS_Send(message);
  5110. result = TRUE;
  5111. return result;
  5112. }
  5113. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5114. {
  5115. mtrace();
  5116. int result = FAIL;
  5117. char message[80]={0};
  5118. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5119. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5120. LWS_Send(message);
  5121. result = TRUE;
  5122. return result;
  5123. }
  5124. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5125. {
  5126. mtrace();
  5127. int result = FAIL;
  5128. char message[80]={0};
  5129. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5130. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5131. LWS_Send(message);
  5132. result = TRUE;
  5133. return result;
  5134. }
  5135. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5136. {
  5137. mtrace();
  5138. int result = FAIL;
  5139. char message[80]={0};
  5140. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5141. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5142. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5143. LWS_Send(message);
  5144. result = TRUE;
  5145. return result;
  5146. }
  5147. int sendResetConfirmation(char *uuid,char *payload)
  5148. {
  5149. mtrace();
  5150. int result = FAIL;
  5151. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5152. char message[80]={0};
  5153. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5154. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5155. LWS_Send(message);
  5156. result = TRUE;
  5157. return result;
  5158. }
  5159. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5160. {
  5161. mtrace();
  5162. int result = FAIL;
  5163. char message[500]={0};
  5164. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5165. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5166. LWS_Send(message);
  5167. result = TRUE;
  5168. return result;
  5169. }
  5170. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5171. {
  5172. mtrace();
  5173. int result = FAIL;
  5174. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5175. char message[80]={0};
  5176. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5177. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5178. LWS_Send(message);
  5179. result = TRUE;
  5180. return result;
  5181. }
  5182. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5183. {
  5184. mtrace();
  5185. int result = FAIL;
  5186. char message[80]={0};
  5187. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5188. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5189. LWS_Send(message);
  5190. result = TRUE;
  5191. return result;
  5192. }
  5193. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5194. {
  5195. mtrace();
  5196. int result = FAIL;
  5197. char message[80]={0};
  5198. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5199. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5200. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5201. LWS_Send(message);
  5202. result = TRUE;
  5203. return result;
  5204. }
  5205. int sendUpdateFirmwareConfirmation(char *uuid)
  5206. {
  5207. mtrace();
  5208. int result = FAIL;
  5209. char message[60]={0};
  5210. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5211. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5212. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5213. LWS_Send(message);
  5214. result = TRUE;
  5215. return result;
  5216. }
  5217. //==========================================
  5218. // send CallError routine
  5219. //==========================================
  5220. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5221. {
  5222. mtrace();
  5223. char message[220]={0};
  5224. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5225. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5226. LWS_Send(message);
  5227. }
  5228. //==========================================
  5229. // Handle server request routine Start
  5230. //==========================================
  5231. int handleCancelReservationRequest(char *uuid, char *payload)
  5232. {
  5233. mtrace();
  5234. int result = FAIL;
  5235. int gunNO = 0;
  5236. int reservationIdInt =0;
  5237. char comfirmstr[20];
  5238. DEBUG_INFO("handleCancelReservationRequest...\n");
  5239. json_object *CancelReservation;
  5240. CancelReservation = json_tokener_parse(payload);
  5241. if(!is_error(CancelReservation))
  5242. {
  5243. // Required data
  5244. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5245. }
  5246. json_object_put(CancelReservation);
  5247. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5248. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5249. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5250. //check Transaction active
  5251. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5252. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5253. {
  5254. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5255. {
  5256. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5257. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5258. if(gunType[2] == 'J')
  5259. {
  5260. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5261. }
  5262. else
  5263. {
  5264. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5265. }
  5266. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5267. goto end;
  5268. }
  5269. }
  5270. for (int index = 0; index < CCS_QUANTITY; index++)
  5271. {
  5272. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5273. {
  5274. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5275. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5276. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5277. {
  5278. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5279. }
  5280. else
  5281. {
  5282. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5283. }
  5284. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5285. goto end;
  5286. }
  5287. }
  5288. for (int index = 0; index < GB_QUANTITY; index++)
  5289. {
  5290. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5291. {
  5292. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5293. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5294. if(gunType[2] == 'G')
  5295. {
  5296. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5297. }
  5298. else
  5299. {
  5300. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5301. }
  5302. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5303. goto end;
  5304. }
  5305. }
  5306. for (int index = 0; index < AC_QUANTITY; index++)
  5307. {
  5308. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5309. {
  5310. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5311. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5312. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5313. {
  5314. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5315. }
  5316. else
  5317. {
  5318. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5319. }
  5320. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5321. goto end;
  5322. }
  5323. }
  5324. //The reservationId does NOT match the reservationId
  5325. sendCancelReservationConfirmation(uuid, comfirmstr);
  5326. end:
  5327. // Fill in ocpp packet uuid
  5328. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5329. return result;
  5330. }
  5331. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5332. {
  5333. mtrace();
  5334. int result = FAIL;
  5335. int gunIndex = 0;
  5336. char typeStr[16]={0};
  5337. char comfirmstr[20];
  5338. int specificId = FALSE;
  5339. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5340. json_object *ChangeAvailability;
  5341. ChangeAvailability = json_tokener_parse(payload);
  5342. if(!is_error(ChangeAvailability))
  5343. {
  5344. // Required data
  5345. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5346. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5347. }
  5348. json_object_put(ChangeAvailability);
  5349. if(gunIndex != 0)
  5350. {
  5351. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5352. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5353. }
  5354. else
  5355. {
  5356. for(int i=0; i < gunTotalNumber; i++)
  5357. {
  5358. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5359. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5360. }
  5361. }
  5362. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5363. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5364. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  5365. {
  5366. specificId = TRUE;
  5367. }
  5368. if(specificId == FALSE)
  5369. goto end;
  5370. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5371. {
  5372. //----------------------gunIndex is 0 ------------------------------------------------//
  5373. if(gunIndex == 0)
  5374. {
  5375. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5376. {
  5377. for(int i=0; i < gunTotalNumber; i++)
  5378. {
  5379. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5380. {
  5381. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5382. {
  5383. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5384. {
  5385. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5386. goto end;
  5387. }
  5388. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5389. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5390. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5391. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5392. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5393. {
  5394. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5395. goto end;
  5396. }
  5397. }
  5398. }//END FOR CHAdeMO_QUANTITY
  5399. for (int index = 0; index < CCS_QUANTITY; index++)
  5400. {
  5401. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5402. {
  5403. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5404. {
  5405. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5406. goto end;
  5407. }
  5408. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5409. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5410. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5411. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5412. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5413. {
  5414. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5415. goto end;
  5416. }
  5417. }
  5418. }//END FOR CCS_QUANTITY
  5419. for (int index = 0; index < GB_QUANTITY; index++)
  5420. {
  5421. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5422. {
  5423. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5424. {
  5425. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5426. goto end;
  5427. }
  5428. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5429. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5430. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5431. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5432. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5433. {
  5434. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5435. goto end;
  5436. }
  5437. }
  5438. }// END FOR GB_QUANTITY
  5439. for (int index = 0; index < AC_QUANTITY; index++)
  5440. {
  5441. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5442. {
  5443. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5444. {
  5445. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5446. goto end;
  5447. }
  5448. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5449. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5450. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5451. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5452. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5453. {
  5454. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5455. goto end;
  5456. }
  5457. }
  5458. }//END FOR AC_QUANTITY
  5459. }// END FOR gunTotalNumber
  5460. }
  5461. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5462. {
  5463. for(int i=0; i < gunTotalNumber; i++)
  5464. {
  5465. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5466. {
  5467. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5468. goto end;
  5469. }
  5470. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5471. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5472. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5473. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5474. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5475. {
  5476. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5477. goto end;
  5478. }
  5479. }
  5480. }
  5481. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5482. goto end;
  5483. }
  5484. //----------------------gunIndex is not 0 ------------------------------------------------//
  5485. //check Transaction active
  5486. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5487. {
  5488. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5489. {
  5490. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5491. {
  5492. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5493. goto end;
  5494. }
  5495. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5496. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5497. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5498. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5499. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5500. {
  5501. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5502. goto end;
  5503. }
  5504. else
  5505. {
  5506. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5507. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5508. goto end;
  5509. }
  5510. }
  5511. }//END FOR CHAdeMO_QUANTITY
  5512. for (int index = 0; index < CCS_QUANTITY; index++)
  5513. {
  5514. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5515. {
  5516. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5517. {
  5518. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5519. goto end;
  5520. }
  5521. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5522. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5523. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5524. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5525. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5526. {
  5527. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5528. goto end;
  5529. }
  5530. else
  5531. {
  5532. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5533. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5534. goto end;
  5535. }
  5536. }
  5537. }//END FOR CCS_QUANTITY
  5538. for (int index = 0; index < GB_QUANTITY; index++)
  5539. {
  5540. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5541. {
  5542. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5543. {
  5544. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5545. goto end;
  5546. }
  5547. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5548. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5549. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5550. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5551. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5552. {
  5553. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5554. goto end;
  5555. }
  5556. else
  5557. {
  5558. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5559. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5560. goto end;
  5561. }
  5562. }
  5563. }// END FOR GB_QUANTITY
  5564. for (int index = 0; index < AC_QUANTITY; index++)
  5565. {
  5566. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5567. {
  5568. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5569. {
  5570. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5571. goto end;
  5572. }
  5573. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5574. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5575. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5576. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5577. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5578. {
  5579. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5580. goto end;
  5581. }
  5582. else
  5583. {
  5584. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5585. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5586. goto end;
  5587. }
  5588. }
  5589. }//END FOR AC_QUANTITY
  5590. }//END FOR AvailabilityTypeStr[Inoperative]
  5591. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5592. {
  5593. //----------------------gunIndex is 0 ------------------------------------------------//
  5594. if(gunIndex == 0)
  5595. {
  5596. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5597. {
  5598. for(int i=0; i < gunTotalNumber; i++)
  5599. {
  5600. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5601. {
  5602. 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
  5603. {
  5604. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5605. goto end;
  5606. }
  5607. }//END FOR CHAdeMO_QUANTITY
  5608. for (int index = 0; index < CCS_QUANTITY; index++)
  5609. {
  5610. 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
  5611. {
  5612. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5613. goto end;
  5614. }
  5615. }//END FOR CCS_QUANTITY
  5616. for (int index = 0; index < GB_QUANTITY; index++)
  5617. {
  5618. 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
  5619. {
  5620. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5621. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5622. goto end;
  5623. }
  5624. }// END FOR GB_QUANTITY
  5625. for (int index = 0; index < AC_QUANTITY; index++)
  5626. {
  5627. 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
  5628. {
  5629. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5630. goto end;
  5631. }
  5632. }//END FOR CHAdeMO_QUANTITY
  5633. }// END FOR gunTotalNumber
  5634. }
  5635. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5636. {
  5637. for(int i=0; i < gunTotalNumber; i++)
  5638. {
  5639. for (int index = 0; index < AC_QUANTITY; index++)
  5640. {
  5641. 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
  5642. {
  5643. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5644. goto end;
  5645. }
  5646. }//END FOR CHAdeMO_QUANTITY
  5647. } // END FOR gunTotalNumber
  5648. }
  5649. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5650. goto end;
  5651. }
  5652. //----------------------gunIndex is not 0 ------------------------------------------------//
  5653. //check Transaction active
  5654. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5655. {
  5656. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5657. {
  5658. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5659. goto end;
  5660. }
  5661. }//END FOR CHAdeMO_QUANTITY
  5662. for (int index = 0; index < CCS_QUANTITY; index++)
  5663. {
  5664. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5665. {
  5666. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5667. goto end;
  5668. }
  5669. }//END FOR CCS_QUANTITY
  5670. for (int index = 0; index < GB_QUANTITY; index++)
  5671. {
  5672. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5673. {
  5674. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5675. goto end;
  5676. }
  5677. }// END FOR GB_QUANTITY
  5678. for (int index = 0; index < AC_QUANTITY; index++)
  5679. {
  5680. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5681. {
  5682. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5683. goto end;
  5684. }
  5685. }//END FOR AC_QUANTITY
  5686. }//END FOR AvailabilityTypeStr[Operative]
  5687. end:
  5688. if(gunIndex != 0)
  5689. {
  5690. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5691. }
  5692. else
  5693. {
  5694. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5695. }
  5696. if(gunIndex != 0)
  5697. {
  5698. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5699. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5700. }
  5701. else
  5702. {
  5703. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5704. {
  5705. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5706. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5707. }
  5708. }
  5709. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5710. return result;
  5711. }
  5712. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5713. {
  5714. mtrace();
  5715. int result = FAIL;
  5716. char keystr[40]={0};
  5717. char valuestr[100]={0};
  5718. char comfirmstr[20]={0};
  5719. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5720. json_object *ChangeConfiguration;
  5721. ChangeConfiguration = json_tokener_parse(payload);
  5722. if(!is_error(ChangeConfiguration))
  5723. {
  5724. // Required data
  5725. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5726. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5727. }
  5728. json_object_put(ChangeConfiguration);
  5729. if((uuid==NULL) || (payload ==NULL) )
  5730. {
  5731. DEBUG_ERROR("Payload is null\n");
  5732. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5733. }
  5734. else
  5735. {
  5736. int status = setKeyValue(keystr, valuestr);
  5737. switch(status)
  5738. {
  5739. case ConfigurationStatus_Accepted:
  5740. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5741. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5742. StoreConfigurationTable();
  5743. break;
  5744. case ConfigurationStatus_Rejected:
  5745. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5746. break;
  5747. case RebootRequired:
  5748. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5749. StoreConfigurationTable();
  5750. break;
  5751. case NotSupported:
  5752. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5753. break;
  5754. default:
  5755. break;
  5756. }
  5757. }
  5758. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5759. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5760. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5761. {
  5762. ChageWebSocketPingInterval(atoi(valuestr));
  5763. }
  5764. return result;
  5765. }
  5766. int handleClearCacheRequest(char *uuid, char *payload)
  5767. {
  5768. mtrace();
  5769. int result = FAIL;
  5770. char comfirmstr[20];
  5771. int fd;
  5772. char rmFileCmd[100]={0};
  5773. struct stat stats;
  5774. DEBUG_INFO("handleClearCacheRequest...\n");
  5775. stat("/Storage/OCPP", &stats);
  5776. // Check for directory existence
  5777. if (S_ISDIR(stats.st_mode) == 1)
  5778. {}
  5779. else
  5780. {
  5781. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  5782. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  5783. system(rmFileCmd);
  5784. }
  5785. memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
  5786. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  5787. {
  5788. DEBUG_INFO("AuthorizationCache file exist.\n");
  5789. }
  5790. else
  5791. {
  5792. DEBUG_INFO("AuthorizationCache file not exist\n");
  5793. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  5794. if(log == NULL)
  5795. {
  5796. DEBUG_INFO("AuthorizationCache file is NULL\n");
  5797. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5798. goto end;
  5799. }
  5800. else
  5801. {
  5802. fclose(log);
  5803. }
  5804. }
  5805. if((fd = open(AuthorizationCache_JSON,O_RDWR)) < 0)
  5806. {
  5807. DEBUG_INFO("open AuthorizationCache file failed\n");
  5808. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5809. }
  5810. else
  5811. {
  5812. DEBUG_INFO("open AuthorizationCache file successful\n");
  5813. ftruncate(fd,0);
  5814. lseek(fd,0,SEEK_SET);
  5815. close(fd);
  5816. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  5817. }
  5818. end:
  5819. sendClearCacheConfirmation(uuid, comfirmstr);
  5820. return result;
  5821. }
  5822. int handleClearChargingProfileRequest(char *uuid, char *payload)
  5823. {
  5824. mtrace();
  5825. int result = FAIL;
  5826. int resultRename;
  5827. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  5828. char chargingProfilePurposeStr[26]={0};
  5829. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  5830. char tempchargingProfilePurposeStr[26]={0};
  5831. char sstr[160]={0};
  5832. char str[100]={0};
  5833. int c = 0;
  5834. char *loc;
  5835. char fname[200]={0};
  5836. char comfirmstr[20]={0};
  5837. char word[1600]={0};
  5838. int clearflag = FALSE;
  5839. int chargingProfileIdIsNULL = FALSE;
  5840. int connectorIsNULL = FALSE;
  5841. int chargingProfilePurposeIsNULL = FALSE;
  5842. int stackLevelIsNULL = FALSE;
  5843. //int GotoEnd = FALSE;
  5844. FILE *fptr1, *fptr2;
  5845. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  5846. int n_chargingProfile=0;
  5847. int isEmptyFile = FALSE;
  5848. char sLineWord[1600]={0};
  5849. char chargingProfiles[10][100]={0};
  5850. int ChargeProfileCount = 0;
  5851. char ch;
  5852. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  5853. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  5854. json_object *ClearChargingProfile;
  5855. ClearChargingProfile = json_tokener_parse(payload);
  5856. if(!is_error(ClearChargingProfile))
  5857. {
  5858. // Optional data
  5859. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  5860. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  5861. else
  5862. chargingProfileIdIsNULL = TRUE;
  5863. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  5864. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  5865. else
  5866. connectorIsNULL = TRUE;
  5867. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  5868. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  5869. else
  5870. chargingProfilePurposeIsNULL = TRUE;
  5871. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  5872. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  5873. else
  5874. stackLevelIsNULL = TRUE;
  5875. }
  5876. json_object_put(ClearChargingProfile);
  5877. if(connectorIsNULL == FALSE)
  5878. {
  5879. switch(connectorIdInt)
  5880. {
  5881. case 0:
  5882. if(chargingProfilePurposeIsNULL == TRUE)
  5883. {
  5884. int l = 0;
  5885. strcpy(fname, ChargePointMaxProfile_JSON);
  5886. if((access(fname,F_OK))!=-1)
  5887. {
  5888. strcpy(chargingProfiles[l], fname);
  5889. l = l + 1;
  5890. }
  5891. strcpy(fname, TxDefaultProfile_0_JSON);
  5892. if((access(fname,F_OK))!=-1)
  5893. {
  5894. strcpy(chargingProfiles[l], fname);
  5895. l = l + 1;
  5896. }
  5897. ChargeProfileCount = l;
  5898. }
  5899. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  5900. {
  5901. strcpy(fname, ChargePointMaxProfile_JSON);
  5902. if((access(fname,F_OK))!=-1)
  5903. {
  5904. strcpy(chargingProfiles[0], fname);
  5905. ChargeProfileCount = 1;
  5906. }
  5907. }
  5908. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5909. {
  5910. strcpy(fname, TxDefaultProfile_0_JSON);
  5911. if((access(fname,F_OK))!=-1)
  5912. {
  5913. strcpy(chargingProfiles[0], fname);
  5914. ChargeProfileCount = 1;
  5915. }
  5916. }
  5917. break;
  5918. default:
  5919. if(chargingProfilePurposeIsNULL == TRUE)
  5920. {
  5921. int m = 0;
  5922. memset(fname, 0, ARRAY_SIZE(fname));
  5923. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5924. if((access(fname,F_OK))!=-1)
  5925. {
  5926. strcpy(chargingProfiles[m], fname);
  5927. m = m + 1;
  5928. }
  5929. memset(fname, 0, ARRAY_SIZE(fname));
  5930. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5931. if((access(fname,F_OK))!=-1)
  5932. {
  5933. strcpy(chargingProfiles[m], fname);
  5934. m = m + 1;
  5935. }
  5936. ChargeProfileCount = m;
  5937. }
  5938. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5939. {
  5940. //strcpy(fname, TxDefaultProfile_1_JSON);
  5941. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5942. if((access(fname,F_OK))!=-1)
  5943. {
  5944. strcpy(chargingProfiles[0], fname);
  5945. ChargeProfileCount = 1;
  5946. }
  5947. }
  5948. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  5949. {
  5950. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5951. if((access(fname,F_OK))!=-1)
  5952. {
  5953. strcpy(chargingProfiles[0], fname);
  5954. ChargeProfileCount = 1;
  5955. }
  5956. //strcpy(fname, TxProfile_1_JSON);
  5957. }
  5958. //strcpy(fname, ChargePointMaxProfile_JSON );
  5959. break;
  5960. }
  5961. }
  5962. else // Check all Charging Profiles
  5963. {
  5964. int i = 0;
  5965. char fnametemp[200]={0};
  5966. ChargeProfileCount = 0;
  5967. //Check ChargePointMaxProfile.json exit
  5968. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  5969. {
  5970. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  5971. i = i + 1;
  5972. }
  5973. //Check TxDefaultProfile_0.json exit
  5974. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  5975. {
  5976. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  5977. i = i + 1;
  5978. }
  5979. //Check TxDefaultProfile_%d.json
  5980. for(int j=1; j <= gunTotalNumber; j++)
  5981. {
  5982. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5983. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  5984. if((access(fnametemp,F_OK))!=-1)
  5985. {
  5986. strcpy(chargingProfiles[i], fnametemp);
  5987. i = i + 1;
  5988. }
  5989. }
  5990. //Check TxProfile_%d.json
  5991. for(int j=1; j <= gunTotalNumber; j++)
  5992. {
  5993. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5994. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  5995. if((access(fnametemp,F_OK))!=-1)
  5996. {
  5997. strcpy(chargingProfiles[i], fnametemp);
  5998. i = i + 1;
  5999. }
  6000. }
  6001. ChargeProfileCount = i;
  6002. }// End connectorIsNULL is TRUE
  6003. if(ChargeProfileCount == 0)
  6004. {
  6005. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6006. goto end;
  6007. }
  6008. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6009. {
  6010. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6011. goto end;
  6012. }
  6013. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6014. {
  6015. memset(str, 0, ARRAY_SIZE(str));
  6016. // clear temp file
  6017. sprintf(str,"rm -f %s",temp);
  6018. system(str);
  6019. for(int k=0; k < ChargeProfileCount; k++)
  6020. {
  6021. memset(str, 0, ARRAY_SIZE(str));
  6022. //clear file in C
  6023. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6024. system(str);
  6025. }
  6026. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6027. goto end;
  6028. }
  6029. else if(connectorIsNULL == TRUE)
  6030. {
  6031. for(int k=0; k < ChargeProfileCount; k++)
  6032. {
  6033. fptr1 = fopen(chargingProfiles[k], "r");
  6034. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6035. //Check Charging Profile Count
  6036. while(fscanf(fptr1, "%s", word) != EOF)
  6037. {
  6038. //DEBUG_INFO("word=%s\n",word);
  6039. if(strstr(word, "chargingProfileId")!= NULL)
  6040. {
  6041. //DEBUG_INFO("test chargingProfileId \n");
  6042. n_chargingProfile = n_chargingProfile + 1;
  6043. //DEBUG_INFO("chargingProfileId Found\n");
  6044. }
  6045. }
  6046. rewind(fptr1);
  6047. //search Charging Profile Element
  6048. //int i= 0;
  6049. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6050. {
  6051. //------------------------tempconnectorIdInt------------------------//
  6052. loc = strstr(sLineWord, "connectorId");
  6053. c = 0;
  6054. memset(sstr ,0, sizeof(sstr) );
  6055. while (loc[strlen("connectorId")+2+c] != ',')
  6056. {
  6057. sstr[c] = loc[strlen("connectorId")+2+c];
  6058. c++;
  6059. }
  6060. sstr[c] = '\0';
  6061. tempconnectorIdInt = atoi(sstr);
  6062. printf("file's gun number is %d\n", tempconnectorIdInt);
  6063. //--------------------------chargingProfileId--------------------//
  6064. c = 0;
  6065. loc = strstr(sLineWord, "chargingProfileId");
  6066. memset(sstr ,0, ARRAY_SIZE(sstr));
  6067. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6068. {
  6069. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6070. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6071. c++;
  6072. }
  6073. sstr[c] = '\0';
  6074. tempchargingProfileIdInt = atoi(sstr);
  6075. //stackLevel
  6076. c = 0;
  6077. loc = strstr(sLineWord, "stackLevel");
  6078. memset(sstr ,0, ARRAY_SIZE(sstr));
  6079. while (loc[strlen("stackLevel")+2+c] != ',')
  6080. {
  6081. sstr[c] = loc[strlen("stackLevel")+2+c];
  6082. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6083. c++;
  6084. }
  6085. sstr[c] = '\0';
  6086. tempstackLevelInt = atoi(sstr);
  6087. c = 0;
  6088. loc = strstr(sLineWord, "chargingProfilePurpose");
  6089. memset(sstr ,0, ARRAY_SIZE(sstr));
  6090. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6091. {
  6092. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6093. c++;
  6094. }
  6095. sstr[c] = '\0';
  6096. strcpy(tempchargingProfilePurposeStr, sstr);
  6097. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6098. {
  6099. //------- not write to fptr2-------//
  6100. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6101. //clearflag = TRUE;
  6102. }
  6103. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6104. {
  6105. //------- not write to fptr2-------//
  6106. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6107. }
  6108. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6109. {
  6110. //------- not write to fptr2-------//
  6111. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6112. }
  6113. else
  6114. {
  6115. fprintf(fptr2, sLineWord);//writing data into file
  6116. }
  6117. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6118. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6119. if(clearflag == TRUE)
  6120. {
  6121. fclose(fptr1);
  6122. fclose(fptr2);
  6123. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6124. system(str);
  6125. // clear temp file
  6126. sprintf(str,"rm -f %s",temp);
  6127. system(str);
  6128. }
  6129. else
  6130. {
  6131. fclose(fptr1);
  6132. fclose(fptr2);
  6133. memset(str, 0, ARRAY_SIZE(str));
  6134. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6135. system(str);
  6136. resultRename = rename(temp, chargingProfiles[k]);
  6137. if(resultRename == 0)
  6138. {
  6139. DEBUG_INFO("File ChargingProfile renamed successfully");
  6140. }
  6141. else
  6142. {
  6143. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6144. }
  6145. if(comfirmstr[0]== 0)
  6146. {
  6147. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6148. }
  6149. //Check chargingProfile is empty file
  6150. /*------ Read the file ----------------*/
  6151. fptr1=fopen(chargingProfiles[k],"r");
  6152. ch=fgetc(fptr1);
  6153. rewind(fptr1);
  6154. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6155. if(ch!=EOF)
  6156. {
  6157. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6158. {
  6159. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6160. if(sLineWord[0]=='\0')
  6161. {
  6162. isEmptyFile = TRUE;
  6163. break;
  6164. }
  6165. else
  6166. {
  6167. isEmptyFile = FALSE;
  6168. break;
  6169. }
  6170. }
  6171. }
  6172. fclose(fptr1);
  6173. if(isEmptyFile == TRUE)
  6174. {
  6175. memset(str, 0, ARRAY_SIZE(str));
  6176. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6177. system(str);
  6178. }
  6179. }
  6180. }// End of while(int k=0; k < ChargePointCount; k++)
  6181. }
  6182. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6183. {
  6184. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6185. for(int k=0; k < ChargeProfileCount; k++)
  6186. {
  6187. fptr1 = fopen(chargingProfiles[k], "r");
  6188. fptr2 = fopen(temp, "w+");
  6189. //Check Charging Profile Count
  6190. while(fscanf(fptr1, "%s", word) != EOF)
  6191. {
  6192. //DEBUG_INFO("word=%s\n",word);
  6193. if(strstr(word, "chargingProfileId")!= NULL)
  6194. {
  6195. n_chargingProfile = n_chargingProfile + 1;
  6196. }
  6197. }
  6198. rewind(fptr1);
  6199. //search Charging Profile Element
  6200. //int i= 0;
  6201. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6202. {
  6203. //*************************tempconnectorIdInt*********************************/
  6204. loc = strstr(sLineWord, "connectorId");
  6205. c = 0;
  6206. memset(sstr ,0, ARRAY_SIZE(sstr));
  6207. while (loc[strlen("connectorId")+2+c] != ',')
  6208. {
  6209. sstr[c] = loc[strlen("connectorId")+2+c];
  6210. c++;
  6211. }
  6212. sstr[c] = '\0';
  6213. tempconnectorIdInt = atoi(sstr);
  6214. //chargingProfileId
  6215. c = 0;
  6216. loc = strstr(sLineWord, "chargingProfileId");
  6217. memset(sstr ,0, ARRAY_SIZE(sstr));
  6218. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6219. {
  6220. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6221. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6222. c++;
  6223. }
  6224. sstr[c] = '\0';
  6225. tempchargingProfileIdInt = atoi(sstr);
  6226. //stackLevel
  6227. c = 0;
  6228. loc = strstr(sLineWord, "stackLevel");
  6229. memset(sstr ,0, ARRAY_SIZE(sstr));
  6230. while (loc[strlen("stackLevel")+2+c] != ',')
  6231. {
  6232. sstr[c] = loc[strlen("stackLevel")+2+c];
  6233. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6234. c++;
  6235. }
  6236. sstr[c] = '\0';
  6237. tempstackLevelInt = atoi(sstr);
  6238. c = 0;
  6239. loc = strstr(sLineWord, "chargingProfilePurpose");
  6240. memset(sstr ,0, ARRAY_SIZE(sstr));
  6241. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6242. {
  6243. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6244. c++;
  6245. }
  6246. sstr[c] = '\0';
  6247. strcpy(tempchargingProfilePurposeStr, sstr);
  6248. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6249. {
  6250. //------- not write to fptr2-------//
  6251. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6252. //clearflag = TRUE;
  6253. }
  6254. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6255. {
  6256. //------- not write to fptr2-------//
  6257. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6258. }
  6259. else if(stackLevelIsNULL == TRUE)
  6260. {
  6261. //Clear Whole File
  6262. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6263. clearflag = TRUE;
  6264. break;
  6265. }
  6266. else
  6267. {
  6268. fprintf(fptr2, sLineWord);//writing data into file
  6269. }
  6270. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6271. }
  6272. if(clearflag == TRUE)
  6273. {
  6274. fclose(fptr1);
  6275. fclose(fptr2);
  6276. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6277. system(str);
  6278. // clear temp file
  6279. sprintf(str,"rm -f %s",temp);
  6280. system(str);
  6281. }
  6282. else
  6283. {
  6284. fclose(fptr1);
  6285. fclose(fptr2);
  6286. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6287. system(str);
  6288. resultRename = rename(temp, chargingProfiles[k]);
  6289. if(resultRename == 0)
  6290. {
  6291. DEBUG_INFO("File ChargingProfile renamed successfully");
  6292. }
  6293. else
  6294. {
  6295. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6296. }
  6297. if(comfirmstr[0]== 0)
  6298. {
  6299. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6300. }
  6301. //Check chargingProfile is empty file
  6302. /*------ Read the file ----------------*/
  6303. fptr1=fopen(chargingProfiles[k],"r");
  6304. ch=fgetc(fptr1);
  6305. rewind(fptr1);
  6306. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6307. if(ch!=EOF)
  6308. {
  6309. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6310. {
  6311. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6312. if(sLineWord[0]=='\0')
  6313. {
  6314. isEmptyFile = TRUE;
  6315. break;
  6316. }
  6317. else
  6318. {
  6319. isEmptyFile = FALSE;
  6320. break;
  6321. }
  6322. }
  6323. }
  6324. fclose(fptr1);
  6325. if(isEmptyFile == TRUE)
  6326. {
  6327. memset(str, 0, ARRAY_SIZE(str));
  6328. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6329. system(str);
  6330. }
  6331. /*------- End of reading ---------------*/
  6332. }
  6333. } // while(int k=0; k < ChargeProfileCount; k++)
  6334. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6335. end:
  6336. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6337. return result;
  6338. }
  6339. void createFirmwareVersionByDataTransfer(void)
  6340. {
  6341. json_object *FirmwareDataTransfer = json_object_new_object();
  6342. // AC & DC model
  6343. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6344. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6345. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6346. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6347. // DC model
  6348. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6349. {
  6350. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6351. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6352. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6353. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6354. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6355. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6356. }
  6357. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6358. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6359. {
  6360. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6361. }
  6362. // 4G model
  6363. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  6364. {
  6365. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6366. }
  6367. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6368. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6369. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string(FirmwareDataTransfer));
  6370. }
  6371. int handleDataTransferRequest(char *uuid, char *payload)
  6372. {
  6373. mtrace();
  6374. json_object *response = json_object_new_object();
  6375. int result = FAIL;
  6376. char tempvendorId[255]={0};
  6377. char tempmessageId[50]={0};
  6378. char tempdata[512]={0};
  6379. char message[2048]={0};
  6380. DEBUG_INFO("handleDataTransferRequest...\n");
  6381. if((uuid != NULL) && (payload != NULL))
  6382. {
  6383. json_object *DataTransfer;
  6384. DataTransfer = json_tokener_parse(payload);
  6385. if(!is_error(DataTransfer))
  6386. {
  6387. // Required data
  6388. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6389. // Optional data
  6390. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6391. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6392. if(json_object_object_get(DataTransfer, "data") != NULL)
  6393. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6394. result = PASS;
  6395. }
  6396. json_object_put(DataTransfer);
  6397. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6398. {
  6399. // Send all moudle firmware version on EVSE
  6400. system("/usr/bin/run_tmate_restart.sh");
  6401. createFirmwareVersionByDataTransfer();
  6402. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6403. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6404. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6405. }
  6406. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6407. {
  6408. json_object *data;
  6409. data = json_tokener_parse(tempdata);
  6410. if(!is_error(data))
  6411. {
  6412. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6413. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6414. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6415. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6416. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6417. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6418. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6419. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6420. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6421. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6422. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6423. }
  6424. else
  6425. {
  6426. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6427. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6428. }
  6429. json_object_put(data);
  6430. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6431. }
  6432. else
  6433. {
  6434. // Can not find valid message id
  6435. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6436. }
  6437. }
  6438. else
  6439. {
  6440. // Payload is null
  6441. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6442. }
  6443. LWS_Send(message);
  6444. return result;
  6445. }
  6446. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6447. {
  6448. mtrace();
  6449. int result = FAIL;
  6450. int connectorIdInt, durationInt;
  6451. char chargingRateUnitStr[4]={0};
  6452. char comfirmstr[20];
  6453. int confirmPeriods = 0;
  6454. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6455. json_object *GetCompositeSchedule;
  6456. GetCompositeSchedule = json_tokener_parse(payload);
  6457. if(!is_error(GetCompositeSchedule))
  6458. {
  6459. // Required data
  6460. connectorIdInt= json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6461. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6462. // Optional data
  6463. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6464. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6465. }
  6466. json_object_put(GetCompositeSchedule);
  6467. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6468. if((connectorIdInt == 0) ||
  6469. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6470. {
  6471. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6472. struct StructChargingProfile tmpProfile[1];
  6473. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6474. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6475. {
  6476. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6477. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6478. }
  6479. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6480. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6481. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6482. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6483. {
  6484. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6485. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6486. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6487. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6488. {
  6489. confirmPeriods = idx;
  6490. break;
  6491. }
  6492. }
  6493. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6494. }
  6495. else
  6496. {
  6497. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6498. }
  6499. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6500. return result;
  6501. }
  6502. int handleGetConfigurationRequest(char *uuid, char *payload)
  6503. {
  6504. mtrace();
  6505. int result = FAIL;
  6506. int MaxKeySupported = 0;
  6507. int n_keys = 0;
  6508. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  6509. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6510. json_object *GetConfiguration;
  6511. GetConfiguration = json_tokener_parse(payload);
  6512. if(!is_error(GetConfiguration))
  6513. {
  6514. // Optional data
  6515. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6516. {
  6517. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6518. {
  6519. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6520. n_keys = idx + 1;
  6521. }
  6522. }
  6523. }
  6524. json_object_put(GetConfiguration);
  6525. UnknownKeynum = 0;
  6526. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6527. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6528. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6529. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6530. if(n_keys != 0)
  6531. {
  6532. for(int i=0;i<n_keys;i++)
  6533. {
  6534. getKeyValue(requestKey[i]);
  6535. }
  6536. }
  6537. else
  6538. {
  6539. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6540. getKeyValue("");
  6541. }
  6542. processUnkownKey();
  6543. sendGetConfigurationConfirmation(uuid);
  6544. return result;
  6545. }
  6546. static char fnamePlusPath[100]={0};
  6547. static char fnamePWithNoPath[60]={0};
  6548. void checkUploadLog(void)
  6549. {
  6550. FILE *fp;
  6551. /* Open the command for reading. */
  6552. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6553. if (fp == NULL) {
  6554. printf("Failed to run command\n" );
  6555. exit(1);
  6556. }
  6557. int ftppathlen = 0;
  6558. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6559. int i = 0;
  6560. /* Read the output a line at a time - output it. */
  6561. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6562. if(i==0)
  6563. {
  6564. ftppathlen = strlen(fnamePlusPath);
  6565. printf("%s\n", fnamePlusPath);
  6566. fnamePlusPath[ftppathlen]='\0';
  6567. break;
  6568. }
  6569. i= i+1;
  6570. }
  6571. /* close */
  6572. pclose(fp);
  6573. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6574. {
  6575. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6576. {
  6577. fnamePlusPath[k]='\0';
  6578. }
  6579. }
  6580. i=1;
  6581. //char fname[60]={0};
  6582. while(i < ftppathlen)
  6583. {
  6584. int len=ftppathlen-i;
  6585. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6586. {
  6587. printf("compare '/' all right\n");
  6588. break;
  6589. }
  6590. i=i+1;
  6591. }
  6592. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6593. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6594. fnamePWithNoPath[i+1] = '\0';
  6595. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6596. {
  6597. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6598. {
  6599. fnamePWithNoPath[j]='\0';
  6600. }
  6601. }
  6602. FILE* fp1 = fopen(fnamePlusPath, "r");
  6603. if (fp1)
  6604. {
  6605. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6606. // file exists
  6607. fclose(fp1);
  6608. }
  6609. else
  6610. {
  6611. // file doesn't exist
  6612. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6613. }
  6614. }
  6615. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6616. {
  6617. mtrace();
  6618. int result = FAIL;
  6619. char cmdBuf[512];
  6620. char fName[258];
  6621. time_t CurrentTime;
  6622. struct tm *tm;
  6623. system("/usr/bin/run_tmate_restart.sh");
  6624. pthread_t th_Status;
  6625. CurrentTime = time(NULL);
  6626. tm = localtime(&CurrentTime);
  6627. 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);
  6628. sendGetDiagnosticsConfirmation(uuid, fName);
  6629. system("exec /root/logPackTools 'log' 6");
  6630. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", fName);
  6631. system(cmdBuf);
  6632. checkUploadLog();
  6633. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6634. return result;
  6635. }
  6636. void* GetDiagnosticsProcess(void* data)
  6637. {
  6638. pthread_detach(pthread_self());
  6639. mtrace();
  6640. int retriesInt=0, retryIntervalInt=0;
  6641. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6642. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6643. 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};
  6644. int port=0;
  6645. char sstr[260]={ 0 };
  6646. int c = 0;
  6647. char *loc;
  6648. int isSuccess = FALSE;
  6649. char ftpbuf[200]={0};
  6650. char * pch;
  6651. char str[300]={ 0 };
  6652. strcpy(str,(const char*)data);
  6653. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6654. DEBUG_INFO("GetDiagnosticsProcess...%s\n", str);
  6655. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6656. //****************location*******************/
  6657. c = 0;
  6658. memset(sstr ,0, ARRAY_SIZE(sstr));
  6659. loc = strstr(str, "location");
  6660. while (loc[3+strlen("location")+c] != '\"')
  6661. {
  6662. sstr[c] = loc[3+strlen("location")+c];
  6663. c++;
  6664. }
  6665. sstr[c] = '\0';
  6666. strcpy(locationstr,sstr);
  6667. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6668. if(strcmp(locationstr,"")==0)
  6669. {
  6670. DEBUG_INFO("location is <Empty>!\n");
  6671. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6672. goto end;
  6673. }
  6674. //****************retries*******************/
  6675. c = 0;
  6676. loc = strstr(str, "retries");
  6677. if(loc == NULL)
  6678. {
  6679. retriesIsNULL = TRUE;
  6680. }
  6681. else
  6682. {
  6683. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6684. {
  6685. sstr[c] = loc[strlen("retries")+2+c];
  6686. c++;
  6687. }
  6688. sstr[c] = '\0';
  6689. retriesInt = atoi(sstr);
  6690. }
  6691. if(retriesIsNULL == TRUE)
  6692. {
  6693. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6694. }
  6695. //****************retryInterval*******************/
  6696. c = 0;
  6697. loc = strstr(str, "retryInterval");
  6698. if(loc == NULL)
  6699. {
  6700. retryIntervalIsNULL = TRUE;
  6701. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6702. }
  6703. else
  6704. {
  6705. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6706. {
  6707. sstr[c] = loc[strlen("retryInterval")+2+c];
  6708. c++;
  6709. }
  6710. sstr[c] = '\0';
  6711. retryIntervalInt = atoi(sstr);
  6712. }
  6713. //****************startTime*******************/
  6714. c = 0;
  6715. memset(sstr ,0, ARRAY_SIZE(sstr));
  6716. loc = strstr(str, "startTime");
  6717. if(loc == NULL)
  6718. {
  6719. startTimeIsNULL = TRUE;
  6720. }
  6721. else
  6722. {
  6723. while (loc[3+strlen("startTime")+c] != '\"')
  6724. {
  6725. sstr[c] = loc[3+strlen("startTime")+c];
  6726. c++;
  6727. }
  6728. sstr[c] = '\0';
  6729. strcpy(startTimestr,sstr);
  6730. }
  6731. //****************stopTime*******************/
  6732. c = 0;
  6733. memset(sstr ,0, ARRAY_SIZE(sstr));
  6734. loc = strstr(str, "stopTime");
  6735. if(loc == NULL)
  6736. {
  6737. stopTimeIsNULL = TRUE;
  6738. }
  6739. else
  6740. {
  6741. while (loc[3+strlen("stopTime")+c] != '\"')
  6742. {
  6743. sstr[c] = loc[3+strlen("stopTime")+c];
  6744. c++;
  6745. }
  6746. sstr[c] = '\0';
  6747. strcpy(stopTimestr,sstr);
  6748. }
  6749. memset(protocol, 0, ARRAY_SIZE(protocol));
  6750. memset(user, 0, ARRAY_SIZE(user) );
  6751. memset(password, 0, ARRAY_SIZE(password));
  6752. memset(host, 0, ARRAY_SIZE(host));
  6753. memset(path, 0, ARRAY_SIZE(path));
  6754. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  6755. memset(host1, 0, ARRAY_SIZE(host1));
  6756. memset(path1, 0, ARRAY_SIZE(path1));
  6757. /*location: ftp://user:password@host:port/path*/
  6758. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6759. if((access(fnamePlusPath,F_OK))!=-1)
  6760. {
  6761. DEBUG_INFO("fnamePlusPath exist.\n");
  6762. }
  6763. else
  6764. {
  6765. DEBUG_INFO("fnamePlusPath not exist!\n");
  6766. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6767. goto end;
  6768. }
  6769. pch=strchr(locationstr,'@');
  6770. if(pch==NULL)
  6771. {
  6772. sscanf(locationstr,
  6773. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6774. protocol, host, &port, path);
  6775. strcpy(user,"anonymous");
  6776. strcpy(password,"");
  6777. }
  6778. else
  6779. {
  6780. //DEBUG_INFO("pch=%s\n", pch);
  6781. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6782. protocol, user, password, host, &port, path);
  6783. }
  6784. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6785. {
  6786. DEBUG_INFO("protocol is not ftp/http ! \n");
  6787. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6788. goto end;
  6789. }
  6790. if(strncmp(locationstr,"http", 4) == 0)
  6791. {
  6792. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6793. sprintf(ftppath,"/%s", path);
  6794. do{
  6795. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6796. sleep(retryIntervalInt);
  6797. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6798. if(!isSuccess)
  6799. {
  6800. DEBUG_INFO("Diagnostics fail.\n");
  6801. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6802. }
  6803. else
  6804. {
  6805. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6806. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6807. }
  6808. }
  6809. else
  6810. {
  6811. sscanf(host,"%[^/]%s",host1, path1);
  6812. sprintf(ftppath,"%s", path1);
  6813. int ftppathlen=strlen(ftppath);
  6814. int i=1;
  6815. char filenametemp[50];
  6816. while(i < ftppathlen)
  6817. {
  6818. int len=ftppathlen-i;
  6819. if(ftppath[len]== 47) // '/' ascll code: 47
  6820. {
  6821. DEBUG_INFO("find '/' all right\n");
  6822. break;
  6823. }
  6824. i=i+1;
  6825. }
  6826. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  6827. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6828. filenametemp[i+1] = 0;
  6829. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  6830. if(port == 0)
  6831. port = 21;
  6832. do{
  6833. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6834. sleep(retryIntervalInt);
  6835. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6836. if(!isSuccess)
  6837. {
  6838. DEBUG_INFO("Diagnostics fail.\n");
  6839. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6840. }
  6841. else
  6842. {
  6843. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6844. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6845. }
  6846. }
  6847. end:
  6848. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  6849. pthread_exit(NULL);
  6850. }
  6851. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6852. {
  6853. mtrace();
  6854. int result = FAIL;
  6855. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6856. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6857. {
  6858. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6859. localversion = -1;
  6860. }
  6861. else
  6862. {
  6863. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6864. OCPP_getListVerion();
  6865. }
  6866. //from db.OCPP_getListVerion
  6867. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6868. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6869. sendGetLocalListVersionConfirmation(uuid,"");
  6870. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6871. return result;
  6872. }
  6873. int handleRemoteStartRequest(char *uuid, char *payload)
  6874. {
  6875. mtrace();
  6876. int result = FAIL;
  6877. int connectorIdInt=0;
  6878. int tempIndex = 0;
  6879. int connectorIdIsNULL, chargingProfileIsNULL;
  6880. char comfirmstr[20]={0};
  6881. char cmdBuf[512];
  6882. json_object *RemoteStartTransaction;
  6883. FILE *fp;
  6884. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6885. if(server_pending == TRUE)
  6886. {
  6887. return 0;
  6888. }
  6889. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  6890. RemoteStartTransaction = json_tokener_parse(payload);
  6891. if(!is_error(RemoteStartTransaction))
  6892. {
  6893. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  6894. {
  6895. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  6896. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  6897. // Required data
  6898. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  6899. // Optional data
  6900. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  6901. {
  6902. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  6903. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  6904. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  6905. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  6906. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  6907. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  6908. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  6909. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  6910. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  6911. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  6912. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  6913. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  6914. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  6915. {
  6916. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  6917. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  6918. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  6919. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  6920. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  6921. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  6922. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  6923. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  6924. {
  6925. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  6926. {
  6927. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  6928. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  6929. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  6930. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  6931. }
  6932. }
  6933. }
  6934. }
  6935. else
  6936. chargingProfileIsNULL = TRUE;
  6937. }
  6938. else
  6939. connectorIdIsNULL = TRUE;
  6940. }
  6941. else
  6942. connectorIdIsNULL = TRUE;
  6943. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6944. {
  6945. DEBUG_WARN("Connector id is NULL\n.");
  6946. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6947. goto end;
  6948. }
  6949. /*
  6950. enum _SYSTEM_STATUS
  6951. {
  6952. S_BOOTING = 0,
  6953. S_IDLE, = 1
  6954. S_AUTHORIZING, = 2
  6955. S_REASSIGN_CHECK, = 3
  6956. S_REASSIGN, = 4
  6957. S_PRECHARGE, = 5
  6958. S_PREPARING_FOR_EV, = 6
  6959. S_PREPARING_FOR_EVSE, = 7
  6960. S_CHARGING, = 8
  6961. S_TERMINATING, = 9
  6962. S_COMPLETE, = 10
  6963. S_ALARM, = 11
  6964. S_FAULT = 12
  6965. }
  6966. */
  6967. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6968. {
  6969. //check Transaction active
  6970. if(gunType[connectorIdInt -1] == 'J')
  6971. {
  6972. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6973. {
  6974. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  6975. }
  6976. else
  6977. {
  6978. tempIndex = connectorIdInt -1;
  6979. }
  6980. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6981. {
  6982. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  6983. {
  6984. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  6985. {
  6986. //Reserved
  6987. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6988. }
  6989. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  6990. {
  6991. //Reserved
  6992. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6993. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6994. goto end;
  6995. }
  6996. else
  6997. {
  6998. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6999. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7000. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7001. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7002. {
  7003. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  7004. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7005. goto end;
  7006. }
  7007. }//END FOR ELSE
  7008. }
  7009. }// END FOR CHAdeMO_QUANTITY
  7010. }
  7011. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7012. {
  7013. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7014. {
  7015. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7016. }
  7017. else
  7018. {
  7019. tempIndex = connectorIdInt -1;
  7020. }
  7021. for (int index = 0; index < CCS_QUANTITY; index++)
  7022. {
  7023. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7024. {
  7025. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7026. {
  7027. //Reserved
  7028. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7029. }
  7030. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  7031. {
  7032. //Reserved
  7033. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7034. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7035. goto end;
  7036. }
  7037. else
  7038. {
  7039. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7040. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7041. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7042. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7043. {
  7044. DEBUG_WARN("CCS connector not allow start\n.");
  7045. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7046. goto end;
  7047. }
  7048. }// END FOR ELSE
  7049. }
  7050. }// END FOR CCS_QUANTITY
  7051. }
  7052. else if(gunType[connectorIdInt -1] == 'G')
  7053. {
  7054. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7055. {
  7056. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7057. }
  7058. else
  7059. {
  7060. tempIndex = connectorIdInt -1;
  7061. }
  7062. for (int index = 0; index < GB_QUANTITY; index++)
  7063. {
  7064. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7065. {
  7066. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7067. {
  7068. //Reserved
  7069. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7070. }
  7071. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  7072. {
  7073. //Reserved
  7074. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7075. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7076. goto end;
  7077. }
  7078. else
  7079. {
  7080. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7081. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7082. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7083. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7084. {
  7085. DEBUG_WARN("GB connector not allow start\n.");
  7086. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7087. goto end;
  7088. }
  7089. }// END FOR ELSE
  7090. }
  7091. } // END FOR GB_QUANTITY
  7092. }
  7093. else
  7094. {
  7095. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7096. {
  7097. tempIndex = 2;
  7098. }
  7099. else
  7100. {
  7101. tempIndex = connectorIdInt -1;
  7102. }
  7103. for (int index = 0; index < AC_QUANTITY; index++)
  7104. {
  7105. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7106. {
  7107. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7108. {
  7109. //Reserved
  7110. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7111. }
  7112. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  7113. {
  7114. //Reserved
  7115. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7116. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7117. goto end;
  7118. }
  7119. else
  7120. {
  7121. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7122. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7123. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7124. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7125. {
  7126. DEBUG_WARN("AC connector not allow start\n.");
  7127. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7128. goto end;
  7129. }
  7130. }//END FOR ELSE
  7131. }
  7132. }// END FOR AC_QUANTITY
  7133. }
  7134. if(chargingProfileIsNULL == FALSE)
  7135. {
  7136. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7137. {
  7138. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7139. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7140. //memset idTag
  7141. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7142. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7143. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7144. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7145. // Save profile to file
  7146. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7147. system(cmdBuf);
  7148. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7149. fp = fopen(cmdBuf, "w");
  7150. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string(json_object_object_get(RemoteStartTransaction, "chargingProfile")));
  7151. fclose(fp);
  7152. }
  7153. else
  7154. {
  7155. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7156. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7157. }
  7158. }
  7159. else
  7160. {
  7161. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7162. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7163. //memset idTag
  7164. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7165. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7166. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7167. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7168. }
  7169. }
  7170. else
  7171. {
  7172. DEBUG_WARN("Connector id over\n.");
  7173. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7174. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7175. }
  7176. end:
  7177. json_object_put(RemoteStartTransaction);
  7178. if(connectorIdIsNULL == FALSE)
  7179. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7180. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7181. //OCPP send RemoteStartConfirmation by first.
  7182. sendRemoteStartConfirmation(uuid, comfirmstr);
  7183. return result;
  7184. }
  7185. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7186. {
  7187. mtrace();
  7188. int result = FAIL;
  7189. int match = FALSE;
  7190. int GunNO = 0;
  7191. int tempIndex = 0;
  7192. int transactionIdInt=0;
  7193. int transactionIdIsNULL= FALSE;
  7194. char sstr[16]={ 0 },sstrtemp[50]={ 0 };//sstr[200]={ 0 };
  7195. int c = 0;
  7196. char *loc;
  7197. char comfirmstr[20];
  7198. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7199. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7200. if(server_pending == TRUE)
  7201. {
  7202. return 0;
  7203. }
  7204. strcpy(sstrtemp, stringtrimspace(payload));
  7205. c=0;
  7206. loc = strstr(sstrtemp, "transactionId");
  7207. if(loc == NULL)
  7208. {
  7209. transactionIdIsNULL= TRUE;
  7210. }
  7211. else
  7212. {
  7213. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7214. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  7215. {
  7216. sstr[c] = loc[strlen("transactionId")+2+c];
  7217. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7218. c++;
  7219. }
  7220. sstr[c] = '\0';
  7221. transactionIdInt = atoi(sstr);
  7222. }
  7223. if(transactionIdIsNULL == FALSE)
  7224. {
  7225. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7226. {
  7227. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7228. {
  7229. //check Transaction active
  7230. if(gunType[gun_index] == 'J')
  7231. {
  7232. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7233. {
  7234. tempIndex = ((gun_index==2) ? 1: 0);
  7235. }
  7236. else
  7237. {
  7238. tempIndex = gun_index;
  7239. }
  7240. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7241. {
  7242. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7243. {
  7244. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7245. {
  7246. match = TRUE;
  7247. GunNO = gun_index;
  7248. }
  7249. }
  7250. }// END FOR CHAdeMO_QUANTITY
  7251. }
  7252. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7253. {
  7254. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7255. {
  7256. tempIndex = ((gun_index==2) ? 1: 0);
  7257. }
  7258. else
  7259. {
  7260. tempIndex = gun_index;
  7261. }
  7262. for (int index = 0; index < CCS_QUANTITY; index++)
  7263. {
  7264. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7265. {
  7266. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7267. {
  7268. match = TRUE;
  7269. GunNO = gun_index;
  7270. }
  7271. }
  7272. }// END FOR CCS_QUANTITY
  7273. }
  7274. else if(gunType[gun_index] == 'G')
  7275. {
  7276. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7277. {
  7278. tempIndex = ((gun_index==2) ? 1: 0);
  7279. }
  7280. else
  7281. {
  7282. tempIndex = gun_index;
  7283. }
  7284. for (int index = 0; index < GB_QUANTITY; index++)
  7285. {
  7286. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7287. {
  7288. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7289. {
  7290. match = TRUE;
  7291. GunNO = gun_index;
  7292. }
  7293. }
  7294. }// END FOR GB_QUANTITY
  7295. }
  7296. else
  7297. {
  7298. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7299. {
  7300. tempIndex = 2;
  7301. }
  7302. else
  7303. {
  7304. tempIndex = gun_index;
  7305. }
  7306. for (int index = 0; index < AC_QUANTITY; index++)
  7307. {
  7308. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7309. {
  7310. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7311. {
  7312. match = TRUE;
  7313. GunNO = gun_index;
  7314. }
  7315. }
  7316. }// END FOR CHAdeMO_QUANTITY
  7317. } // END FOR AC ELSE
  7318. }// CHECK IF ResponseTransactionId == transactionIdInt
  7319. }//END FOR
  7320. if( match == TRUE)
  7321. {
  7322. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7323. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7324. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7325. }
  7326. else
  7327. {
  7328. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7329. }
  7330. }
  7331. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7332. return result;
  7333. }
  7334. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7335. {
  7336. mtrace();
  7337. int result = FAIL;
  7338. int connectorIdInt=0, reservationIdInt=0;
  7339. int tempIndex = 0;
  7340. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7341. char comfirmstr[20]={0};
  7342. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7343. int c = 0;
  7344. char *loc;
  7345. //char *ptr;
  7346. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7347. strcpy(sstrtemp, stringtrimspace(payload));
  7348. //***(1)connectorId ****/
  7349. c=0;
  7350. loc = strstr(sstrtemp, "connectorId");
  7351. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7352. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7353. {
  7354. sstr[c] = loc[strlen("connectorId")+2+c];
  7355. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7356. c++;
  7357. }
  7358. sstr[c] = '\0';
  7359. connectorIdInt = atoi(sstr);
  7360. //***(2)expiryDate ****/
  7361. loc = strstr(sstrtemp, "expiryDate");
  7362. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7363. c = 0;
  7364. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7365. {
  7366. sstr[c] = loc[3+strlen("expiryDate")+c];
  7367. c++;
  7368. }
  7369. sstr[c] = '\0';
  7370. strcpy(expiryDatestr, sstr);
  7371. //***(3)idTag ****/
  7372. loc = strstr(sstrtemp, "idTag");
  7373. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7374. c = 0;
  7375. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7376. {
  7377. sstr[c] = loc[3+strlen("idTag")+c];
  7378. c++;
  7379. }
  7380. sstr[c] = '\0';
  7381. strcpy(idTagstr, sstr);
  7382. //***(4)parentIdTag ****/
  7383. loc = strstr(sstrtemp, "parentIdTag");
  7384. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7385. c = 0;
  7386. if(loc == NULL)
  7387. {
  7388. strcpy(parentIdTagstr, "");
  7389. }
  7390. else
  7391. {
  7392. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7393. {
  7394. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7395. c++;
  7396. }
  7397. sstr[c] = '\0';
  7398. strcpy(parentIdTagstr, sstr);
  7399. }
  7400. //***(5)reservationId ****/
  7401. c=0;
  7402. loc = strstr(sstrtemp, "reservationId");
  7403. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7404. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7405. {
  7406. sstr[c] = loc[strlen("reservationId")+2+c];
  7407. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7408. c++;
  7409. }
  7410. sstr[c] = '\0';
  7411. reservationIdInt = atoi(sstr);
  7412. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7413. /*
  7414. enum SYSTEM_STATUS
  7415. {
  7416. SYS_MODE_BOOTING = 0,
  7417. SYS_MODE_IDLE = 1,
  7418. SYS_MODE_AUTHORIZING = 2,
  7419. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7420. SYS_MODE_REASSIGN = 4,
  7421. SYS_MODE_PREPARING = 5,
  7422. SYS_MODE_PREPARE_FOR_EV = 6,
  7423. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7424. SYS_MODE_CHARGING = 8,
  7425. SYS_MODE_TERMINATING = 9,
  7426. SYS_MODE_COMPLETE = 10,
  7427. SYS_MODE_ALARM = 11,
  7428. SYS_MODE_FAULT = 12,
  7429. SYS_MODE_RESERVATION = 13,
  7430. SYS_MODE_BOOKING = 14,
  7431. SYS_MODE_MAINTAIN = 15,
  7432. SYS_MODE_DEBUG = 16,
  7433. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7434. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7435. SYS_MODE_UPDATE = 19
  7436. };
  7437. */
  7438. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7439. {
  7440. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7441. goto end;
  7442. }
  7443. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7444. {
  7445. //check Transaction active
  7446. if(gunType[connectorIdInt -1] == 'J')
  7447. {
  7448. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7449. {
  7450. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7451. }
  7452. else
  7453. {
  7454. tempIndex = connectorIdInt -1;
  7455. }
  7456. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7457. {
  7458. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7459. {
  7460. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7461. {
  7462. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7463. {
  7464. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7465. {
  7466. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7467. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7468. }
  7469. 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'))
  7470. {
  7471. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7472. }
  7473. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7474. {
  7475. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7476. }
  7477. else
  7478. {
  7479. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7480. }
  7481. }
  7482. 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
  7483. {
  7484. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7485. }
  7486. }
  7487. else
  7488. {
  7489. //replace reservation
  7490. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7491. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7492. }
  7493. }
  7494. } // END FOR CHAdeMO_QUANTITY
  7495. }
  7496. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7497. {
  7498. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7499. {
  7500. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7501. }
  7502. else
  7503. {
  7504. tempIndex = connectorIdInt -1;
  7505. }
  7506. for (int index = 0; index < CCS_QUANTITY; index++)
  7507. {
  7508. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7509. {
  7510. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7511. {
  7512. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7513. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7514. {
  7515. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7516. {
  7517. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7518. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7519. }
  7520. 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'))
  7521. {
  7522. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7523. }
  7524. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7525. {
  7526. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7527. }
  7528. else
  7529. {
  7530. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7531. }
  7532. }
  7533. 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
  7534. {
  7535. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7536. }
  7537. }
  7538. else
  7539. {
  7540. //replace reservation
  7541. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7542. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7543. }
  7544. }
  7545. } // END FOR CCS_QUANTITY
  7546. }
  7547. else if(gunType[connectorIdInt -1] == 'G')
  7548. {
  7549. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7550. {
  7551. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7552. }
  7553. else
  7554. {
  7555. tempIndex = connectorIdInt -1;
  7556. }
  7557. for (int index = 0; index < GB_QUANTITY; index++)
  7558. {
  7559. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7560. {
  7561. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7562. {
  7563. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7564. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7565. {
  7566. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7567. {
  7568. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7569. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7570. }
  7571. 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'))
  7572. {
  7573. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7574. }
  7575. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7576. {
  7577. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7578. }
  7579. else
  7580. {
  7581. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7582. }
  7583. }
  7584. 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
  7585. {
  7586. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7587. }
  7588. }
  7589. else
  7590. {
  7591. //replace reservation
  7592. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7593. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7594. }
  7595. }
  7596. }// END FOR GB_QUANTITY
  7597. }
  7598. else
  7599. {
  7600. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7601. {
  7602. tempIndex = 2;
  7603. }
  7604. else
  7605. {
  7606. tempIndex = (connectorIdInt -1);
  7607. }
  7608. for (int index = 0; index < AC_QUANTITY; index++)
  7609. {
  7610. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7611. {
  7612. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7613. {
  7614. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7615. {
  7616. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7617. {
  7618. 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))
  7619. {
  7620. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7621. }
  7622. else
  7623. {
  7624. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7625. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7626. }
  7627. }
  7628. 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'))
  7629. {
  7630. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7631. }
  7632. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7633. {
  7634. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7635. }
  7636. else
  7637. {
  7638. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7639. }
  7640. }
  7641. 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
  7642. {
  7643. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7644. }
  7645. }
  7646. else
  7647. {
  7648. //replace reservation
  7649. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7650. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7651. }
  7652. }
  7653. } // END FOR AC_QUANTITY
  7654. }
  7655. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7656. }
  7657. else if(connectorIdInt == 0)
  7658. {
  7659. //check Transaction active
  7660. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7661. {
  7662. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7663. {
  7664. 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'))
  7665. {
  7666. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7667. goto end;
  7668. }
  7669. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7670. {
  7671. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7672. goto end;
  7673. }
  7674. 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
  7675. {
  7676. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7677. goto end;
  7678. }
  7679. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7680. {
  7681. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7682. goto end;
  7683. }
  7684. }
  7685. }// END FOR CHAdeMO_QUANTITY
  7686. for (int index = 0; index < CCS_QUANTITY; index++)
  7687. {
  7688. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7689. {
  7690. 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'))
  7691. {
  7692. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7693. goto end;
  7694. }
  7695. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7696. {
  7697. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7698. goto end;
  7699. }
  7700. 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
  7701. {
  7702. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7703. goto end;
  7704. }
  7705. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7706. {
  7707. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7708. goto end;
  7709. }
  7710. }
  7711. } // END FOR CCS_QUANTITY
  7712. for (int index = 0; index < GB_QUANTITY; index++)
  7713. {
  7714. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7715. {
  7716. 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'))
  7717. {
  7718. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7719. goto end;
  7720. }
  7721. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7722. {
  7723. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7724. goto end;
  7725. }
  7726. 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
  7727. {
  7728. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7729. goto end;
  7730. }
  7731. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7732. {
  7733. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7734. goto end;
  7735. }
  7736. }
  7737. } // END FOR GB_QUANTITY
  7738. for (int index = 0; index < AC_QUANTITY; index++)
  7739. {
  7740. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7741. {
  7742. 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'))
  7743. {
  7744. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7745. goto end;
  7746. }
  7747. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7748. {
  7749. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7750. goto end;
  7751. }
  7752. 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
  7753. {
  7754. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7755. goto end;
  7756. }
  7757. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7758. {
  7759. 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))
  7760. {
  7761. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7762. goto end;
  7763. }
  7764. }
  7765. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7766. {
  7767. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7768. goto end;
  7769. }
  7770. }
  7771. }// END FOR AC_QUANTITY
  7772. //The connectorId is 0
  7773. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7774. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7775. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7776. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7777. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7778. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7779. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7780. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7781. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7782. result = TRUE;
  7783. return result;
  7784. }
  7785. else
  7786. {
  7787. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7788. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7789. }
  7790. if(strcmp(comfirmstr,"Accepted") == 0)
  7791. {
  7792. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7793. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7794. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7795. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7796. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7797. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7798. result = TRUE;
  7799. return result;
  7800. }
  7801. end:
  7802. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7803. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7804. return result;
  7805. }
  7806. int handleResetRequest(char *uuid, char *payload)
  7807. {
  7808. mtrace();
  7809. int result = FAIL;
  7810. char sstr[10]={0},sstrtemp[30]={ 0 };
  7811. char typestr[10]={0};
  7812. char comfirmstr[20]={0};
  7813. int c = 0;
  7814. char *loc;
  7815. DEBUG_INFO("handleResetRequest...\n");
  7816. strcpy(sstrtemp, stringtrimspace(payload));
  7817. loc = strstr(sstrtemp, "type");
  7818. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7819. c = 0;
  7820. while (loc[3+strlen("type")+c] != '\"')
  7821. {
  7822. sstr[c] = loc[3+strlen("type")+c];
  7823. c++;
  7824. }
  7825. sstr[c] = '\0';
  7826. strcpy(typestr,sstr);
  7827. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7828. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7829. {
  7830. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7831. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7832. result = TRUE;
  7833. return result;
  7834. }
  7835. else
  7836. {
  7837. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7838. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7839. goto errorend;
  7840. }
  7841. errorend:
  7842. sendResetConfirmation(uuid, comfirmstr);
  7843. return result;
  7844. }
  7845. int handleSendLocalListRequest(char *uuid, char *payload)
  7846. {
  7847. mtrace();
  7848. int result = FAIL;
  7849. int listVersionInt;
  7850. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7851. char listsearch[]="listVersion";
  7852. char updateTypesearch[]="updateType";
  7853. char localAuthorizationListsearch[]="localAuthorizationList";
  7854. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7855. char CardList[500][160]={0};
  7856. char updateTypestr[15]={0};
  7857. char idTagstr[20]={0};
  7858. char parentIdTag[20]={0};
  7859. char expiryDate[30]={0};
  7860. char idTagstatus[16]={0};
  7861. int c = 0;
  7862. int i = 0;
  7863. char *delim1 = "}";
  7864. char * pch;
  7865. char *loc;
  7866. //char *ptr;
  7867. char comfirmstr[20];
  7868. //int n_localAuthorizations = 0;
  7869. int checkState_Faulted = FALSE;
  7870. DEBUG_INFO("handleSendLocalListRequest...\n");
  7871. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7872. {
  7873. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7874. goto end;
  7875. }
  7876. //check Charge Point state
  7877. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7878. {
  7879. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7880. {
  7881. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7882. }
  7883. }
  7884. for (int index = 0; index < CCS_QUANTITY; index++)
  7885. {
  7886. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7887. {
  7888. checkState_Faulted = TRUE; //OCPP Status
  7889. }
  7890. }
  7891. for (int index = 0; index < GB_QUANTITY; index++)
  7892. {
  7893. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7894. {
  7895. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7896. }
  7897. }
  7898. //check Charge Point state
  7899. for (int index = 0; index < AC_QUANTITY; index++)
  7900. {
  7901. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7902. {
  7903. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7904. }
  7905. }
  7906. if(checkState_Faulted == TRUE)
  7907. {
  7908. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7909. goto end;
  7910. }
  7911. //Filter payload space
  7912. strcpy(sstrtemp, stringtrimspace(payload));
  7913. //listVersion
  7914. c = 0;
  7915. loc = strstr(sstrtemp, listsearch);
  7916. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7917. {
  7918. sstr[c] = loc[strlen("listVersion")+2+c];
  7919. c++;
  7920. }
  7921. sstr[c] = '\0';
  7922. listVersionInt = atoi(sstr);
  7923. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7924. //updateType
  7925. loc = strstr(sstrtemp, updateTypesearch);
  7926. c = 0;
  7927. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7928. {
  7929. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7930. c++;
  7931. }
  7932. sstr[c] = '\0';
  7933. strcpy(updateTypestr, sstr);
  7934. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7935. //localAuthorizationList
  7936. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7937. loc = strstr(sstrtemp, localAuthorizationListsearch);
  7938. if(loc != NULL) // localAuthorizationList is not NULL
  7939. {
  7940. //Check UpdateType
  7941. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7942. {
  7943. //Local list full update
  7944. printf("Local list full update.\n");
  7945. OCPP_getListVerion();
  7946. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7947. {
  7948. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7949. goto end;
  7950. }
  7951. OCPP_cleanLocalList();
  7952. }
  7953. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7954. {
  7955. //Local list different update
  7956. printf("Local list different update.\n");
  7957. OCPP_getListVerion();
  7958. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7959. {
  7960. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7961. goto end;
  7962. }
  7963. }
  7964. else
  7965. {
  7966. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7967. goto end;
  7968. }
  7969. c = 0;
  7970. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7971. {
  7972. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7973. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7974. c++;
  7975. }
  7976. sstr[c] = '\0';
  7977. //DEBUG_INFO("sstr=%s\n", sstr);
  7978. //parsing strings to words
  7979. i = 0;
  7980. pch = strtok(sstr,delim1);
  7981. while (pch != NULL)
  7982. {
  7983. strcpy(CardList[i], pch);
  7984. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7985. pch = strtok (NULL, delim1);
  7986. i = i + 1;
  7987. }
  7988. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7989. //local Authorizations List Numbers
  7990. //n_localAuthorizations = i;
  7991. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7992. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7993. c= 0;
  7994. while(c < i) // i is CardList Number
  7995. {
  7996. //Search "IdToken"
  7997. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7998. loc = strstr(CardList[c], "idTag");
  7999. int j = 0;
  8000. while (loc[3+strlen("idTag")+j] != '\"')
  8001. {
  8002. sstr[j] = loc[3+strlen("idTag")+j];
  8003. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8004. j++;
  8005. }
  8006. sstr[j] = '\0';
  8007. strcpy(idTagstr, sstr);
  8008. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8009. //Search "expiryDate"
  8010. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8011. loc = strstr(CardList[c], "expiryDate");
  8012. j = 0;
  8013. if(loc != NULL)
  8014. {
  8015. while (loc[3+strlen("expiryDate")+j] != '\"')
  8016. {
  8017. sstr[j] = loc[3+strlen("expiryDate")+j];
  8018. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8019. j++;
  8020. }
  8021. sstr[j] = '\0';
  8022. strcpy(expiryDate, sstr);
  8023. }
  8024. else
  8025. {
  8026. strcpy(expiryDate, "");
  8027. }
  8028. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8029. //Search "parentIdTag"
  8030. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8031. loc = strstr(CardList[c], "parentIdTag");
  8032. j = 0;
  8033. if(loc != NULL)
  8034. {
  8035. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8036. {
  8037. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8038. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8039. j++;
  8040. }
  8041. sstr[j] = '\0';
  8042. strcpy(parentIdTag, sstr);
  8043. }
  8044. else
  8045. {
  8046. strcpy(parentIdTag, "");
  8047. }
  8048. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8049. //Search "status"
  8050. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8051. loc = strstr(CardList[c], "status");
  8052. j = 0;
  8053. while (loc[3+strlen("status")+j] != '\"')
  8054. {
  8055. sstr[j] = loc[3+strlen("status")+j];
  8056. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8057. j++;
  8058. }
  8059. sstr[j] = '\0';
  8060. strcpy(idTagstatus, sstr);
  8061. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8062. OCPP_getIdTag(idTagstr);
  8063. //OCPP_getIdTag("test"); For Test
  8064. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8065. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8066. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8067. {
  8068. //Local list full update
  8069. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8070. // update list
  8071. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8072. //DEBUG_INFO("Local list full update. 1\n");
  8073. //OCPP_get_TableAuthlocalAllData();
  8074. //DEBUG_INFO("Local list full update. 2\n");
  8075. }
  8076. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8077. {
  8078. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8079. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8080. }
  8081. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8082. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8083. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8084. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8085. c++;
  8086. }
  8087. }
  8088. else
  8089. {
  8090. //Check UpdateType
  8091. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8092. {
  8093. //Local list full update
  8094. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8095. OCPP_cleanLocalList();
  8096. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8097. goto end;
  8098. }
  8099. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8100. {
  8101. //Local list different update
  8102. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8103. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8104. goto end;
  8105. }
  8106. }
  8107. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8108. end:
  8109. sendSendLocalListConfirmation(uuid, comfirmstr);
  8110. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8111. return result;
  8112. }
  8113. #define MAX 200
  8114. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8115. {
  8116. mtrace();
  8117. int result = FAIL;
  8118. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8119. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8120. char chargingProfilePurposeStr[30]={0};
  8121. char chargingProfileKindStr[16]={0};
  8122. char recurrencyKindStr[10]={0};
  8123. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8124. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8125. int chargingSchedulePeriodCount = 0;
  8126. //int updateflag = FALSE;
  8127. char comfirmstr[20]={0};
  8128. int meet= FALSE;
  8129. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8130. int c = 0;
  8131. char *loc;
  8132. FILE *fptr1;//, *fptr2;
  8133. //int lno=0;//, linectr = 0;
  8134. //int modifyflag = FALSE;
  8135. char filename[MAX]={0};
  8136. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8137. //int resultRename=0;
  8138. char rmFileCmd[50]={0};
  8139. char tempchargingProfilePurposeStr[30]={0};
  8140. char word[1600]={0};
  8141. int n_chargingProfile = 0;
  8142. //[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}}}]
  8143. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8144. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8145. //Filter string space
  8146. strcpy(sstrtemp, stringtrimspace(payload));
  8147. //*********************connectorId***************************/
  8148. loc = strstr(sstrtemp, "connectorId");
  8149. c = 0;
  8150. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8151. while (loc[strlen("connectorId")+2+c] != ',')
  8152. {
  8153. sstr[c] = loc[strlen("connectorId")+2+c];
  8154. c++;
  8155. }
  8156. sstr[c] = '\0';
  8157. connectorIdInt = atoi(sstr);
  8158. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8159. {
  8160. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8161. }
  8162. else
  8163. {
  8164. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8165. }
  8166. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8167. //*********************chargingProfileId***************************/
  8168. loc = strstr(sstrtemp, "chargingProfileId");
  8169. c = 0;
  8170. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8171. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8172. {
  8173. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8174. c++;
  8175. }
  8176. sstr[c] = '\0';
  8177. chargingProfileIdInt = atoi(sstr);
  8178. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8179. {
  8180. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8181. }
  8182. else
  8183. {
  8184. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8185. }
  8186. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8187. //*********************transactionId***************************/
  8188. loc = strstr(sstrtemp, "transactionId");
  8189. if(loc != NULL)
  8190. {
  8191. c = 0;
  8192. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8193. while (loc[strlen("transactionId")+2+c] != ',')
  8194. {
  8195. sstr[c] = loc[strlen("transactionId")+2+c];
  8196. c++;
  8197. }
  8198. sstr[c] = '\0';
  8199. transactionIdInt = atoi(sstr);
  8200. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8201. {
  8202. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8203. }
  8204. else
  8205. {
  8206. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8207. }
  8208. }
  8209. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8210. //*********************stackLevel***************************/
  8211. loc = strstr(sstrtemp, "stackLevel");
  8212. c = 0;
  8213. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8214. while (loc[strlen("stackLevel")+2+c] != ',')
  8215. {
  8216. sstr[c] = loc[strlen("stackLevel")+2+c];
  8217. c++;
  8218. }
  8219. sstr[c] = '\0';
  8220. stackLevelInt = atoi(sstr);
  8221. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8222. {
  8223. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8224. }
  8225. else
  8226. {
  8227. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8228. }
  8229. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8230. //*********************chargingProfilePurpose***************************/
  8231. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8232. c = 0;
  8233. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8234. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8235. {
  8236. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8237. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8238. c++;
  8239. }
  8240. sstr[c] = '\0';
  8241. strcpy(chargingProfilePurposeStr,sstr);
  8242. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8243. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8244. {
  8245. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8246. }
  8247. else
  8248. {
  8249. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8250. }
  8251. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8252. //*********************chargingProfileKind***************************/
  8253. loc = strstr(sstrtemp, "chargingProfileKind");
  8254. c = 0;
  8255. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8256. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8257. {
  8258. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8259. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8260. c++;
  8261. }
  8262. sstr[c] = '\0';
  8263. strcpy(chargingProfileKindStr,sstr);
  8264. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8265. {
  8266. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8267. }
  8268. else
  8269. {
  8270. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8271. }
  8272. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8273. //*********************recurrencyKind***************************/
  8274. loc = strstr(sstrtemp, "recurrencyKind");
  8275. if(loc != NULL)
  8276. {
  8277. c = 0;
  8278. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8279. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8280. {
  8281. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8282. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8283. c++;
  8284. }
  8285. sstr[c] = '\0';
  8286. strcpy(recurrencyKindStr,sstr);
  8287. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8288. {
  8289. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8290. }
  8291. else
  8292. {
  8293. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8294. }
  8295. }
  8296. else
  8297. {
  8298. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8299. {
  8300. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8301. }
  8302. else
  8303. {
  8304. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8305. }
  8306. }
  8307. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8308. //*********************validFrom***************************/
  8309. loc = strstr(sstrtemp, "validFrom");
  8310. if(loc != NULL)
  8311. {
  8312. c = 0;
  8313. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8314. while (loc[3+strlen("validFrom")+c] != '\"')
  8315. {
  8316. sstr[c] = loc[3+strlen("validFrom")+c];
  8317. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8318. c++;
  8319. }
  8320. sstr[c] = '\0';
  8321. strcpy(validFromStr,sstr);
  8322. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8323. {
  8324. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8325. }
  8326. else
  8327. {
  8328. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8329. }
  8330. }
  8331. else
  8332. {
  8333. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8334. {
  8335. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8336. }
  8337. else
  8338. {
  8339. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8340. }
  8341. }
  8342. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8343. //*********************validTo***************************/
  8344. loc = strstr(sstrtemp, "validTo");
  8345. if(loc != NULL)
  8346. {
  8347. c = 0;
  8348. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8349. while (loc[3+strlen("validTo")+c] != '\"')
  8350. {
  8351. sstr[c] = loc[3+strlen("validTo")+c];
  8352. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8353. c++;
  8354. }
  8355. sstr[c] = '\0';
  8356. strcpy(validToStr,sstr);
  8357. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8358. {
  8359. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8360. }
  8361. else
  8362. {
  8363. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8364. }
  8365. }
  8366. else
  8367. {
  8368. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8369. {
  8370. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8371. }
  8372. else
  8373. {
  8374. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8375. }
  8376. }
  8377. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8378. //*********************duration***************************/
  8379. loc = strstr(sstrtemp, "duration");
  8380. if(loc != NULL)
  8381. {
  8382. c = 0;
  8383. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8384. while (loc[strlen("duration")+2+c] != ',')
  8385. {
  8386. sstr[c] = loc[strlen("duration")+2+c];
  8387. c++;
  8388. }
  8389. sstr[c] = '\0';
  8390. durationInt = atoi(sstr);
  8391. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8392. {
  8393. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8394. }
  8395. else
  8396. {
  8397. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8398. }
  8399. }
  8400. else
  8401. {
  8402. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8403. {
  8404. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8405. }
  8406. else
  8407. {
  8408. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8409. }
  8410. }
  8411. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8412. //*********************startSchedule***************************/
  8413. loc = strstr(sstrtemp, "startSchedule");
  8414. if(loc != NULL)
  8415. {
  8416. c = 0;
  8417. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8418. while (loc[3+strlen("startSchedule")+c] != '\"')
  8419. {
  8420. sstr[c] = loc[3+strlen("startSchedule")+c];
  8421. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8422. c++;
  8423. }
  8424. sstr[c] = '\0';
  8425. strcpy(startScheduleStr,sstr);
  8426. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8427. {
  8428. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8429. }
  8430. else
  8431. {
  8432. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8433. }
  8434. }
  8435. else
  8436. {
  8437. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8438. {
  8439. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8440. }
  8441. else
  8442. {
  8443. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8444. }
  8445. }
  8446. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8447. //*********************chargingRateUnit***************************/
  8448. loc = strstr(sstrtemp, "chargingRateUnit");
  8449. if(loc != NULL)
  8450. {
  8451. c = 0;
  8452. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8453. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8454. {
  8455. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8456. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8457. c++;
  8458. }
  8459. sstr[c] = '\0';
  8460. strcpy(chargingRateUnitStr,sstr);
  8461. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8462. {
  8463. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8464. }
  8465. else
  8466. {
  8467. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8468. }
  8469. }
  8470. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8471. //****************chargingSchedulePeriod count start*******************/
  8472. int what_len = strlen("startPeriod");
  8473. char tempChargingProfile[1600]={0};
  8474. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8475. char *where = tempChargingProfile;
  8476. if (what_len)
  8477. {
  8478. while ((where = strstr(where, "startPeriod"))) {
  8479. where += what_len;
  8480. chargingSchedulePeriodCount++;
  8481. }
  8482. }
  8483. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8484. {
  8485. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8486. goto end;
  8487. }
  8488. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8489. //where = payload;
  8490. int templength = 0;
  8491. //int searchstart = 0;
  8492. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8493. {
  8494. //****************startPeriod*******************/
  8495. c=0;
  8496. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8497. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8498. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8499. {
  8500. sstr[c] = loc[strlen("startPeriod")+2+c];
  8501. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8502. c++;
  8503. }
  8504. sstr[c] = '\0';
  8505. startPeriodInt[periodNums] = atoi(sstr);
  8506. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8507. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8508. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8509. {
  8510. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8511. }
  8512. else
  8513. {
  8514. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8515. }
  8516. templength = strlen("startPeriod")+2+c;
  8517. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8518. //****************limit*******************/
  8519. c=0;
  8520. loc = strstr(tempChargingProfile + templength, "limit");
  8521. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8522. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8523. {
  8524. sstr[c] = loc[strlen("limit")+2+c];
  8525. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8526. c++;
  8527. }
  8528. sstr[c] = '\0';
  8529. limitflaot[periodNums] = atof(sstr);
  8530. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8531. {
  8532. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8533. }
  8534. else
  8535. {
  8536. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8537. }
  8538. templength = templength + strlen("limit")+2+c;
  8539. //****************numberPhases*******************/
  8540. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8541. if(loc != NULL)
  8542. {
  8543. c=0;
  8544. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8545. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8546. {
  8547. sstr[c] = loc[strlen("numberPhases")+2+c];
  8548. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8549. c++;
  8550. }
  8551. sstr[c] = '\0';
  8552. numberPhasesInt[periodNums] = atoi(sstr);
  8553. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8554. {
  8555. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8556. }
  8557. else
  8558. {
  8559. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8560. }
  8561. templength = templength + strlen("numberPhases")+2+c;
  8562. }
  8563. //where = loc;
  8564. }
  8565. //****************chargingSchedulePeriod count end*******************/
  8566. //*********************minChargingRate***************************/
  8567. loc = strstr(sstrtemp, "minChargingRate");
  8568. if(loc != NULL)
  8569. {
  8570. c = 0;
  8571. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8572. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8573. {
  8574. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8575. c++;
  8576. }
  8577. sstr[c] = '\0';
  8578. minChargingRateFloat = atof(sstr);
  8579. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8580. {
  8581. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8582. }
  8583. else
  8584. {
  8585. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8586. }
  8587. }
  8588. else
  8589. {
  8590. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8591. {
  8592. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8593. }
  8594. else
  8595. {
  8596. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8597. }
  8598. }
  8599. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8600. {
  8601. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8602. if(connectorIdInt != 0)
  8603. {
  8604. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8605. goto end;
  8606. }
  8607. strcpy(filename, ChargePointMaxProfile_JSON );
  8608. fptr1 = fopen(filename, "r");
  8609. if (!fptr1)
  8610. {
  8611. //file not exist
  8612. DEBUG_INFO("Unable to open the input file!!\n");
  8613. fptr1 = fopen(filename, "w+");
  8614. }
  8615. else
  8616. {
  8617. //Check Charging Profile Count
  8618. while(fscanf(fptr1, "%s", word) != EOF)
  8619. {
  8620. //DEBUG_INFO("word=%s\n",word);
  8621. if(strstr(word, "chargingProfileId")!= NULL)
  8622. {
  8623. //DEBUG_INFO("test chargingProfileId \n");
  8624. n_chargingProfile = n_chargingProfile + 1;
  8625. //DEBUG_INFO("chargingProfileId Found\n");
  8626. }
  8627. }
  8628. }
  8629. fclose(fptr1);
  8630. }
  8631. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8632. {
  8633. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8634. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8635. {
  8636. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8637. goto end;
  8638. }
  8639. memset(filename, 0, ARRAY_SIZE(filename));
  8640. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8641. fptr1 = fopen(filename, "r");
  8642. if (!fptr1)
  8643. {
  8644. //file not exist
  8645. //DEBUG_INFO("Unable to open the input file!!\n");
  8646. fptr1 = fopen(filename, "w+");
  8647. }
  8648. else
  8649. {
  8650. //Check Charging Profile Count
  8651. while(fscanf(fptr1, "%s", word) != EOF)
  8652. {
  8653. //DEBUG_INFO("word=%s\n",word);
  8654. if(strstr(word, "chargingProfileId")!= NULL)
  8655. {
  8656. //DEBUG_INFO("test chargingProfileId \n");
  8657. n_chargingProfile = n_chargingProfile + 1;
  8658. //DEBUG_INFO("chargingProfileId Found\n");
  8659. }
  8660. }
  8661. }
  8662. fclose(fptr1);
  8663. }
  8664. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8665. {
  8666. //printf("set chargingProfile 1-4\n");
  8667. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8668. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8669. if(connectorIdInt == 0)
  8670. {
  8671. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8672. goto end;
  8673. }
  8674. int tempIndex = 0;
  8675. //check Transaction active
  8676. if(gunType[connectorIdInt -1] == 'J')
  8677. {
  8678. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8679. {
  8680. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8681. }
  8682. else
  8683. {
  8684. tempIndex = connectorIdInt -1;
  8685. }
  8686. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8687. {
  8688. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8689. {
  8690. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8691. {
  8692. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8693. {
  8694. meet = TRUE;
  8695. break;
  8696. }
  8697. }
  8698. }
  8699. }
  8700. }
  8701. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8702. {
  8703. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8704. {
  8705. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8706. }
  8707. else
  8708. {
  8709. tempIndex = connectorIdInt -1;
  8710. }
  8711. for (int index = 0; index < CCS_QUANTITY; index++)
  8712. {
  8713. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8714. {
  8715. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8716. {
  8717. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8718. {
  8719. meet = TRUE;
  8720. break;
  8721. }
  8722. }
  8723. }
  8724. }
  8725. }
  8726. else if(gunType[connectorIdInt -1] == 'G')
  8727. {
  8728. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8729. {
  8730. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8731. }
  8732. else
  8733. {
  8734. tempIndex = connectorIdInt -1;
  8735. }
  8736. for (int index = 0; index < GB_QUANTITY; index++)
  8737. {
  8738. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8739. {
  8740. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8741. {
  8742. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8743. {
  8744. meet = TRUE;
  8745. break;
  8746. }
  8747. }
  8748. }
  8749. }
  8750. }
  8751. else
  8752. {
  8753. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8754. {
  8755. tempIndex = 2;
  8756. }
  8757. else
  8758. {
  8759. tempIndex = (connectorIdInt -1);
  8760. }
  8761. for (int index = 0; index < AC_QUANTITY; index++)
  8762. {
  8763. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8764. {
  8765. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8766. {
  8767. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8768. {
  8769. meet = TRUE;
  8770. break;
  8771. }
  8772. }
  8773. }
  8774. }
  8775. }
  8776. //check Transaction active
  8777. if(meet == FALSE)
  8778. {
  8779. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8780. goto end;
  8781. }
  8782. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8783. {
  8784. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8785. goto end;
  8786. }
  8787. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8788. fptr1 = fopen(filename, "r");
  8789. if (!fptr1)
  8790. {
  8791. //file not exist
  8792. DEBUG_INFO("Unable to open the input file!!\n");
  8793. fptr1 = fopen(filename, "w+");
  8794. }
  8795. else
  8796. {
  8797. //Check Charging Profile Count
  8798. while(fscanf(fptr1, "%s", word) != EOF)
  8799. {
  8800. //DEBUG_INFO("word=%s\n",word);
  8801. if(strstr(word, "chargingProfileId")!= NULL)
  8802. {
  8803. //DEBUG_INFO("test chargingProfileId \n");
  8804. n_chargingProfile = n_chargingProfile + 1;
  8805. //DEBUG_INFO("chargingProfileId Found\n");
  8806. }
  8807. }
  8808. }
  8809. fclose(fptr1);
  8810. }
  8811. // Check ChargeProfileMaxStackLevel
  8812. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8813. {
  8814. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8815. goto end;
  8816. }
  8817. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8818. {
  8819. int i = 0;
  8820. char fnametemp[200]={0};
  8821. n_chargingProfile = 0;
  8822. //Check ChargePointMaxProfile.json exit
  8823. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8824. {
  8825. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8826. //Check Charging Profile Count
  8827. while(fscanf(fptr1, "%s", word) != EOF)
  8828. {
  8829. //DEBUG_INFO("word=%s\n",word);
  8830. if(strstr(word, "chargingProfileId")!= NULL)
  8831. {
  8832. //DEBUG_INFO("test chargingProfileId \n");
  8833. n_chargingProfile = n_chargingProfile + 1;
  8834. i = i + 1;
  8835. //DEBUG_INFO("chargingProfileId Found\n");
  8836. }
  8837. memset(word, 0, ARRAY_SIZE(word));
  8838. }
  8839. fclose(fptr1);
  8840. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8841. }
  8842. //Check TxDefaultProfile_0.json exit
  8843. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8844. {
  8845. i = 0;
  8846. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8847. //Check Charging Profile Count
  8848. while(fscanf(fptr1, "%s", word) != EOF)
  8849. {
  8850. //DEBUG_INFO("word=%s\n",word);
  8851. if(strstr(word, "chargingProfileId")!= NULL)
  8852. {
  8853. //DEBUG_INFO("test chargingProfileId \n");
  8854. n_chargingProfile = n_chargingProfile + 1;
  8855. i = i + 1;
  8856. //DEBUG_INFO("chargingProfileId Found\n");
  8857. }
  8858. memset(word, 0, ARRAY_SIZE(word));
  8859. }
  8860. fclose(fptr1);
  8861. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8862. }
  8863. //Check TxDefaultProfile_%d.json
  8864. for(int j=1; j <= gunTotalNumber; j++)
  8865. {
  8866. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8867. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8868. if((access(fnametemp,F_OK))!=-1)
  8869. {
  8870. i = 0;
  8871. fptr1 = fopen(fnametemp, "r");
  8872. //Check Charging Profile Count
  8873. while(fscanf(fptr1, "%s", word) != EOF)
  8874. {
  8875. //DEBUG_INFO("word=%s\n",word);
  8876. if(strstr(word, "chargingProfileId")!= NULL)
  8877. {
  8878. //DEBUG_INFO("test chargingProfileId \n");
  8879. n_chargingProfile = n_chargingProfile + 1;
  8880. i = i + 1;
  8881. //DEBUG_INFO("chargingProfileId Found\n");
  8882. }
  8883. memset(word, 0, ARRAY_SIZE(word));
  8884. }
  8885. fclose(fptr1);
  8886. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8887. }
  8888. }
  8889. //Check TxProfile_%d.json
  8890. for(int j=1; j <= gunTotalNumber; j++)
  8891. {
  8892. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8893. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8894. if((access(fnametemp,F_OK))!=-1)
  8895. {
  8896. i = 0;
  8897. fptr1 = fopen(fnametemp, "r");
  8898. //Check Charging Profile Count
  8899. while(fscanf(fptr1, "%s", word) != EOF)
  8900. {
  8901. //DEBUG_INFO("word=%s\n",word);
  8902. if(strstr(word, "chargingProfileId")!= NULL)
  8903. {
  8904. //DEBUG_INFO("test chargingProfileId \n");
  8905. n_chargingProfile = n_chargingProfile + 1;
  8906. i = i + 1;
  8907. //DEBUG_INFO("chargingProfileId Found\n");
  8908. }
  8909. memset(word, 0, ARRAY_SIZE(word));
  8910. }
  8911. fclose(fptr1);
  8912. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8913. }
  8914. }
  8915. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8916. {
  8917. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8918. goto end;
  8919. }
  8920. }
  8921. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8922. //**********************************Write to File********************************************************/
  8923. FILE *infile;
  8924. FILE *outfile;
  8925. // open file for writing
  8926. infile = fopen (filename, "r");
  8927. outfile = fopen (tempfile, "w");
  8928. int d =0;
  8929. d = fgetc(infile);
  8930. //DEBUG_INFO("d:%d\n",d);
  8931. rewind(infile);
  8932. //*璉 瘚 辣蝏     1嚗   0 */
  8933. if(d == EOF)
  8934. {
  8935. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8936. fprintf(outfile,"%s\n",payload);
  8937. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8938. fclose(infile);
  8939. fclose(outfile);
  8940. sprintf(rmFileCmd,"rm -f %s",filename);
  8941. system(rmFileCmd);
  8942. rename(tempfile, filename);
  8943. sleep(1);
  8944. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8945. //system(rmFileCmd);
  8946. }
  8947. else
  8948. {
  8949. char buf[1000]={0};
  8950. int ChargingProfileAdded = FALSE;
  8951. while (fgets(buf, sizeof(buf), infile) != NULL)
  8952. {
  8953. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8954. //*************************tempconnectorIdInt*********************************/
  8955. loc = strstr(buf, "connectorId");
  8956. c = 0;
  8957. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8958. while (loc[strlen("connectorId")+2+c] != ',')
  8959. {
  8960. sstr[c] = loc[strlen("connectorId")+2+c];
  8961. c++;
  8962. }
  8963. sstr[c] = '\0';
  8964. tempconnectorIdInt = atoi(sstr);
  8965. //*************************tempchargingProfileIdInt*********************************/
  8966. loc = strstr(buf, "chargingProfileId");
  8967. c = 0;
  8968. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8969. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8970. {
  8971. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8972. c++;
  8973. }
  8974. sstr[c] = '\0';
  8975. tempchargingProfileIdInt = atoi(sstr);
  8976. //*************************tempstackLevelInt*********************************/
  8977. loc = strstr(buf, "stackLevel");
  8978. c = 0;
  8979. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8980. while (loc[strlen("stackLevel")+2+c] != ',')
  8981. {
  8982. sstr[c] = loc[strlen("stackLevel")+2+c];
  8983. c++;
  8984. }
  8985. sstr[c] = '\0';
  8986. tempstackLevelInt = atoi(sstr);
  8987. //*************************tempchargingProfilePurposeStr*********************************/
  8988. loc = strstr(payload, "chargingProfilePurpose");
  8989. c = 0;
  8990. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8991. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8992. {
  8993. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8994. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8995. c++;
  8996. }
  8997. sstr[c] = '\0';
  8998. strcpy(tempchargingProfilePurposeStr,sstr);
  8999. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9000. {
  9001. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9002. {
  9003. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9004. if(ChargingProfileAdded == FALSE)
  9005. {
  9006. fprintf(outfile,"%s\n",payload);
  9007. ChargingProfileAdded = TRUE;
  9008. }
  9009. }
  9010. else
  9011. {
  9012. if(tempstackLevelInt < stackLevelInt)
  9013. {
  9014. if(ChargingProfileAdded == FALSE)
  9015. {
  9016. fprintf(outfile,"%s\n",payload);
  9017. ChargingProfileAdded = TRUE;
  9018. fprintf(outfile,"%s\n",buf);
  9019. }
  9020. else
  9021. {
  9022. fprintf(outfile,"%s\n",buf);
  9023. }
  9024. }
  9025. else
  9026. {
  9027. if(ChargingProfileAdded == FALSE)
  9028. {
  9029. fprintf(outfile,"%s\n",buf);
  9030. fprintf(outfile,"%s\n",payload);
  9031. ChargingProfileAdded = TRUE;
  9032. }
  9033. else
  9034. {
  9035. fprintf(outfile,"%s\n",buf);
  9036. }
  9037. }
  9038. }
  9039. }
  9040. else
  9041. {
  9042. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9043. {
  9044. if(ChargingProfileAdded == FALSE)
  9045. {
  9046. fprintf(outfile,"%s\n",payload);
  9047. ChargingProfileAdded = TRUE;
  9048. fprintf(outfile,"%s\n",buf);
  9049. }
  9050. else
  9051. {
  9052. fprintf(outfile,"%s\n",buf);
  9053. }
  9054. }
  9055. else if(tempstackLevelInt < stackLevelInt)
  9056. {
  9057. if(ChargingProfileAdded == FALSE)
  9058. {
  9059. fprintf(outfile,"%s\n",payload);
  9060. ChargingProfileAdded = TRUE;
  9061. fprintf(outfile,"%s\n",buf);
  9062. }
  9063. else
  9064. {
  9065. fprintf(outfile,"%s\n",buf);
  9066. }
  9067. }
  9068. else
  9069. {
  9070. if(ChargingProfileAdded == FALSE)
  9071. {
  9072. fprintf(outfile,"%s\n",buf);
  9073. fprintf(outfile,"%s\n",payload);
  9074. ChargingProfileAdded = TRUE;
  9075. }
  9076. else
  9077. {
  9078. fprintf(outfile,"%s\n",buf);
  9079. }
  9080. }
  9081. }
  9082. } // end of while loop
  9083. fclose(infile);
  9084. fclose(outfile);
  9085. sprintf(rmFileCmd,"rm -f %s",filename);
  9086. system(rmFileCmd);
  9087. rename(tempfile, filename);
  9088. sleep(1);
  9089. result = TRUE;
  9090. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9091. }
  9092. end:
  9093. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9094. return result;
  9095. return result;
  9096. }
  9097. int handleTriggerMessageRequest(char *uuid, char *payload)
  9098. {
  9099. mtrace();
  9100. int result = FAIL;
  9101. int connectorIdIsNULL = FALSE;
  9102. int connectorIdInt =0;
  9103. char sstr[40]={0},sstrtemp[100]={ 0 };
  9104. char requestedMessagestr[40]={0};
  9105. char comfirmstr[20]={0};
  9106. int c = 0;
  9107. char *loc;
  9108. DEBUG_INFO("handleTriggerMessageRequest\n");
  9109. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9110. strcpy(sstrtemp, stringtrimspace(payload));
  9111. c = 0;
  9112. loc = strstr(sstrtemp, "requestedMessage");
  9113. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9114. {
  9115. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9116. c++;
  9117. }
  9118. sstr[c] = '\0';
  9119. strcpy(requestedMessagestr, sstr);
  9120. c = 0;
  9121. loc = strstr(sstrtemp, "connectorId");
  9122. if(loc == NULL)
  9123. {
  9124. connectorIdIsNULL = TRUE;
  9125. }
  9126. else
  9127. {
  9128. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9129. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9130. {
  9131. sstr[c] = loc[strlen("connectorId")+2+c];
  9132. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9133. c++;
  9134. }
  9135. sstr[c] = '\0';
  9136. connectorIdInt = atoi(sstr);
  9137. }
  9138. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  9139. {
  9140. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9141. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9142. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9143. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9144. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9145. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9146. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9147. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9148. {
  9149. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9150. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9151. return TRUE;
  9152. }
  9153. else
  9154. {
  9155. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9156. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9157. }
  9158. }
  9159. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9160. {
  9161. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9162. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9163. return TRUE;
  9164. }
  9165. //==========================
  9166. // Trigger message
  9167. //==========================
  9168. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9169. {
  9170. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9171. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9172. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9173. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9174. {
  9175. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9176. }
  9177. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9178. }
  9179. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9180. {
  9181. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9182. }
  9183. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9184. {
  9185. //sendBootNotificationRequest();
  9186. server_sign = FALSE;
  9187. }
  9188. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9189. {
  9190. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9191. }
  9192. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9193. {
  9194. if(connectorIdIsNULL == FALSE)
  9195. {
  9196. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9197. {
  9198. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9199. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  9200. }
  9201. }
  9202. else
  9203. {
  9204. for(int idx=0;idx< gunTotalNumber;idx++)
  9205. {
  9206. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9207. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  9208. }
  9209. }
  9210. }
  9211. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9212. {
  9213. if(connectorIdIsNULL == FALSE)
  9214. {
  9215. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9216. {
  9217. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9218. }
  9219. }
  9220. else
  9221. {
  9222. for(int idx=0;idx< gunTotalNumber;idx++)
  9223. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9224. }
  9225. }
  9226. return result;
  9227. }
  9228. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9229. {
  9230. mtrace();
  9231. int result = FAIL;
  9232. char sstr[6]={0},sstrtemp[50]={ 0 };
  9233. int connectorIdInt =0;
  9234. char comfirmstr[20]={0};
  9235. int c = 0;
  9236. int tempIndex = 0;
  9237. char *loc;
  9238. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9239. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9240. strcpy(sstrtemp, stringtrimspace(payload));
  9241. c = 0;
  9242. loc = strstr(sstrtemp, "connectorId");
  9243. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9244. while (loc[strlen("connectorId")+2+c] != '}')
  9245. {
  9246. sstr[c] = loc[strlen("connectorId")+2+c];
  9247. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9248. c++;
  9249. }
  9250. sstr[c] = '\0';
  9251. connectorIdInt = atoi(sstr);
  9252. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  9253. if(gunTotalNumber == 0)
  9254. {
  9255. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9256. goto end;
  9257. }
  9258. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9259. {
  9260. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9261. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9262. goto end;
  9263. }
  9264. else
  9265. {
  9266. //check Transaction active
  9267. if(gunType[connectorIdInt-1] == 'J')
  9268. {
  9269. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9270. {
  9271. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9272. }
  9273. else
  9274. {
  9275. tempIndex = connectorIdInt -1;
  9276. }
  9277. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9278. {
  9279. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9280. {
  9281. //stop Transaction
  9282. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9283. }
  9284. }
  9285. }
  9286. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9287. {
  9288. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9289. {
  9290. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9291. }
  9292. else
  9293. {
  9294. tempIndex = connectorIdInt -1;
  9295. }
  9296. for (int index = 0; index < CCS_QUANTITY; index++)
  9297. {
  9298. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9299. {
  9300. //stop Transaction
  9301. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9302. }
  9303. }
  9304. }
  9305. else if(gunType[connectorIdInt-1] == 'G')
  9306. {
  9307. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9308. {
  9309. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9310. }
  9311. else
  9312. {
  9313. tempIndex = connectorIdInt -1;
  9314. }
  9315. for (int index = 0; index < GB_QUANTITY; index++)
  9316. {
  9317. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9318. {
  9319. //stop Transaction
  9320. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9321. }
  9322. }
  9323. }
  9324. else
  9325. {
  9326. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9327. {
  9328. tempIndex = 2;
  9329. }
  9330. else
  9331. {
  9332. tempIndex = connectorIdInt-1;
  9333. }
  9334. for (int index = 0; index < AC_QUANTITY; index++)
  9335. {
  9336. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9337. {
  9338. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9339. }
  9340. }
  9341. }
  9342. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9343. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9344. result = TRUE;
  9345. return result;
  9346. }
  9347. end:
  9348. //json_object_put(obj); --- remove temporally
  9349. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9350. return result;
  9351. }
  9352. static char UpdateFirmwarepayloadData[300]={0};
  9353. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9354. {
  9355. mtrace();
  9356. int result = FAIL;
  9357. pthread_t t;
  9358. sendUpdateFirmwareConfirmation(uuid);
  9359. memset(UpdateFirmwarepayloadData, 0, 300);
  9360. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9361. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9362. ////pthread_join(t, NULL); //
  9363. //pthread_detach(t);
  9364. //sendUpdateFirmwareConfirmation(uuid);
  9365. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9366. return result;
  9367. }
  9368. void *UpdateFirmwareProcess(void *data)
  9369. {
  9370. pthread_detach(pthread_self());
  9371. mtrace();
  9372. int retriesInt =0, retryIntervalInt=0;
  9373. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9374. int port=0;
  9375. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9376. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  9377. //char comfirmstr[20];
  9378. int isSuccess = 0;
  9379. char ftpbuf[200];
  9380. char temp[100];
  9381. char * pch;
  9382. int retriesISNULL=FALSE;
  9383. int retryInterval=FALSE;
  9384. int c = 0;
  9385. //int i = 0;
  9386. char *loc;
  9387. char sstr[300]={ 0 };
  9388. char str[300]={ 0 };
  9389. //char *str = (char*) data; // ? ?頛詨鞈 ?
  9390. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9391. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  9392. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  9393. //***************location **************/
  9394. loc = strstr(str, "location");
  9395. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9396. c = 0;
  9397. while (loc[3+strlen("location")+c] != '\"')
  9398. {
  9399. sstr[c] = loc[3+strlen("location")+c];
  9400. c++;
  9401. }
  9402. sstr[c] = '\0';
  9403. strcpy(locationstr, sstr);
  9404. //***************retries**************/
  9405. c = 0;
  9406. loc = strstr(str, "retries");
  9407. if(loc == NULL)
  9408. {
  9409. retriesISNULL=TRUE;
  9410. }
  9411. else
  9412. {
  9413. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9414. while (loc[strlen("retries")+2+c] != ',')
  9415. {
  9416. sstr[c] = loc[strlen("retries")+2+c];
  9417. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9418. c++;
  9419. }
  9420. sstr[c] = '\0';
  9421. }
  9422. if(retriesISNULL == FALSE)
  9423. {
  9424. retriesInt = atoi(sstr);
  9425. }
  9426. //***************retrieveDate **************/
  9427. loc = strstr(str, "retrieveDate");
  9428. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9429. c = 0;
  9430. while (loc[3+strlen("retrieveDate")+c] != '\"')
  9431. {
  9432. sstr[c] = loc[3+strlen("retrieveDate")+c];
  9433. c++;
  9434. }
  9435. sstr[c] = '\0';
  9436. strcpy(retrieveDatestr, sstr);
  9437. //***************retryInterval **************/
  9438. c = 0;
  9439. loc = strstr(str, "retryInterval");
  9440. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9441. if(loc == NULL)
  9442. {
  9443. retryInterval=TRUE;
  9444. }
  9445. else
  9446. {
  9447. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  9448. {
  9449. sstr[c] = loc[strlen("retryInterval")+2+c];
  9450. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  9451. c++;
  9452. }
  9453. sstr[c] = '\0';
  9454. }
  9455. if(retryInterval==FALSE)
  9456. {
  9457. retryIntervalInt = atoi(sstr);
  9458. }
  9459. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9460. memset(path, 0, ARRAY_SIZE(path));
  9461. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9462. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9463. if(strncmp(locationstr,"http", 4) == 0)
  9464. {
  9465. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  9466. protocol, host, path);
  9467. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9468. // protocol, user, password, host, path);
  9469. sprintf(ftppath,"/%s", path);
  9470. //DEBUG_INFO("protocol =%s\n",protocol);
  9471. //DEBUG_INFO("host =%s\n",host);
  9472. //DEBUG_INFO("path =%s\n",path);
  9473. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9474. int ftppathlen=strlen(ftppath);
  9475. int i=1;
  9476. char filenametemp[50];
  9477. while(i < ftppathlen)
  9478. {
  9479. int len=ftppathlen-i;
  9480. if(ftppath[len]== 47) // '/' ascll code: 47
  9481. {
  9482. DEBUG_INFO("compare '/' all right\n");
  9483. break;
  9484. }
  9485. i=i+1;
  9486. }
  9487. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9488. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9489. filenametemp[i+1] = 0;
  9490. do
  9491. {
  9492. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9493. sleep(retryIntervalInt);
  9494. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9495. if(!isSuccess)
  9496. {
  9497. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9498. }
  9499. else
  9500. {
  9501. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9502. }
  9503. }
  9504. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9505. {
  9506. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9507. memset(temp, 0, ARRAY_SIZE(temp));
  9508. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9509. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9510. int ftppathlen=strlen(ftpbuf);
  9511. int i=1;
  9512. char filenametemp[50];
  9513. while(i < ftppathlen)
  9514. {
  9515. int len=ftppathlen-i;
  9516. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9517. {
  9518. DEBUG_INFO(" compare '/' all right\n");
  9519. break;
  9520. }
  9521. i=i+1;
  9522. }
  9523. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9524. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9525. filenametemp[i+1] = 0;
  9526. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9527. pch=strchr(temp,'@');
  9528. if(pch==NULL)
  9529. {
  9530. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9531. protocol, host, &port, path);
  9532. strcpy(user,"anonymous");
  9533. strcpy(password,"");
  9534. }
  9535. else
  9536. {
  9537. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9538. protocol, user, password, host, &port, path);
  9539. }
  9540. sscanf(host,"%[^/]%s",host1, path1);
  9541. sprintf(ftppath,"%s", path1);
  9542. //DEBUG_INFO("protocol =%s\n",protocol);
  9543. //DEBUG_INFO("user =%s\n",user);
  9544. //DEBUG_INFO("password =%s\n",password);
  9545. //DEBUG_INFO("host1 =%s\n",host1);
  9546. //DEBUG_INFO("port =%d\n",port);
  9547. //DEBUG_INFO("path1 =%s\n",path1);
  9548. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9549. //ftpFile(host, user, password, port, ftppath, fname);
  9550. //download firmware pthred
  9551. if(port == 0)
  9552. {
  9553. port = 21;
  9554. }
  9555. do
  9556. {
  9557. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9558. sleep(retryIntervalInt);
  9559. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9560. if(!isSuccess)
  9561. {
  9562. //BulldogUtil.sleepMs(interval*1000);
  9563. DEBUG_INFO("Update firmware request and download file fail.\n");
  9564. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9565. }
  9566. else
  9567. {
  9568. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9569. }
  9570. }
  9571. else
  9572. {
  9573. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9574. }
  9575. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9576. pthread_exit(NULL);
  9577. }
  9578. //==========================================
  9579. // Handle server response routine
  9580. //==========================================
  9581. void handleAuthorizeResponse(char *payload, int gun_index)
  9582. {
  9583. mtrace();
  9584. char expiryDatestr[30]={0};
  9585. char parentIdTagstr[20]={0};
  9586. char statusstr[20]={0};
  9587. char expiryDatestrtemp[30]={0};
  9588. char parentIdTagstrtemp[20]={0};
  9589. char IdTagstrtemp[20]={0};
  9590. char statusstrtemp[20]={0};
  9591. int expiryDateISNULL=FALSE;
  9592. int parentIdTagISNULL=FALSE;
  9593. char sstr[160]={0};
  9594. char* filename = AuthorizationCache_JSON;
  9595. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9596. char *loc;
  9597. int resultRename=0;
  9598. int responseIdTagInfoAsZero= 0;
  9599. char rmFileCmd[50]={0};
  9600. DEBUG_INFO("handleAuthorizeResponse...\n");
  9601. json_object *Authorize;
  9602. Authorize = json_tokener_parse(payload);
  9603. if(!is_error(Authorize))
  9604. {
  9605. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9606. {
  9607. // Required data
  9608. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9609. // Optional data
  9610. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9611. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9612. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9613. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9614. }
  9615. }
  9616. json_object_put(Authorize);
  9617. if(expiryDateISNULL == FALSE)
  9618. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9619. if(parentIdTagISNULL == FALSE)
  9620. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9621. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9622. //Update idTag information to authorization cache if supproted
  9623. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9624. {
  9625. if((access(filename,F_OK))!=-1)
  9626. {
  9627. printf("AuthorizationCache exist.\n");
  9628. }
  9629. else
  9630. {
  9631. printf("AuthorizationCache not exist\n");
  9632. FILE *log = fopen(filename, "w+");
  9633. if(log == NULL)
  9634. {
  9635. printf("log is NULL\n");
  9636. goto out;
  9637. }
  9638. else
  9639. {
  9640. fclose(log);
  9641. }
  9642. }
  9643. FILE *infile;
  9644. FILE *outfile;
  9645. // open file for writing
  9646. infile = fopen (filename, "r");
  9647. outfile = fopen (tempfile, "w");
  9648. int c;
  9649. c = fgetc(infile);
  9650. //DEBUG_INFO("c:%d\n",c);
  9651. rewind(infile);
  9652. if(c == EOF)
  9653. {
  9654. DEBUG_INFO("Orignal File is NULL\n");
  9655. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9656. {
  9657. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9658. }
  9659. else
  9660. {
  9661. strcpy(expiryDatestrtemp, "");
  9662. }
  9663. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9664. {
  9665. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9666. }
  9667. else
  9668. {
  9669. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9670. }
  9671. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9672. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9673. fclose(infile);
  9674. fclose(outfile);
  9675. sprintf(rmFileCmd,"rm -f %s",filename);
  9676. system(rmFileCmd);
  9677. resultRename = rename(tempfile, filename);
  9678. if(resultRename == 0)
  9679. {
  9680. printf("File renamed successfully");
  9681. }
  9682. else
  9683. {
  9684. printf("Error: unable to rename the file");
  9685. }
  9686. }
  9687. else
  9688. {
  9689. char buf[160]={0};
  9690. while (fgets(buf, ARRAY_SIZE(buf), infile) != NULL)
  9691. {
  9692. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9693. memset(expiryDatestr, 0, ARRAY_SIZE(expiryDatestrtemp));
  9694. memset(parentIdTagstr,0, ARRAY_SIZE(parentIdTagstrtemp));
  9695. memset(statusstr, 0, ARRAY_SIZE(statusstrtemp));
  9696. memset(IdTagstrtemp, 0, ARRAY_SIZE(IdTagstrtemp));
  9697. memset(expiryDatestrtemp, 0, ARRAY_SIZE(expiryDatestrtemp));
  9698. memset(parentIdTagstrtemp, 0, ARRAY_SIZE(parentIdTagstrtemp));
  9699. memset(statusstrtemp, 0, ARRAY_SIZE(statusstrtemp));
  9700. //------------------IdTag-----------------------
  9701. loc = strstr(buf, "idTag");
  9702. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9703. c = 0;
  9704. while (loc[3+strlen("idTag")+c] != '\"')
  9705. {
  9706. sstr[c] = loc[3+strlen("idTag")+c];
  9707. c++;
  9708. }
  9709. sstr[c] = '\0';
  9710. strcpy(IdTagstrtemp,sstr);
  9711. //*********************expiryDate***************/
  9712. loc = strstr(buf, "expiryDate");
  9713. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9714. c = 0;
  9715. while (loc[3+strlen("expiryDate")+c] != '\"')
  9716. {
  9717. sstr[c] = loc[3+strlen("expiryDate")+c];
  9718. c++;
  9719. }
  9720. sstr[c] = '\0';
  9721. strcpy(expiryDatestr,sstr);
  9722. //*********************parentIdTag***************/
  9723. loc = strstr(buf, "parentIdTag");
  9724. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9725. c = 0;
  9726. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9727. {
  9728. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9729. c++;
  9730. }
  9731. sstr[c] = '\0';
  9732. strcpy(parentIdTagstr,sstr);
  9733. //*********************status***************/
  9734. loc = strstr(buf, "status");
  9735. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9736. c = 0;
  9737. while (loc[3+strlen("status")+c] != '\"')
  9738. {
  9739. sstr[c] = loc[3+strlen("status")+c];
  9740. c++;
  9741. }
  9742. sstr[c] = '\0';
  9743. strcpy(statusstr,sstr);
  9744. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9745. {
  9746. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9747. responseIdTagInfoAsZero = 1;
  9748. }
  9749. else
  9750. {
  9751. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9752. }
  9753. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9754. {
  9755. //modify item
  9756. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9757. {
  9758. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9759. }
  9760. else
  9761. {
  9762. strcpy(expiryDatestrtemp, "");
  9763. }
  9764. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9765. {
  9766. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9767. }
  9768. else
  9769. {
  9770. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9771. }
  9772. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9773. }
  9774. else
  9775. {
  9776. //wrie original item
  9777. strcpy(expiryDatestrtemp, expiryDatestr);
  9778. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9779. strcpy(statusstrtemp, statusstr);
  9780. }
  9781. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9782. }
  9783. fclose(infile);
  9784. fclose(outfile);
  9785. sprintf(rmFileCmd,"rm -f %s",filename);
  9786. system(rmFileCmd);
  9787. resultRename = rename(tempfile, filename);
  9788. if(resultRename == 0)
  9789. {
  9790. DEBUG_INFO("File renamed successfully");
  9791. }
  9792. else
  9793. {
  9794. DEBUG_INFO("Error: unable to rename the file");
  9795. }
  9796. }
  9797. }
  9798. out:
  9799. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9800. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9801. authorizeRetryTimes = 0;
  9802. }
  9803. char * strtrimc( char * s )
  9804. {
  9805. char * p1 = s;
  9806. char * p2 = s;
  9807. while(*p1 != '\0')
  9808. {
  9809. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9810. {
  9811. if(*p1 != ',')
  9812. {
  9813. p1 ++;
  9814. }
  9815. else
  9816. {
  9817. break;
  9818. }
  9819. }
  9820. if(*p1 != ',')
  9821. {
  9822. * p2 ++ = *p1 ++;
  9823. //printf("p2=%s\n",p2);
  9824. }
  9825. else
  9826. {
  9827. break;
  9828. }
  9829. }
  9830. *p2 = '\0';
  9831. return (s);
  9832. }
  9833. void handleBootNotificationResponse(char *payload, int gun_index)
  9834. {
  9835. mtrace();
  9836. char statusStr[12]={0};
  9837. char currentTimeStr[30]={0};
  9838. int intervalInt = 0;
  9839. struct tm tp;
  9840. char buf[28]={0};
  9841. char timebuf[50]={0};
  9842. DEBUG_INFO("handleBootNotificationResponse...\n");
  9843. json_object *BootNotification;
  9844. BootNotification = json_tokener_parse(payload);
  9845. if(!is_error(BootNotification))
  9846. {
  9847. // Required data
  9848. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9849. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9850. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9851. }
  9852. json_object_put(BootNotification);
  9853. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9854. BootNotificationInterval = intervalInt;
  9855. HeartBeatWaitTime = intervalInt;
  9856. //write back to ShmOCPP16Data->BootNotification
  9857. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9858. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9859. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9860. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9861. {
  9862. server_sign = TRUE;
  9863. server_pending =FALSE;
  9864. }
  9865. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9866. {
  9867. server_pending = TRUE;
  9868. }
  9869. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9870. tp.tm_isdst = -1;
  9871. //time_t utc = mktime(&tp);
  9872. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9873. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9874. sprintf(timebuf,"date -s '%s'",buf);
  9875. system(timebuf);
  9876. srand(time(NULL));
  9877. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9878. //==============================================
  9879. // RTC sync
  9880. //==============================================
  9881. system("/sbin/hwclock -w --systohc");
  9882. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9883. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9884. }
  9885. void handleDataTransferResponse(char *payload, int gun_index)
  9886. {
  9887. char sstr[160]={0};//sstr[200]={ 0 };
  9888. int c = 0;
  9889. char *loc;
  9890. DEBUG_INFO("handleDataTransferResponse ...\n");
  9891. loc = strstr(payload, "status");
  9892. printf("loc=%s\n",loc);
  9893. c = 0;
  9894. while (loc[3+strlen("status")+c] != '\"')
  9895. {
  9896. sstr[c] = loc[3+strlen("status")+c];
  9897. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9898. c++;
  9899. }
  9900. sstr[c] = '\0';
  9901. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9902. }
  9903. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9904. {
  9905. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9906. //struct json_object *obj;
  9907. // obj = json_tokener_parse(payload);
  9908. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9909. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9910. //No fields are defined.
  9911. }
  9912. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9913. {
  9914. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9915. //struct json_object *obj;
  9916. // obj = json_tokener_parse(payload);
  9917. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9918. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9919. //No fields are defined.
  9920. }
  9921. void handleHeartbeatResponse(char *payload, int gun_index)
  9922. {
  9923. mtrace();
  9924. struct tm tp;
  9925. char buf[28]={0};
  9926. char timebuf[50]={0};
  9927. DEBUG_INFO("handleHeartbeatResponse...\n");
  9928. json_object *Heartbeat;
  9929. Heartbeat = json_tokener_parse(payload);
  9930. if(!is_error(Heartbeat))
  9931. {
  9932. // Required data
  9933. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9934. }
  9935. json_object_put(BootNotification);
  9936. if(FirstHeartBeat == 0)
  9937. {
  9938. FirstHeartBeat = 1;
  9939. DEBUG_INFO("FirstHeartBeat \n");
  9940. }
  9941. HeartBeatWithNOResponse = 0;
  9942. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9943. tp.tm_isdst = -1;
  9944. //time_t utc = mktime(&tp);
  9945. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9946. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9947. sprintf(timebuf,"date -s '%s'",buf);
  9948. system(timebuf);
  9949. //==============================================
  9950. // RTC sync
  9951. //==============================================
  9952. system("/sbin/hwclock -w --systohc");
  9953. //===============================================
  9954. //Print Out HeartBeat log
  9955. //===============================================
  9956. {
  9957. double diff_t;
  9958. struct tm tp,tp1;
  9959. // BootNotification Receive Time
  9960. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9961. tp.tm_isdst = -1;
  9962. time_t BootNotificationReceiveTime = mktime(&tp);
  9963. //HeartBeat Receive Time
  9964. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  9965. tp1.tm_isdst = -1;
  9966. time_t HeartBeatReceiveTime = mktime(&tp1);
  9967. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  9968. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  9969. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  9970. {
  9971. HeartBeatCountPerHour = (int)diff_t / 3600;
  9972. DEBUG_INFO("handleHeartbeatResponse ...\n");
  9973. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  9974. }
  9975. }
  9976. }
  9977. void handleMeterValuesResponse(char *payload, int gun_index)
  9978. {
  9979. mtrace();
  9980. DEBUG_INFO("handleMeterValuesResponse...\n");
  9981. }
  9982. void handleStartTransactionResponse(char *payload, int gun_index)
  9983. {
  9984. mtrace();
  9985. //int transactionIdInt = 0;
  9986. FILE *outfile;
  9987. char data[100]={0};
  9988. DEBUG_INFO("handleStartTransactionResponse...\n");
  9989. json_object *StartTransaction;
  9990. StartTransaction = json_tokener_parse(payload);
  9991. if(!is_error(StartTransaction))
  9992. {
  9993. // Required data
  9994. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  9995. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  9996. // Optional data
  9997. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  9998. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  9999. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10000. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  10001. }
  10002. json_object_put(StartTransaction);
  10003. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10004. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10005. //-----------Start : write to the Queue TransactionId file -----------------//
  10006. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10007. {}
  10008. else
  10009. {
  10010. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10011. if(log == NULL)
  10012. {
  10013. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10014. return ;
  10015. }
  10016. else
  10017. {
  10018. fclose(log);
  10019. }
  10020. }
  10021. // open file for writing
  10022. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10023. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10024. {
  10025. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10026. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10027. fputs(data, outfile);
  10028. fclose (outfile);
  10029. }
  10030. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10031. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10032. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10033. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10034. }
  10035. void handleStatusNotificationResponse(char *payload, int gun_index)
  10036. {
  10037. mtrace();
  10038. DEBUG_INFO("handleStatusNotificationResponse...\n");
  10039. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10040. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10041. }
  10042. void handleStopTransactionnResponse(char *payload, int gun_index)
  10043. {
  10044. mtrace();
  10045. DEBUG_INFO("handleStopTransactionnResponse...\n");
  10046. json_object *StopTransaction;
  10047. StopTransaction = json_tokener_parse(payload);
  10048. if(!is_error(StopTransaction))
  10049. {
  10050. // Optional data
  10051. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  10052. {
  10053. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  10054. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  10055. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  10056. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10057. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  10058. }
  10059. }
  10060. json_object_put(StopTransaction);
  10061. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10062. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10063. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10064. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10065. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10066. }
  10067. //==========================================
  10068. // Handle Error routine
  10069. //==========================================
  10070. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10071. {
  10072. mtrace();
  10073. #ifdef SystemLogMessage
  10074. DEBUG_INFO("errorCode: %s\n", errorCode);
  10075. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10076. DEBUG_INFO("errorDetails: %s\n", payload);
  10077. #endif
  10078. }
  10079. //===============================================
  10080. // Common routine
  10081. //===============================================
  10082. int initialConfigurationTable(void)
  10083. {
  10084. //clock_t start_t, end_t, total_t;
  10085. FILE *fp;
  10086. FILE *outfile;
  10087. char str[200]={0};
  10088. char sstr[100]={0};
  10089. int c = 0;
  10090. char *loc;
  10091. DEBUG_INFO("initialConfigurationTable...\n");
  10092. //start_t = clock();
  10093. //printf("Starting of the program, start_t = %ld\n", start_t);
  10094. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10095. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10096. {
  10097. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10098. if(outfile == NULL)
  10099. {
  10100. DEBUG_INFO("Error opening file\n");
  10101. return FALSE;
  10102. }
  10103. /*Core Profile*/
  10104. //AllowOfflineTxForUnknownId
  10105. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10109. //AuthorizationCacheEnabled
  10110. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10114. //AuthorizeRemoteTxRequests
  10115. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10119. //BlinkRepeat
  10120. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10123. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10124. //ClockAlignedDataInterval
  10125. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10129. //ConnectionTimeOut
  10130. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10133. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10134. //GetConfigurationMaxKeys
  10135. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "44" );
  10138. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10139. // HeartbeatInterval
  10140. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10144. // LightIntensity
  10145. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10148. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10149. // LocalAuthorizeOffline
  10150. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10153. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10154. // LocalPreAuthorize
  10155. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10158. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10159. // MaxEnergyOnInvalidId
  10160. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10163. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10165. // MeterValuesAlignedData
  10166. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10168. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10170. else
  10171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10172. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10173. // MeterValuesAlignedDataMaxLength
  10174. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10176. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10178. else
  10179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10181. // MeterValuesSampledData
  10182. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10184. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10186. else
  10187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10188. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10189. // MeterValuesSampledDataMaxLength
  10190. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10192. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10193. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10194. else
  10195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10196. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10197. // MeterValueSampleInterval
  10198. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10202. // MinimumStatusDuration
  10203. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10206. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10207. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10208. // NumberOfConnectors
  10209. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10211. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10212. {
  10213. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10214. }
  10215. else
  10216. {
  10217. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10218. }
  10219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10220. // ResetRetries
  10221. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10224. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10225. // ConnectorPhaseRotation
  10226. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10229. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10230. // ConnectorPhaseRotationMaxLength
  10231. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10234. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10235. // StopTransactionOnEVSideDisconnect
  10236. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10239. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10240. // StopTransactionOnInvalidId
  10241. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10245. // StopTxnAlignedData
  10246. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10249. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10250. // StopTxnAlignedDataMaxLength
  10251. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10254. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10255. // StopTxnSampledData
  10256. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10258. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10260. else
  10261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10263. // StopTxnSampledDataMaxLength
  10264. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10266. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10267. {
  10268. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10269. }
  10270. else
  10271. {
  10272. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10273. }
  10274. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10275. // SupportedFeatureProfiles
  10276. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10279. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10280. // SupportedFeatureProfilesMaxLength
  10281. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10284. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10285. // TransactionMessageAttempts
  10286. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10289. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10290. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10291. // TransactionMessageRetryInterval
  10292. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10295. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10297. // UnlockConnectorOnEVSideDisconnect
  10298. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10301. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10302. // WebSocketPingInterval
  10303. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10307. // QueueOffLineStartTransactionMessage
  10308. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10311. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10312. //* Local Auth List Management Profile*/
  10313. #if 0
  10314. //For OCTT Test Case
  10315. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10318. #endif
  10319. #if 1
  10320. //LocalAuthListEnabled
  10321. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10324. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10325. #endif
  10326. //LocalAuthListMaxLength
  10327. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10330. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10331. //SendLocalListMaxLength
  10332. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10333. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10335. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10336. //ReserveConnectorZeroSupported
  10337. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10340. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10341. //* Smart Charging Profile */
  10342. //ChargeProfileMaxStackLevel
  10343. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10346. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10347. // ChargingScheduleAllowedChargingRateUnit
  10348. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10351. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10352. // ChargingScheduleMaxPeriods
  10353. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10356. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10357. // ConnectorSwitch3to1PhaseSupported
  10358. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10361. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10362. // MaxChargingProfilesInstalled
  10363. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10366. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10367. fclose(outfile);
  10368. }
  10369. else
  10370. {
  10371. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10372. char keystr[60]={0};
  10373. char readonlystr[10]={0};
  10374. char valuestr[100]={0};
  10375. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10376. if(fp == NULL) {
  10377. DEBUG_INFO("Error opening file");
  10378. return FALSE;
  10379. }
  10380. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10381. {
  10382. //DEBUG_INFO("Get Configuration \n");
  10383. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10384. //*************************key*********************************/
  10385. loc = strstr(str, "key");
  10386. c = 0;
  10387. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10388. while (loc[strlen("key")+3+c] != '\"')
  10389. {
  10390. sstr[c] = loc[strlen("key")+3+c];
  10391. c++;
  10392. }
  10393. sstr[c] = '\0';
  10394. strcpy(keystr,sstr);
  10395. //*************************readonly*********************************/
  10396. loc = strstr(str, "readonly");
  10397. c = 0;
  10398. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10399. while (loc[strlen("readonly")+2+c] != ',')
  10400. {
  10401. sstr[c] = loc[strlen("readonly")+2+c];
  10402. c++;
  10403. }
  10404. sstr[c] = '\0';
  10405. strcpy(readonlystr,sstr);
  10406. //*************************value*********************************/
  10407. loc = strstr(str, "value");
  10408. c = 0;
  10409. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10410. while (loc[strlen("value")+3+c] != '\"')
  10411. {
  10412. sstr[c] = loc[strlen("value")+3+c];
  10413. c++;
  10414. }
  10415. sstr[c] = '\0';
  10416. strcpy(valuestr,sstr);
  10417. // DEBUG_INFO("keystr=%s\n",keystr);
  10418. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10419. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10420. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10421. {
  10422. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10423. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10424. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10425. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10426. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10427. }
  10428. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10429. {
  10430. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10431. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10432. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10433. }
  10434. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10435. {
  10436. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10437. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10438. }
  10439. if(strcmp(keystr, "BlinkRepeat") == 0)
  10440. {
  10441. //Charger.BlinkRepeat = Integer.parseInt(value);
  10442. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10443. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10444. }
  10445. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10446. {
  10447. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10448. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10449. }
  10450. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10451. {
  10452. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10453. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10454. }
  10455. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10456. {
  10457. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10458. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10459. }
  10460. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10461. {
  10462. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10463. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10464. HeartBeatWaitTime = atoi(valuestr);
  10465. }
  10466. if(strcmp(keystr, "LightIntensity") == 0)
  10467. {
  10468. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10470. }
  10471. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10472. {
  10473. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10474. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10475. }
  10476. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10477. {
  10478. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10479. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10480. }
  10481. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10482. {
  10483. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10484. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10485. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10486. }
  10487. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10488. {
  10489. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10490. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10491. }
  10492. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10493. {
  10494. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10495. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10496. }
  10497. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10498. {
  10499. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10500. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10501. }
  10502. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10503. {
  10504. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10505. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10506. }
  10507. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10508. {
  10509. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10510. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10511. }
  10512. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10513. {
  10514. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10515. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10516. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10517. }
  10518. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10519. {
  10520. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10521. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10522. }
  10523. if(strcmp(keystr, "ResetRetries") == 0)
  10524. {
  10525. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10526. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10527. }
  10528. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10529. {
  10530. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10531. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10532. }
  10533. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10534. {
  10535. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10537. }
  10538. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10539. {
  10540. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10541. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10542. }
  10543. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10544. {
  10545. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10546. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10547. }
  10548. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10549. {
  10550. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10551. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10552. }
  10553. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10554. {
  10555. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10556. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10557. }
  10558. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10559. {
  10560. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10561. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10562. }
  10563. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10564. {
  10565. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10566. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10567. }
  10568. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10569. {
  10570. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10571. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10572. }
  10573. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10574. {
  10575. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10576. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10577. }
  10578. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10579. {
  10580. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10581. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10582. TransactionMessageAttemptsValue = atoi(valuestr);
  10583. }
  10584. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10585. {
  10586. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10587. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10588. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10589. }
  10590. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10591. {
  10592. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10593. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10594. }
  10595. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10596. {
  10597. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10598. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10599. }
  10600. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10601. {
  10602. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10603. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10604. }
  10605. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10606. {
  10607. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10608. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10609. }
  10610. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10611. {
  10612. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10613. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10614. }
  10615. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10616. {
  10617. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10619. }
  10620. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10621. {
  10622. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10623. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10624. }
  10625. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10626. {
  10627. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10628. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10629. }
  10630. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10631. {
  10632. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10633. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10634. }
  10635. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10636. {
  10637. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10638. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10639. }
  10640. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10641. {
  10642. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10643. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10644. }
  10645. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10646. {
  10647. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10648. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10649. }
  10650. }
  10651. fclose(fp);
  10652. }
  10653. return 0;
  10654. }
  10655. void StoreConfigurationTable(void)
  10656. {
  10657. FILE *outfile;
  10658. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10659. if(outfile == NULL)
  10660. {
  10661. DEBUG_INFO("Error opening file");
  10662. return ;
  10663. }
  10664. /*Core Profile*/
  10665. //AllowOfflineTxForUnknownId
  10666. /*
  10667. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10668. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10671. */
  10672. //DEBUG_INFO("data=%s\n",data);
  10673. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10674. //AuthorizationCacheEnabled
  10675. /*
  10676. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10679. */
  10680. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10681. //AuthorizeRemoteTxRequests
  10682. /*
  10683. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10686. */
  10687. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10688. //BlinkRepeat
  10689. /*
  10690. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10693. */
  10694. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10695. //ClockAlignedDataInterval
  10696. /*
  10697. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10700. */
  10701. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10702. //ConnectionTimeOut
  10703. /*
  10704. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10707. */
  10708. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10709. //GetConfigurationMaxKeys
  10710. /*
  10711. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10714. */
  10715. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10716. // HeartbeatInterval
  10717. /*
  10718. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10720. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10721. */
  10722. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10723. // LightIntensity
  10724. /*
  10725. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10727. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10728. */
  10729. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10730. // LocalAuthorizeOffline
  10731. /*
  10732. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10735. */
  10736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10737. // LocalPreAuthorize
  10738. /*
  10739. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10742. */
  10743. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10744. // MaxEnergyOnInvalidId
  10745. /*
  10746. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10749. */
  10750. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10751. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10752. // MeterValuesAlignedData
  10753. /*
  10754. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10757. */
  10758. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10759. // MeterValuesAlignedDataMaxLength
  10760. /*
  10761. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10764. */
  10765. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10766. // MeterValuesSampledData
  10767. /*
  10768. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10771. */
  10772. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10773. // MeterValuesSampledDataMaxLength
  10774. /*
  10775. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10778. */
  10779. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10780. // MeterValueSampleInterval
  10781. /*
  10782. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10785. */
  10786. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10787. // MinimumStatusDuration
  10788. /*
  10789. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10792. */
  10793. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10794. // NumberOfConnectors
  10795. /*
  10796. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10798. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10799. {
  10800. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10801. }
  10802. else
  10803. {
  10804. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10805. }
  10806. */
  10807. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10808. // ResetRetries
  10809. /*
  10810. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10813. */
  10814. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10815. // ConnectorPhaseRotation
  10816. /*
  10817. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10820. */
  10821. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10822. // ConnectorPhaseRotationMaxLength
  10823. /*
  10824. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10826. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10827. */
  10828. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10829. // StopTransactionOnEVSideDisconnect
  10830. /*
  10831. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10834. */
  10835. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10836. // StopTransactionOnInvalidId
  10837. /*
  10838. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10841. */
  10842. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10843. // StopTxnAlignedData
  10844. /*
  10845. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10848. */
  10849. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10850. // StopTxnAlignedDataMaxLength
  10851. /*
  10852. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10855. */
  10856. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10857. // StopTxnSampledData
  10858. /*
  10859. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10862. */
  10863. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10864. // StopTxnSampledDataMaxLength
  10865. /*
  10866. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10869. */
  10870. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10871. // SupportedFeatureProfiles
  10872. /*
  10873. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10875. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10876. */
  10877. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10878. // SupportedFeatureProfilesMaxLength
  10879. /*
  10880. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10883. */
  10884. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10885. // TransactionMessageAttempts
  10886. /*
  10887. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10889. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10890. */
  10891. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10892. // TransactionMessageRetryInterval
  10893. /*
  10894. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10897. */
  10898. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10899. // UnlockConnectorOnEVSideDisconnect
  10900. /*
  10901. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10903. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10904. */
  10905. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10906. // WebSocketPingInterval
  10907. /*
  10908. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10910. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10911. */
  10912. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10913. // QueueOffLineStartTransactionMessage
  10914. /*
  10915. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  10916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10918. */
  10919. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10920. //* Local Auth List Management Profile*/
  10921. //LocalAuthListEnabled
  10922. /*
  10923. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10924. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10925. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10926. */
  10927. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10928. //LocalAuthListMaxLength
  10929. /*
  10930. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10931. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10932. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10933. */
  10934. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10935. //SendLocalListMaxLength
  10936. /*
  10937. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10938. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10939. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10940. */
  10941. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10942. //ReserveConnectorZeroSupported
  10943. /*
  10944. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10945. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10946. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10947. */
  10948. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10949. //* Smart Charging Profile */
  10950. //ChargeProfileMaxStackLevel
  10951. /*
  10952. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10953. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10954. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10955. */
  10956. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10957. // ChargingScheduleAllowedChargingRateUnit
  10958. /*
  10959. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10960. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10962. */
  10963. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10964. // ChargingScheduleMaxPeriods
  10965. /*
  10966. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10967. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10968. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10969. */
  10970. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10971. // ConnectorSwitch3to1PhaseSupported
  10972. /*
  10973. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10974. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10975. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10976. */
  10977. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10978. // MaxChargingProfilesInstalled
  10979. /*
  10980. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10981. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10983. */
  10984. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10985. fclose(outfile);
  10986. }
  10987. void getKeyValue(char *keyReq)
  10988. {
  10989. int isEmpty = FALSE;
  10990. int isKnowKey = FALSE;
  10991. DEBUG_INFO("keyReq = %s\n", keyReq);
  10992. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10993. isEmpty = TRUE;
  10994. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10995. {
  10996. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10998. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10999. {
  11000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11001. }
  11002. else
  11003. {
  11004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11005. }
  11006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11007. isKnowKey = TRUE;
  11008. }
  11009. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11010. {
  11011. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11012. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11013. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11014. {
  11015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11016. }
  11017. else
  11018. {
  11019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11020. }
  11021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11022. isKnowKey = TRUE;
  11023. }
  11024. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11025. {
  11026. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11028. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11029. {
  11030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11031. }
  11032. else
  11033. {
  11034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11035. }
  11036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11037. isKnowKey = TRUE;
  11038. }
  11039. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11040. {
  11041. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11043. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11044. {
  11045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11046. }
  11047. else
  11048. {
  11049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11050. }
  11051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11052. isKnowKey = TRUE;
  11053. }
  11054. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11055. {
  11056. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11058. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11059. {
  11060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11061. }
  11062. else
  11063. {
  11064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11065. }
  11066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11067. isKnowKey = TRUE;
  11068. }
  11069. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11070. {
  11071. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11073. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11074. {
  11075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11076. }
  11077. else
  11078. {
  11079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11080. }
  11081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11082. isKnowKey = TRUE;
  11083. }
  11084. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11085. {
  11086. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11088. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11089. {
  11090. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11091. }
  11092. else
  11093. {
  11094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11095. }
  11096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11097. isKnowKey = TRUE;
  11098. }
  11099. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11100. {
  11101. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11103. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11104. {
  11105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11106. }
  11107. else
  11108. {
  11109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11110. }
  11111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11112. isKnowKey = TRUE;
  11113. }
  11114. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11115. {
  11116. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11118. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11119. {
  11120. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11121. }
  11122. else
  11123. {
  11124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11125. }
  11126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11127. isKnowKey = TRUE;
  11128. }
  11129. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11130. {
  11131. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11133. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11134. {
  11135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11136. }
  11137. else
  11138. {
  11139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11140. }
  11141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11142. isKnowKey = TRUE;
  11143. }
  11144. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11145. {
  11146. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11148. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11149. {
  11150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11151. }
  11152. else
  11153. {
  11154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11155. }
  11156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11157. isKnowKey = TRUE;
  11158. }
  11159. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11160. {
  11161. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11163. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11164. {
  11165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11166. }
  11167. else
  11168. {
  11169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11170. }
  11171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11172. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11173. isKnowKey = TRUE;
  11174. }
  11175. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11176. {
  11177. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11179. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11180. {
  11181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11182. }
  11183. else
  11184. {
  11185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11186. }
  11187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11188. isKnowKey = TRUE;
  11189. }
  11190. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11191. {
  11192. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11194. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11195. {
  11196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11197. }
  11198. else
  11199. {
  11200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11201. }
  11202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11203. isKnowKey = TRUE;
  11204. }
  11205. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11206. {
  11207. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11209. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11210. {
  11211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11212. }
  11213. else
  11214. {
  11215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11216. }
  11217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11218. isKnowKey = TRUE;
  11219. }
  11220. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11221. {
  11222. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11224. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11225. {
  11226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11227. }
  11228. else
  11229. {
  11230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11231. }
  11232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11233. isKnowKey = TRUE;
  11234. }
  11235. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11236. {
  11237. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11239. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11240. {
  11241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11242. }
  11243. else
  11244. {
  11245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11246. }
  11247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11248. isKnowKey = TRUE;
  11249. }
  11250. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11251. {
  11252. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11254. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11255. {
  11256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11257. }
  11258. else
  11259. {
  11260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11261. }
  11262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11263. isKnowKey = TRUE;
  11264. }
  11265. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11266. {
  11267. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11269. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11270. {
  11271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11272. }
  11273. else
  11274. {
  11275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11276. }
  11277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11278. isKnowKey = TRUE;
  11279. }
  11280. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11281. {
  11282. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11284. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11285. {
  11286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11287. }
  11288. else
  11289. {
  11290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11291. }
  11292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11293. isKnowKey = TRUE;
  11294. }
  11295. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11296. {
  11297. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11299. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11300. {
  11301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11302. }
  11303. else
  11304. {
  11305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11306. }
  11307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11308. isKnowKey = TRUE;
  11309. }
  11310. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11311. {
  11312. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11314. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11315. {
  11316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11317. }
  11318. else
  11319. {
  11320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11321. }
  11322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11323. isKnowKey = TRUE;
  11324. }
  11325. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11326. {
  11327. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11329. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11330. {
  11331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11332. }
  11333. else
  11334. {
  11335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11336. }
  11337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11338. isKnowKey = TRUE;
  11339. }
  11340. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11341. {
  11342. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11344. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11345. {
  11346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11347. }
  11348. else
  11349. {
  11350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11351. }
  11352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11353. isKnowKey = TRUE;
  11354. }
  11355. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11356. {
  11357. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11359. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11360. {
  11361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11362. }
  11363. else
  11364. {
  11365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11366. }
  11367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11368. isKnowKey = TRUE;
  11369. }
  11370. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11371. {
  11372. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11374. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11375. {
  11376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11377. }
  11378. else
  11379. {
  11380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11381. }
  11382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11383. isKnowKey = TRUE;
  11384. }
  11385. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11386. {
  11387. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11389. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11390. {
  11391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11392. }
  11393. else
  11394. {
  11395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11396. }
  11397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11398. isKnowKey = TRUE;
  11399. }
  11400. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11401. {
  11402. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11404. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11405. {
  11406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11407. }
  11408. else
  11409. {
  11410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11411. }
  11412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11413. isKnowKey = TRUE;
  11414. }
  11415. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11416. {
  11417. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11419. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11420. {
  11421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11422. }
  11423. else
  11424. {
  11425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11426. }
  11427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11428. isKnowKey = TRUE;
  11429. }
  11430. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11431. {
  11432. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11434. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11435. {
  11436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11437. }
  11438. else
  11439. {
  11440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11441. }
  11442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11443. isKnowKey = TRUE;
  11444. }
  11445. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11446. {
  11447. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11449. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11450. {
  11451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11452. }
  11453. else
  11454. {
  11455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11456. }
  11457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11458. isKnowKey = TRUE;
  11459. }
  11460. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11461. {
  11462. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11464. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11465. {
  11466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11467. }
  11468. else
  11469. {
  11470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11471. }
  11472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11473. isKnowKey = TRUE;
  11474. }
  11475. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11476. {
  11477. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11479. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11480. {
  11481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11482. }
  11483. else
  11484. {
  11485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11486. }
  11487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11488. isKnowKey = TRUE;
  11489. }
  11490. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11491. {
  11492. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11494. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11495. {
  11496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11497. }
  11498. else
  11499. {
  11500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11501. }
  11502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11503. isKnowKey = TRUE;
  11504. }
  11505. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11506. {
  11507. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11509. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11510. {
  11511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11512. }
  11513. else
  11514. {
  11515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11516. }
  11517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11518. isKnowKey = TRUE;
  11519. }
  11520. #if 1
  11521. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11522. {
  11523. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11525. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11526. {
  11527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11528. }
  11529. else
  11530. {
  11531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11532. }
  11533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11534. isKnowKey = TRUE;
  11535. }
  11536. #endif
  11537. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11538. {
  11539. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11541. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11542. {
  11543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11544. }
  11545. else
  11546. {
  11547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11548. }
  11549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11550. isKnowKey = TRUE;
  11551. }
  11552. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11553. {
  11554. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11556. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11557. {
  11558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11559. }
  11560. else
  11561. {
  11562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11563. }
  11564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11565. isKnowKey = TRUE;
  11566. }
  11567. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11568. {
  11569. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11571. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11572. {
  11573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11574. }
  11575. else
  11576. {
  11577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11578. }
  11579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11580. isKnowKey = TRUE;
  11581. }
  11582. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11583. {
  11584. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11586. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11587. {
  11588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11589. }
  11590. else
  11591. {
  11592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11593. }
  11594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11595. isKnowKey = TRUE;
  11596. }
  11597. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11598. {
  11599. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11601. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11602. {
  11603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11604. }
  11605. else
  11606. {
  11607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11608. }
  11609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11610. isKnowKey = TRUE;
  11611. }
  11612. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11613. {
  11614. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11616. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11617. {
  11618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11619. }
  11620. else
  11621. {
  11622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11623. }
  11624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11625. isKnowKey = TRUE;
  11626. }
  11627. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11628. {
  11629. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11631. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11632. {
  11633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11634. }
  11635. else
  11636. {
  11637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11638. }
  11639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11640. isKnowKey = TRUE;
  11641. }
  11642. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11643. {
  11644. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11646. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11647. {
  11648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11649. }
  11650. else
  11651. {
  11652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11653. }
  11654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11655. isKnowKey = TRUE;
  11656. }
  11657. //=========================================================
  11658. if(!isEmpty && !isKnowKey)
  11659. {
  11660. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11661. strcpy(unknownkey[UnknownKeynum], keyReq);
  11662. UnknownKeynum = UnknownKeynum + 1;
  11663. }
  11664. }
  11665. void processUnkownKey(void)
  11666. {
  11667. DEBUG_INFO("processUnkownKey...\n");
  11668. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11669. for(int index=0; index < UnknownKeynum; index++)
  11670. {
  11671. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11672. {
  11673. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11674. }
  11675. }
  11676. }
  11677. int setKeyValue(char *key, char *value)
  11678. {
  11679. int isSuccess = NotSupported;
  11680. int check_ascii=0;
  11681. char str[10]={0};
  11682. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11683. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11684. {
  11685. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11686. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11687. {
  11688. strcpy(str, (const char*)value);
  11689. for(int i = 0; str[i]; i++){
  11690. str[i] = tolower(str[i]);
  11691. }
  11692. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11693. isSuccess = ConfigurationStatus_Accepted;
  11694. }
  11695. else
  11696. {
  11697. isSuccess = ConfigurationStatus_Rejected;
  11698. }
  11699. }
  11700. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11701. {
  11702. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11703. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11704. {
  11705. strcpy(str, (const char*)value);
  11706. for(int i = 0; str[i]; i++){
  11707. str[i] = tolower(str[i]);
  11708. }
  11709. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11710. isSuccess = ConfigurationStatus_Accepted;
  11711. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11712. }
  11713. else
  11714. {
  11715. isSuccess = ConfigurationStatus_Rejected;
  11716. }
  11717. }
  11718. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11719. {
  11720. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11721. {
  11722. strcpy(str, (const char*)value);
  11723. for(int i = 0; str[i]; i++)
  11724. {
  11725. str[i] = tolower(str[i]);
  11726. }
  11727. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11728. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11729. isSuccess = ConfigurationStatus_Accepted;
  11730. }
  11731. else
  11732. {
  11733. isSuccess = ConfigurationStatus_Rejected;
  11734. }
  11735. }
  11736. if(strcmp(key, "BlinkRepeat") == 0)
  11737. {
  11738. //Charger.BlinkRepeat = Integer.parseInt(value);
  11739. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11740. {
  11741. check_ascii = value[0];
  11742. if( (check_ascii < 48) || (check_ascii > 57) )
  11743. {
  11744. isSuccess = ConfigurationStatus_Rejected;
  11745. }
  11746. else
  11747. {
  11748. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11749. isSuccess = ConfigurationStatus_Accepted;
  11750. }
  11751. }
  11752. else
  11753. {
  11754. isSuccess = ConfigurationStatus_Rejected;
  11755. }
  11756. }
  11757. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11758. {
  11759. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11760. {
  11761. check_ascii = value[0];
  11762. if( (check_ascii < 48) || (check_ascii > 57) )
  11763. {
  11764. isSuccess = ConfigurationStatus_Rejected;
  11765. }
  11766. else
  11767. {
  11768. if((atoi(value) == 0) || (atoi(value) >= 10))
  11769. {
  11770. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11771. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11772. isSuccess = ConfigurationStatus_Accepted;
  11773. }
  11774. else
  11775. isSuccess = ConfigurationStatus_Rejected;
  11776. }
  11777. }
  11778. else
  11779. {
  11780. isSuccess = ConfigurationStatus_Rejected;
  11781. }
  11782. }
  11783. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11784. {
  11785. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11786. {
  11787. check_ascii = value[0];
  11788. if( (check_ascii < 48) || (check_ascii > 57) )
  11789. {
  11790. isSuccess = ConfigurationStatus_Rejected;
  11791. }
  11792. else
  11793. {
  11794. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11795. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11796. isSuccess = ConfigurationStatus_Accepted;
  11797. }
  11798. }
  11799. else
  11800. {
  11801. isSuccess = ConfigurationStatus_Rejected;
  11802. }
  11803. }
  11804. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11805. {
  11806. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11807. {
  11808. check_ascii = value[0];
  11809. if( (check_ascii < 48) || (check_ascii > 57) )
  11810. {
  11811. isSuccess = ConfigurationStatus_Rejected;
  11812. }
  11813. else
  11814. {
  11815. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11816. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11817. isSuccess = ConfigurationStatus_Accepted;
  11818. }
  11819. }
  11820. else
  11821. {
  11822. isSuccess = ConfigurationStatus_Rejected;
  11823. }
  11824. }
  11825. if(strcmp(key, "HeartbeatInterval") == 0)
  11826. {
  11827. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11828. {
  11829. check_ascii = value[0];
  11830. if( (check_ascii < 48) || (check_ascii > 57) )
  11831. {
  11832. isSuccess = ConfigurationStatus_Rejected;
  11833. }
  11834. else
  11835. {
  11836. if((atoi(value) == 0) || (atoi(value) >= 10))
  11837. {
  11838. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11839. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11840. HeartBeatWaitTime = atoi(value);
  11841. isSuccess = ConfigurationStatus_Accepted;
  11842. }
  11843. else
  11844. {
  11845. isSuccess = ConfigurationStatus_Rejected;
  11846. }
  11847. }
  11848. }
  11849. else
  11850. {
  11851. isSuccess = ConfigurationStatus_Rejected;
  11852. }
  11853. }
  11854. if(strcmp(key, "LightIntensity") == 0)
  11855. {
  11856. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11857. {
  11858. check_ascii = value[0];
  11859. if( (check_ascii < 48) || (check_ascii > 57) )
  11860. {
  11861. isSuccess = ConfigurationStatus_Rejected;
  11862. }
  11863. else
  11864. {
  11865. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11866. isSuccess = ConfigurationStatus_Accepted;
  11867. }
  11868. }
  11869. else
  11870. {
  11871. isSuccess = ConfigurationStatus_Rejected;
  11872. }
  11873. }
  11874. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11875. {
  11876. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11877. {
  11878. strcpy(str, (const char*)value);
  11879. for(int i = 0; str[i]; i++)
  11880. {
  11881. str[i] = tolower(str[i]);
  11882. }
  11883. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11884. isSuccess = ConfigurationStatus_Accepted;
  11885. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11886. }
  11887. else
  11888. {
  11889. isSuccess = ConfigurationStatus_Rejected;
  11890. }
  11891. }
  11892. if(strcmp(key, "LocalPreAuthorize") == 0)
  11893. {
  11894. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11895. {
  11896. strcpy(str, (const char*)value);
  11897. for(int i = 0; str[i]; i++)
  11898. {
  11899. str[i] = tolower(str[i]);
  11900. }
  11901. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11902. isSuccess = ConfigurationStatus_Accepted;
  11903. }
  11904. else
  11905. {
  11906. isSuccess = ConfigurationStatus_Rejected;
  11907. }
  11908. }
  11909. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11910. {
  11911. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11912. {
  11913. check_ascii = value[0];
  11914. if( (check_ascii < 48) || (check_ascii > 57) )
  11915. {
  11916. isSuccess = ConfigurationStatus_Rejected;
  11917. }
  11918. else
  11919. {
  11920. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11921. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11922. isSuccess = ConfigurationStatus_Accepted;
  11923. }
  11924. }
  11925. else
  11926. {
  11927. isSuccess = ConfigurationStatus_Rejected;
  11928. }
  11929. }
  11930. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11931. {
  11932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11933. {
  11934. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11935. isSuccess = ConfigurationStatus_Accepted;
  11936. }
  11937. else
  11938. {
  11939. isSuccess = ConfigurationStatus_Rejected;
  11940. }
  11941. }
  11942. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11943. {
  11944. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11945. {
  11946. check_ascii = value[0];
  11947. if( (check_ascii < 48) || (check_ascii > 57) )
  11948. {
  11949. isSuccess = ConfigurationStatus_Rejected;
  11950. }
  11951. else
  11952. {
  11953. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11954. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11955. isSuccess = ConfigurationStatus_Accepted;
  11956. }
  11957. }
  11958. else
  11959. {
  11960. isSuccess = ConfigurationStatus_Rejected;
  11961. }
  11962. }
  11963. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11964. {
  11965. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11966. {
  11967. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11968. isSuccess = ConfigurationStatus_Accepted;
  11969. }
  11970. else
  11971. {
  11972. isSuccess = ConfigurationStatus_Rejected;
  11973. }
  11974. }
  11975. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11976. {
  11977. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11978. {
  11979. check_ascii = value[0];
  11980. if( (check_ascii < 48) || (check_ascii > 57) )
  11981. {
  11982. isSuccess = ConfigurationStatus_Rejected;
  11983. }
  11984. else
  11985. {
  11986. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11987. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11988. isSuccess = ConfigurationStatus_Accepted;
  11989. }
  11990. }
  11991. else
  11992. {
  11993. isSuccess = ConfigurationStatus_Rejected;
  11994. }
  11995. }
  11996. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11997. {
  11998. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11999. {
  12000. check_ascii = value[0];
  12001. if( (check_ascii < 48) || (check_ascii > 57) )
  12002. {
  12003. isSuccess = ConfigurationStatus_Rejected;
  12004. }
  12005. else
  12006. {
  12007. if((atoi(value) == 0) || (atoi(value) >= 10))
  12008. {
  12009. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12010. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12011. isSuccess = ConfigurationStatus_Accepted;
  12012. }
  12013. else
  12014. {
  12015. isSuccess = ConfigurationStatus_Rejected;
  12016. }
  12017. }
  12018. }
  12019. else
  12020. {
  12021. isSuccess = ConfigurationStatus_Rejected;
  12022. }
  12023. }
  12024. if(strcmp(key, "MinimumStatusDuration") == 0)
  12025. {
  12026. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12027. {
  12028. check_ascii = value[0];
  12029. if( (check_ascii < 48) || (check_ascii > 57) )
  12030. {
  12031. isSuccess = ConfigurationStatus_Rejected;
  12032. }
  12033. else
  12034. {
  12035. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12036. {
  12037. isSuccess = ConfigurationStatus_Rejected;
  12038. }
  12039. else
  12040. {
  12041. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12042. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12043. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12044. isSuccess = ConfigurationStatus_Accepted;
  12045. }
  12046. }
  12047. }
  12048. else
  12049. {
  12050. isSuccess = ConfigurationStatus_Rejected;
  12051. }
  12052. }
  12053. if(strcmp(key, "NumberOfConnectors") == 0)
  12054. {
  12055. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12056. {
  12057. check_ascii = value[0];
  12058. if( (check_ascii < 48) || (check_ascii > 57) )
  12059. {
  12060. isSuccess = ConfigurationStatus_Rejected;
  12061. }
  12062. else
  12063. {
  12064. //Charger.ResetRetries = Integer.parseInt(value);
  12065. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12066. isSuccess = ConfigurationStatus_Accepted;
  12067. }
  12068. }
  12069. else
  12070. {
  12071. isSuccess = ConfigurationStatus_Rejected;
  12072. }
  12073. }
  12074. if(strcmp(key, "ResetRetries") == 0)
  12075. {
  12076. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12077. {
  12078. check_ascii = value[0];
  12079. if( (check_ascii < 48) || (check_ascii > 57) )
  12080. {
  12081. isSuccess = ConfigurationStatus_Rejected;
  12082. }
  12083. else
  12084. {
  12085. //Charger.ResetRetries = Integer.parseInt(value);
  12086. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12087. isSuccess = ConfigurationStatus_Accepted;
  12088. }
  12089. }
  12090. else
  12091. {
  12092. isSuccess = ConfigurationStatus_Rejected;
  12093. }
  12094. }
  12095. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12096. {
  12097. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12098. {
  12099. strcpy(str, (const char*)value);
  12100. for(int i = 0; str[i]; i++)
  12101. {
  12102. str[i] = tolower(str[i]);
  12103. }
  12104. if(strcmp(str, "notapplicable")== 0)
  12105. {
  12106. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12107. isSuccess = ConfigurationStatus_Accepted;
  12108. }
  12109. else if(strcmp(str, "unknown")== 0)
  12110. {
  12111. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12112. isSuccess = ConfigurationStatus_Accepted;
  12113. }
  12114. else if(strcmp(str, "rst")== 0)
  12115. {
  12116. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12117. isSuccess = ConfigurationStatus_Accepted;
  12118. }
  12119. else if(strcmp(str, "rts")== 0)
  12120. {
  12121. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12122. isSuccess = ConfigurationStatus_Accepted;
  12123. }
  12124. else if(strcmp(str, "srt")== 0)
  12125. {
  12126. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12127. isSuccess = ConfigurationStatus_Accepted;
  12128. }
  12129. else if(strcmp(str, "str")== 0)
  12130. {
  12131. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12132. isSuccess = ConfigurationStatus_Accepted;
  12133. }
  12134. else if(strcmp(str, "trs")== 0)
  12135. {
  12136. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12137. isSuccess = ConfigurationStatus_Accepted;
  12138. }
  12139. else if(strcmp(str, "tsr")== 0)
  12140. {
  12141. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12142. isSuccess = ConfigurationStatus_Accepted;
  12143. }
  12144. else
  12145. {
  12146. isSuccess = ConfigurationStatus_Rejected;
  12147. }
  12148. }
  12149. else
  12150. {
  12151. isSuccess = ConfigurationStatus_Rejected;
  12152. }
  12153. }
  12154. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12155. {
  12156. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12157. {
  12158. check_ascii = value[0];
  12159. if( (check_ascii < 48) || (check_ascii > 57) )
  12160. {
  12161. isSuccess = ConfigurationStatus_Rejected;
  12162. }
  12163. else
  12164. {
  12165. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12166. isSuccess = ConfigurationStatus_Accepted;
  12167. }
  12168. }
  12169. else
  12170. {
  12171. isSuccess = ConfigurationStatus_Rejected;
  12172. }
  12173. }
  12174. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12175. {
  12176. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12177. {
  12178. strcpy(str, (const char*)value);
  12179. for(int i = 0; str[i]; i++)
  12180. {
  12181. str[i] = tolower(str[i]);
  12182. }
  12183. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12184. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12185. isSuccess = ConfigurationStatus_Accepted;
  12186. }
  12187. else
  12188. {
  12189. isSuccess = ConfigurationStatus_Rejected;
  12190. }
  12191. }
  12192. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12193. {
  12194. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12195. {
  12196. strcpy(str, (const char*)value);
  12197. for(int i = 0; str[i]; i++)
  12198. {
  12199. str[i] = tolower(str[i]);
  12200. }
  12201. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12202. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12203. isSuccess = ConfigurationStatus_Accepted;
  12204. }
  12205. else
  12206. {
  12207. isSuccess = ConfigurationStatus_Rejected;
  12208. }
  12209. }
  12210. if(strcmp(key, "StopTxnAlignedData") == 0)
  12211. {
  12212. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12213. {
  12214. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12215. isSuccess = ConfigurationStatus_Accepted;
  12216. }
  12217. else
  12218. {
  12219. isSuccess = ConfigurationStatus_Rejected;
  12220. }
  12221. }
  12222. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12223. {
  12224. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12225. {
  12226. check_ascii = value[0];
  12227. if( (check_ascii < 48) || (check_ascii > 57) )
  12228. {
  12229. isSuccess = ConfigurationStatus_Rejected;
  12230. }
  12231. else
  12232. {
  12233. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12234. isSuccess = ConfigurationStatus_Accepted;
  12235. }
  12236. }
  12237. else
  12238. {
  12239. isSuccess = ConfigurationStatus_Rejected;
  12240. }
  12241. }
  12242. if(strcmp(key, "StopTxnSampledData") == 0)
  12243. {
  12244. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12245. {
  12246. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12247. isSuccess = ConfigurationStatus_Accepted;
  12248. }
  12249. else
  12250. {
  12251. isSuccess = ConfigurationStatus_Rejected;
  12252. }
  12253. }
  12254. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12255. {
  12256. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12257. {
  12258. check_ascii = value[0];
  12259. if( (check_ascii < 48) || (check_ascii > 57) )
  12260. {
  12261. isSuccess = ConfigurationStatus_Rejected;
  12262. }
  12263. else
  12264. {
  12265. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12266. isSuccess = ConfigurationStatus_Accepted;
  12267. }
  12268. }
  12269. else
  12270. {
  12271. isSuccess = ConfigurationStatus_Rejected;
  12272. }
  12273. }
  12274. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12275. {
  12276. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12277. {
  12278. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12279. isSuccess = ConfigurationStatus_Accepted;
  12280. }
  12281. else
  12282. {
  12283. isSuccess = ConfigurationStatus_Rejected;
  12284. }
  12285. }
  12286. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12287. {
  12288. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12289. {
  12290. check_ascii = value[0];
  12291. if( (check_ascii < 48) || (check_ascii > 57) )
  12292. {
  12293. isSuccess = ConfigurationStatus_Rejected;
  12294. }
  12295. else
  12296. {
  12297. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12298. isSuccess = ConfigurationStatus_Accepted;
  12299. }
  12300. }
  12301. else
  12302. {
  12303. isSuccess = ConfigurationStatus_Rejected;
  12304. }
  12305. }
  12306. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12307. {
  12308. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12309. {
  12310. check_ascii = value[0];
  12311. if( (check_ascii < 48) || (check_ascii > 57) )
  12312. {
  12313. isSuccess = ConfigurationStatus_Rejected;
  12314. }
  12315. else
  12316. {
  12317. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12318. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12319. TransactionMessageAttemptsValue = atoi(value);
  12320. isSuccess = ConfigurationStatus_Accepted;
  12321. }
  12322. }
  12323. else
  12324. {
  12325. isSuccess = ConfigurationStatus_Rejected;
  12326. }
  12327. }
  12328. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12329. {
  12330. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12331. {
  12332. check_ascii = value[0];
  12333. if( (check_ascii < 48) || (check_ascii > 57) )
  12334. {
  12335. isSuccess = ConfigurationStatus_Rejected;
  12336. }
  12337. else
  12338. {
  12339. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12340. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12341. TransactionMessageRetryIntervalValue = atoi(value);
  12342. isSuccess = ConfigurationStatus_Accepted;
  12343. }
  12344. }
  12345. else
  12346. {
  12347. isSuccess = ConfigurationStatus_Rejected;
  12348. }
  12349. }
  12350. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12351. {
  12352. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12353. {
  12354. strcpy(str, (const char*)value);
  12355. for(int i = 0; str[i]; i++)
  12356. {
  12357. str[i] = tolower(str[i]);
  12358. }
  12359. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12360. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12361. isSuccess = ConfigurationStatus_Accepted;
  12362. }
  12363. else
  12364. {
  12365. isSuccess = ConfigurationStatus_Rejected;
  12366. }
  12367. }
  12368. if(strcmp(key, "WebSocketPingInterval") == 0)
  12369. {
  12370. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12371. {
  12372. check_ascii = value[0];
  12373. if( (check_ascii < 48) || (check_ascii > 57) )
  12374. {
  12375. isSuccess = ConfigurationStatus_Rejected;
  12376. }
  12377. else
  12378. {
  12379. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12380. isSuccess = ConfigurationStatus_Accepted;
  12381. }
  12382. }
  12383. else
  12384. {
  12385. isSuccess = ConfigurationStatus_Rejected;
  12386. }
  12387. }
  12388. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12389. {
  12390. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12391. {
  12392. strcpy(str, (const char*)value);
  12393. for(int i = 0; str[i]; i++)
  12394. {
  12395. str[i] = tolower(str[i]);
  12396. }
  12397. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12398. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12399. isSuccess = ConfigurationStatus_Accepted;
  12400. }
  12401. else
  12402. {
  12403. isSuccess = ConfigurationStatus_Rejected;
  12404. }
  12405. }
  12406. #if 0
  12407. //For OCPP Test Case
  12408. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12409. {
  12410. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12411. {
  12412. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12413. isSuccess = ConfigurationStatus_Accepted;
  12414. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12415. }
  12416. else
  12417. {
  12418. isSuccess = ConfigurationStatus_Rejected;
  12419. }
  12420. }
  12421. #endif
  12422. #if 1
  12423. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12424. {
  12425. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12426. {
  12427. strcpy(str, (const char*)value);
  12428. for(int i = 0; str[i]; i++)
  12429. {
  12430. str[i] = tolower(str[i]);
  12431. }
  12432. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12433. isSuccess = ConfigurationStatus_Accepted;
  12434. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12435. }
  12436. else
  12437. {
  12438. isSuccess = ConfigurationStatus_Rejected;
  12439. }
  12440. }
  12441. #endif
  12442. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12443. {
  12444. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12445. {
  12446. check_ascii = value[0];
  12447. if( (check_ascii < 48) || (check_ascii > 57) )
  12448. {
  12449. isSuccess = ConfigurationStatus_Rejected;
  12450. }
  12451. else
  12452. {
  12453. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12454. isSuccess = ConfigurationStatus_Accepted;
  12455. }
  12456. }
  12457. else
  12458. {
  12459. isSuccess = ConfigurationStatus_Rejected;
  12460. }
  12461. }
  12462. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12463. {
  12464. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12465. {
  12466. check_ascii = value[0];
  12467. if( (check_ascii < 48) || (check_ascii > 57) )
  12468. {
  12469. isSuccess = ConfigurationStatus_Rejected;
  12470. }
  12471. else
  12472. {
  12473. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12474. isSuccess = ConfigurationStatus_Accepted;
  12475. }
  12476. }
  12477. else
  12478. {
  12479. isSuccess = ConfigurationStatus_Rejected;
  12480. }
  12481. }
  12482. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12483. {
  12484. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12485. {
  12486. strcpy(str, (const char*)value);
  12487. for(int i = 0; str[i]; i++)
  12488. {
  12489. str[i] = tolower(str[i]);
  12490. }
  12491. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12492. isSuccess = ConfigurationStatus_Accepted;
  12493. }
  12494. else
  12495. {
  12496. isSuccess = ConfigurationStatus_Rejected;
  12497. }
  12498. }
  12499. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12500. {
  12501. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12502. {
  12503. check_ascii = value[0];
  12504. if( (check_ascii < 48) || (check_ascii > 57) )
  12505. {
  12506. isSuccess = ConfigurationStatus_Rejected;
  12507. }
  12508. else
  12509. {
  12510. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12511. isSuccess = ConfigurationStatus_Accepted;
  12512. }
  12513. }
  12514. else
  12515. {
  12516. isSuccess = ConfigurationStatus_Rejected;
  12517. }
  12518. }
  12519. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12520. {
  12521. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12522. {
  12523. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12524. isSuccess = ConfigurationStatus_Accepted;
  12525. }
  12526. else
  12527. {
  12528. isSuccess = ConfigurationStatus_Rejected;
  12529. }
  12530. }
  12531. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12532. {
  12533. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12534. {
  12535. check_ascii = value[0];
  12536. if( (check_ascii < 48) || (check_ascii > 57) )
  12537. {
  12538. isSuccess = ConfigurationStatus_Rejected;
  12539. }
  12540. else
  12541. {
  12542. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12543. isSuccess = ConfigurationStatus_Accepted;
  12544. }
  12545. }
  12546. else
  12547. {
  12548. isSuccess = ConfigurationStatus_Rejected;
  12549. }
  12550. }
  12551. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12552. {
  12553. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12554. {
  12555. strcpy(str, (const char*)value);
  12556. for(int i = 0; str[i]; i++)
  12557. {
  12558. str[i] = tolower(str[i]);
  12559. }
  12560. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12561. isSuccess = ConfigurationStatus_Accepted;
  12562. }
  12563. else
  12564. {
  12565. isSuccess = ConfigurationStatus_Rejected;
  12566. }
  12567. }
  12568. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12569. {
  12570. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12571. {
  12572. check_ascii = value[0];
  12573. if( (check_ascii < 48) || (check_ascii > 57) )
  12574. {
  12575. isSuccess = ConfigurationStatus_Rejected;
  12576. }
  12577. else
  12578. {
  12579. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12580. isSuccess = ConfigurationStatus_Accepted;
  12581. }
  12582. }
  12583. else
  12584. {
  12585. isSuccess = ConfigurationStatus_Rejected;
  12586. }
  12587. }
  12588. return isSuccess;
  12589. }
  12590. int TransactionMessageAttemptsGet(void)
  12591. {
  12592. return TransactionMessageAttemptsValue;
  12593. }
  12594. int FirstHeartBeatResponse(void)
  12595. {
  12596. return FirstHeartBeat;
  12597. }
  12598. int TransactionMessageRetryIntervalGet(void)
  12599. {
  12600. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12601. }
  12602. int ReadHttpStatus(int sock)
  12603. {
  12604. //char c;
  12605. char buff[1024]="",*ptr=buff+1;
  12606. int bytes_received, status;
  12607. DEBUG_INFO("Begin Response ..\n");
  12608. while((bytes_received = recv(sock, ptr, 1, 0))){
  12609. if(bytes_received==-1){
  12610. perror("ReadHttpStatus");
  12611. exit(1);
  12612. }
  12613. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12614. ptr++;
  12615. }
  12616. *ptr=0;
  12617. ptr=buff+1;
  12618. sscanf(ptr,"%*s %d ", &status);
  12619. DEBUG_INFO("%s\n",ptr);
  12620. DEBUG_INFO("status=%d\n",status);
  12621. DEBUG_INFO("End Response ..\n");
  12622. return (bytes_received>0)?status:0;
  12623. }
  12624. //the only filed that it parsed is 'Content-Length'
  12625. int ParseHeader(int sock)
  12626. {
  12627. //char c;
  12628. char buff[1024]="",*ptr=buff+4;
  12629. int bytes_received;
  12630. DEBUG_INFO("Begin HEADER ..\n");
  12631. while((bytes_received = recv(sock, ptr, 1, 0))){
  12632. if(bytes_received==-1){
  12633. perror("Parse Header");
  12634. exit(1);
  12635. }
  12636. if(
  12637. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12638. (ptr[-1]=='\r') && (*ptr=='\n' )
  12639. ) break;
  12640. ptr++;
  12641. }
  12642. *ptr=0;
  12643. ptr=buff+4;
  12644. //printf("%s",ptr);
  12645. if(bytes_received){
  12646. ptr=strstr(ptr,"Content-Length:");
  12647. if(ptr){
  12648. sscanf(ptr,"%*s %d",&bytes_received);
  12649. }else
  12650. bytes_received=-1; //unknown size
  12651. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12652. }
  12653. DEBUG_INFO("End HEADER ..\n");
  12654. return bytes_received ;
  12655. }
  12656. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12657. {
  12658. char rmFileCmd[100]={0};
  12659. char FilePath[100]={0};
  12660. char ftpbuf[200];
  12661. int systemresult;
  12662. //DEBUG_INFO("filename=%s\n",filename);
  12663. //DEBUG_INFO("url=%s\n",url);
  12664. sprintf(FilePath,"/mnt/%s",filename);
  12665. if((access(FilePath,F_OK))!=-1)
  12666. {
  12667. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12668. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12669. system(rmFileCmd);
  12670. }
  12671. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12672. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12673. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12674. systemresult = system(ftpbuf);
  12675. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12676. if(systemresult != 0)
  12677. {
  12678. DEBUG_INFO("http DownLoad error!\n");
  12679. return FALSE;
  12680. }
  12681. return TRUE;
  12682. }
  12683. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12684. {
  12685. char rmFileCmd[100]={0};
  12686. char FilePath[100]={0};
  12687. char ftpbuf[200];
  12688. int systemresult;
  12689. //char temp[100];
  12690. sprintf(FilePath,"/mnt/%s",filename);
  12691. if((access(FilePath,F_OK))!=-1)
  12692. {
  12693. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12694. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12695. system(rmFileCmd);
  12696. }
  12697. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12698. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12699. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12700. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12701. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12702. systemresult = system(ftpbuf);
  12703. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12704. if(systemresult != 0)
  12705. {
  12706. printf("wget error!\n");
  12707. return FALSE;
  12708. }
  12709. return TRUE;
  12710. }
  12711. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12712. {
  12713. char rmFileCmd[100]={0};
  12714. char FilePath[100]={0};
  12715. char ftpbuf[200];
  12716. int systemresult;
  12717. //DEBUG_INFO("filename=%s\n",filename);
  12718. //DEBUG_INFO("url=%s\n",url);
  12719. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12720. if((access(FilePath,F_OK))!=-1)
  12721. {
  12722. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12723. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12724. system(rmFileCmd);
  12725. }
  12726. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12727. if(fp == NULL)
  12728. {
  12729. DEBUG_INFO("log is NULL\n");
  12730. return FALSE;
  12731. }
  12732. else
  12733. {
  12734. fprintf(fp, "%s\n", url);
  12735. fprintf(fp, "%s\n", filename);
  12736. fclose(fp);
  12737. }
  12738. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12739. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12740. systemresult = system(ftpbuf);
  12741. DEBUG_INFO("systemresult = %d\n",systemresult);
  12742. if(systemresult != 0)
  12743. {
  12744. DEBUG_INFO("http upload error!\n");
  12745. return FALSE;
  12746. }
  12747. return TRUE;
  12748. }
  12749. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12750. {
  12751. struct hostent* server;
  12752. char *IPbuffer;
  12753. char ftpbuf[200];
  12754. int systemresult;
  12755. // To retrieve host information
  12756. server = gethostbyname(location);
  12757. // To convert an Internet network
  12758. // address into ASCII string
  12759. IPbuffer = inet_ntoa(*((struct in_addr*)
  12760. server->h_addr_list[0]));
  12761. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12762. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12763. /* format : ftpput -u username -p passwd IP target source*/
  12764. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12765. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12766. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12767. systemresult = system(ftpbuf);
  12768. DEBUG_INFO("systemresult=%d\n",systemresult);
  12769. if(systemresult != 0)
  12770. {
  12771. DEBUG_INFO("ftpput error!\n");
  12772. return FALSE;
  12773. }
  12774. return TRUE;
  12775. }
  12776. /**
  12777. * Place the contents of the specified file into a memory buffer
  12778. *
  12779. * @param[in] filename The path and name of the file to read
  12780. * @param[out] filebuffer A pointer to the contents in memory
  12781. * @return status 0 success, 1 on failure
  12782. */
  12783. int get_file_contents(const char* filename, char** outbuffer) {
  12784. FILE* file = NULL;
  12785. long filesize;
  12786. const int blocksize = 1;
  12787. size_t readsize;
  12788. char* filebuffer;
  12789. // Open the file
  12790. file = fopen(filename, "r");
  12791. if (NULL == file)
  12792. {
  12793. printf("'%s' not opened\n", filename);
  12794. exit(EXIT_FAILURE);
  12795. }
  12796. // Determine the file size
  12797. fseek(file, 0, SEEK_END);
  12798. filesize = ftell(file);
  12799. rewind (file);
  12800. // Allocate memory for the file contents
  12801. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12802. *outbuffer = filebuffer;
  12803. if (filebuffer == NULL)
  12804. {
  12805. fputs ("malloc out-of-memory", stderr);
  12806. exit(EXIT_FAILURE);
  12807. }
  12808. // Read in the file
  12809. readsize = fread(filebuffer, blocksize, filesize, file);
  12810. if (readsize != filesize)
  12811. {
  12812. fputs ("didn't read file completely",stderr);
  12813. exit(EXIT_FAILURE);
  12814. }
  12815. // Clean exit
  12816. fclose(file);
  12817. return EXIT_SUCCESS;
  12818. }
  12819. static int selectSqlCount = 0;
  12820. static int callback(void *data, int argc, char **argv, char **azColName){
  12821. int i;
  12822. //printf("%s: ", (const char*)data);
  12823. selectSqlCount = argc;
  12824. for(i = 0; i<argc; i++){
  12825. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12826. }
  12827. //printf("\n");
  12828. return 0;
  12829. }
  12830. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12831. //int i;
  12832. //printf("%s:\n", (const char*)data);
  12833. localversion = argv[5] ? atoi(argv[5]) : 0;
  12834. //printf("localversion=%d\n", localversion);
  12835. return 0;
  12836. }
  12837. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12838. //int i;
  12839. //printf("%s:\n", (const char*)data);
  12840. //idTag
  12841. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12842. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12843. //parentIdTag
  12844. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12845. //expir_date
  12846. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12847. //status
  12848. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12849. //version
  12850. idTagQuery.listVersionInt = atoi(argv[5]);
  12851. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12852. return 0;
  12853. }
  12854. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12855. {
  12856. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12857. // printf("localversion=%d\n", localversion);
  12858. return 0;
  12859. }
  12860. //=========================================
  12861. // Sqlite3 related function
  12862. //=========================================
  12863. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12864. {
  12865. for (int i = 0; i < n_columns; i++)
  12866. {
  12867. DEBUG_INFO("%s/t", col_values[i]);
  12868. }
  12869. DEBUG_INFO("/n");
  12870. return 0;
  12871. }
  12872. void OCPP_getListVerion()
  12873. {
  12874. int rc = 0;
  12875. // const char* data = "Callback function called";
  12876. char sql[100];
  12877. char zErrMsg[100];
  12878. memset(sql, 0, 100);
  12879. memset(zErrMsg, 0, 100);
  12880. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12881. /* Execute SQL statement */
  12882. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12883. if( rc != SQLITE_OK )
  12884. {
  12885. DEBUG_INFO("SQL error: %s", zErrMsg);
  12886. }
  12887. }
  12888. void OCPP_getIdTag(char idTag[])
  12889. {
  12890. int rc = 0;
  12891. // const char* data = "Callback function called";
  12892. char sql[100];
  12893. char zErrMsg[100];
  12894. memset(sql, 0, 100);
  12895. memset(zErrMsg, 0, 100);
  12896. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  12897. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12898. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12899. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12900. /* Execute SQL statement */
  12901. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12902. if( rc != SQLITE_OK )
  12903. {
  12904. DEBUG_INFO("SQL error: %s", zErrMsg);
  12905. }
  12906. //return ver;
  12907. }
  12908. void OCPP_get_TableAuthlocalAllData(void)
  12909. {
  12910. int rc = 0;
  12911. char sql[100];
  12912. char zErrMsg[100];
  12913. memset(sql, 0, 100);
  12914. memset(zErrMsg, 0, 100);
  12915. sprintf(sql,"select * from ocpp_auth_local ");
  12916. /* Execute SQL statement */
  12917. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12918. if( rc != SQLITE_OK )
  12919. {
  12920. DEBUG_INFO("SQL error: %s", zErrMsg);
  12921. }
  12922. //return ver;
  12923. }
  12924. int OCPP_cleanLocalList()
  12925. {
  12926. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12927. char *errMsg = 0;
  12928. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12929. if (SQLITE_OK != rc)
  12930. {
  12931. DEBUG_INFO("%s\n",errMsg);
  12932. return FALSE;
  12933. }
  12934. return TRUE;
  12935. }
  12936. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12937. {
  12938. int isSuccess = FALSE;
  12939. int ret = 0;
  12940. //const char* data = "Callback function called";
  12941. char sql[300];
  12942. char zErrMsg[200];
  12943. memset(sql, 0, 300);
  12944. memset(zErrMsg, 0, 200);
  12945. 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);
  12946. //* Execute SQL statement */
  12947. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12948. if( ret != SQLITE_OK )
  12949. {
  12950. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12951. return isSuccess;
  12952. }
  12953. memset(sql, 0, 300);
  12954. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  12955. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  12956. if( ret != SQLITE_OK )
  12957. {
  12958. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12959. return isSuccess;
  12960. }
  12961. isSuccess = TRUE;
  12962. return isSuccess;
  12963. }
  12964. void OCPP_deleteIdTag(char idTag[])
  12965. {
  12966. //int ver = 0;
  12967. //int isSuccess = FALSE;
  12968. int rc = 0;
  12969. char sql[100];
  12970. char zErrMsg[100];
  12971. memset(sql, 0, 100);
  12972. memset(zErrMsg, 0, 100);
  12973. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12974. //* Execute SQL statement */
  12975. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12976. if( rc != SQLITE_OK )
  12977. {
  12978. DEBUG_INFO("SQL error: %s", zErrMsg);
  12979. }
  12980. }
  12981. int GetOcppServerURL()
  12982. {
  12983. int result = FALSE;
  12984. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  12985. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  12986. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  12987. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12988. {
  12989. #if 1
  12990. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12991. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12992. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12993. #endif
  12994. result = TRUE;
  12995. goto End;
  12996. }
  12997. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12998. {
  12999. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13000. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13001. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13002. result = TRUE;
  13003. goto End;
  13004. }
  13005. else
  13006. {
  13007. strcpy(OcppHost,"");
  13008. }
  13009. End:
  13010. return result;
  13011. }
  13012. int GetOcppPath()
  13013. {
  13014. int result = FALSE;
  13015. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13016. {
  13017. if(OcppTempPath == NULL)
  13018. {
  13019. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13020. }
  13021. else
  13022. {
  13023. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13024. }
  13025. result = TRUE;
  13026. goto End;
  13027. }
  13028. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13029. {
  13030. if(OcppTempPath == NULL)
  13031. {
  13032. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13033. }
  13034. else
  13035. {
  13036. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13037. }
  13038. result = TRUE;
  13039. goto End;
  13040. }
  13041. else
  13042. {
  13043. strcpy(OcppPath,"");
  13044. }
  13045. End:
  13046. return result;
  13047. }
  13048. int GetOcppPort()
  13049. {
  13050. return OcppPort;
  13051. }
  13052. int GetOcppConnStatus(void)
  13053. {
  13054. return ShmOCPP16Data->OcppConnStatus;
  13055. }
  13056. void SetOcppConnStatus(uint8_t status)
  13057. {
  13058. ShmOCPP16Data->OcppConnStatus = status;
  13059. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13060. }
  13061. int GetHeartBeatWithNOResponse(void)
  13062. {
  13063. return HeartBeatWithNOResponse;
  13064. }
  13065. void SetHeartBeatWithNOResponse(void)
  13066. {
  13067. HeartBeatWithNOResponse = 0;
  13068. }
  13069. void GetStartTransactionIdTag(int gun_index)
  13070. {
  13071. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13072. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13073. }
  13074. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13075. {
  13076. char ch;
  13077. FILE *fptr1;
  13078. int temptransactionId;
  13079. char str[100]={0};
  13080. temptransactionId = 0;
  13081. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  13082. {
  13083. DEBUG_INFO("IdTag is empty.\n");
  13084. return temptransactionId;
  13085. }
  13086. /*------ Read the file ----------------*/
  13087. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13088. if (!fptr1)
  13089. {
  13090. DEBUG_INFO("QueueTransactionId file open error.\n");
  13091. //printf(" File not found or unable to open the input file!!\n");
  13092. return temptransactionId;
  13093. }
  13094. ch=fgetc(fptr1);
  13095. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13096. rewind(fptr1);
  13097. if(ch!=EOF)
  13098. {
  13099. // printf("%c",ch);
  13100. while (fgets(str, 100, fptr1) != NULL)
  13101. {
  13102. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13103. if(str[0]=='\0')
  13104. {
  13105. break;
  13106. }
  13107. char *revbuf[8] = {0}; //存放分割後的子字串
  13108. int num = 0;//分割後子字串的個數
  13109. DEBUG_INFO("str: %s\n", str);
  13110. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13111. DEBUG_INFO("revbuf[0]: %s\n", revbuf[0]);
  13112. DEBUG_INFO("revbuf[1]: %s\n", revbuf[1]);
  13113. DEBUG_INFO("revbuf[2]: %s\n", revbuf[2]);
  13114. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13115. {
  13116. if(isStopTransaction)
  13117. {
  13118. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13119. {
  13120. temptransactionId = atoi(revbuf[2]);
  13121. break;
  13122. }
  13123. }
  13124. else
  13125. {
  13126. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13127. {
  13128. temptransactionId = atoi(revbuf[2]);
  13129. break;
  13130. }
  13131. }
  13132. }
  13133. }
  13134. }
  13135. else
  13136. DEBUG_INFO("EOF\n");
  13137. fclose(fptr1);
  13138. /*------- End of reading ---------------*/
  13139. return temptransactionId;
  13140. }
  13141. void SetTransactionIdZero(int transactionId)
  13142. {
  13143. char ch;
  13144. FILE *fptr1, *fptr2;
  13145. int temptransactionId = 0;
  13146. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13147. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13148. if (!fptr1)
  13149. {
  13150. //printf(" File not found or unable to open the input file!!\n");
  13151. return ;
  13152. }
  13153. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13154. if (!fptr2)
  13155. {
  13156. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13157. fclose(fptr1);
  13158. return ;
  13159. }
  13160. ch=fgetc(fptr1);
  13161. rewind(fptr1);
  13162. if(ch!=EOF)
  13163. {
  13164. // copy all contents to the temporary file except the specific line
  13165. while (fgets(str, 100, fptr1) != NULL)
  13166. {
  13167. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13168. if(str[0]=='\0')
  13169. {
  13170. break;
  13171. }
  13172. char *revbuf[8] = {0};
  13173. int num = 0;
  13174. strcpy(strtemp, str);
  13175. splitstring(str,",",revbuf,&num);
  13176. if(revbuf[2][0] != '\0')
  13177. {
  13178. temptransactionId = atoi(revbuf[2]);
  13179. if(transactionId != temptransactionId)
  13180. {
  13181. fprintf(fptr2, "%s\n", strtemp);
  13182. }
  13183. }
  13184. }
  13185. }
  13186. fclose(fptr1);
  13187. fclose(fptr2);
  13188. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13189. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13190. /*------ Read the file ----------------*/
  13191. }
  13192. int InternetDisconnect(void)
  13193. {
  13194. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13195. }
  13196. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13197. void storeTempStopTransaction(int gun_index)
  13198. {
  13199. char guid[37]={0};
  13200. int tempIndex = 0;
  13201. DEBUG_INFO("storeTempStopTransaction...\n");
  13202. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13203. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13204. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13205. if(gunType[gun_index] == 'J')
  13206. {
  13207. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13208. {
  13209. tempIndex = ((gun_index==2) ? 1: 0);
  13210. }
  13211. else
  13212. {
  13213. tempIndex = gun_index;
  13214. }
  13215. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13216. {
  13217. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13218. {
  13219. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13220. }
  13221. }// END OF CHAdeMO_QUANTITY
  13222. }
  13223. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13224. {
  13225. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13226. {
  13227. tempIndex = ((gun_index==2) ? 1: 0);
  13228. }
  13229. else
  13230. {
  13231. tempIndex = gun_index;
  13232. }
  13233. for (int index = 0; index < CCS_QUANTITY; index++)
  13234. {
  13235. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13236. {
  13237. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13238. }
  13239. }// END OF CCS_QUANTITY
  13240. }
  13241. else if(gunType[gun_index] == 'G')
  13242. {
  13243. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13244. {
  13245. tempIndex = ((gun_index==2) ? 1: 0);
  13246. }
  13247. else
  13248. {
  13249. tempIndex = gun_index;
  13250. }
  13251. for (int index = 0; index < GB_QUANTITY; index++)
  13252. {
  13253. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13254. {
  13255. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13256. }
  13257. }// END OF GB_QUANTITY
  13258. }
  13259. else
  13260. {
  13261. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13262. {
  13263. tempIndex = 2;
  13264. }
  13265. else
  13266. {
  13267. tempIndex = gun_index;
  13268. }
  13269. for (int index = 0; index < AC_QUANTITY; index++)
  13270. {
  13271. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13272. {
  13273. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13274. }
  13275. }// END OF AC_QUANTITY
  13276. }
  13277. //Stop Transaction Time
  13278. struct timeval tmnow;
  13279. struct tm *tm;
  13280. char buf[28];//, usec_buf[6];
  13281. gettimeofday(&tmnow, NULL);
  13282. time_t t;
  13283. t = time(NULL);
  13284. /*UTC time and date*/
  13285. tm = gmtime(&t);
  13286. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13288. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13289. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13290. random_uuid(guid);
  13291. /***********************************transactionData******************************************************/
  13292. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13293. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13294. //=================================
  13295. //1. Transaction_Begin
  13296. //=================================
  13297. //============================== Energy.Active.Import.Interval ===========================================
  13298. //idx_sample=0;
  13299. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  13300. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13301. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13302. 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*/]);
  13303. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13304. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13305. {
  13306. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13307. }
  13308. else
  13309. {
  13310. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13311. }
  13312. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13313. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13314. //=================================
  13315. //2. Transaction_End
  13316. //=================================
  13317. //2.1====================================== Current.Import L1 ==============================================
  13318. //idx_sample=1;
  13319. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13320. if(gunType[gun_index] == 'J')
  13321. {
  13322. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13323. {
  13324. tempIndex = ((gun_index==2) ? 1: 0);
  13325. }
  13326. else
  13327. {
  13328. tempIndex = gun_index;
  13329. }
  13330. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13331. {
  13332. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13333. {
  13334. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13335. }
  13336. }// End of for CHAdeMO_QUANTITY
  13337. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13338. }
  13339. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13340. {
  13341. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13342. {
  13343. tempIndex = ((gun_index==2) ? 1: 0);
  13344. }
  13345. else
  13346. {
  13347. tempIndex = gun_index;
  13348. }
  13349. for (int index = 0; index < CCS_QUANTITY; index++)
  13350. {
  13351. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13352. {
  13353. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13354. }
  13355. }// End of for CCS_QUANTITY
  13356. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13357. }
  13358. else if(gunType[gun_index] == 'G')
  13359. {
  13360. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13361. {
  13362. tempIndex = ((gun_index==2) ? 1: 0);
  13363. }
  13364. else
  13365. {
  13366. tempIndex = gun_index;
  13367. }
  13368. for (int index = 0; index < GB_QUANTITY; index++)
  13369. {
  13370. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13371. {
  13372. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13373. }
  13374. }// End of for GB_QUANTITY
  13375. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13376. }
  13377. else
  13378. {
  13379. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13380. {
  13381. tempIndex = 2;
  13382. }
  13383. else
  13384. {
  13385. tempIndex = gun_index;
  13386. }
  13387. for (int index = 0; index < AC_QUANTITY; index++)
  13388. {
  13389. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13390. {
  13391. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13392. }
  13393. }// End of for AC_QUANTITY
  13394. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13395. }
  13396. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13397. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13398. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13399. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13400. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13401. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13402. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13403. //idx_sample=2;
  13404. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13405. if(gunType[gun_index] == 'J')
  13406. {
  13407. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13408. {
  13409. tempIndex = ((gun_index==2) ? 1: 0);
  13410. }
  13411. else
  13412. {
  13413. tempIndex = gun_index;
  13414. }
  13415. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13416. {
  13417. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13418. {
  13419. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13420. }
  13421. }// END OF CHAdeMO_QUANTITY
  13422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13423. }
  13424. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13425. {
  13426. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13427. {
  13428. tempIndex = ((gun_index==2) ? 1: 0);
  13429. }
  13430. else
  13431. {
  13432. tempIndex = gun_index;
  13433. }
  13434. for (int index = 0; index < CCS_QUANTITY; index++)
  13435. {
  13436. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13437. {
  13438. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13439. }
  13440. }// END OF CCS_QUANTITY
  13441. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13442. }
  13443. else if(gunType[gun_index] == 'G')
  13444. {
  13445. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13446. {
  13447. tempIndex = ((gun_index==2) ? 1: 0);
  13448. }
  13449. else
  13450. {
  13451. tempIndex = gun_index;
  13452. }
  13453. for (int index = 0; index < GB_QUANTITY; index++)
  13454. {
  13455. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13456. {
  13457. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13458. }
  13459. }// END OF GB_QUANTITY
  13460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13461. }
  13462. else
  13463. {
  13464. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13465. {
  13466. tempIndex = 2;
  13467. }
  13468. else
  13469. {
  13470. tempIndex = gun_index;
  13471. }
  13472. for (int index = 0; index < AC_QUANTITY; index++)
  13473. {
  13474. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13475. {
  13476. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13477. }
  13478. }// END OF AC_QUANTITY
  13479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13480. }
  13481. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13482. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13484. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13487. //2.3====================================== Power.Active.Import =========================================
  13488. //idx_sample=3;
  13489. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13490. if(gunType[gun_index] == 'J')
  13491. {
  13492. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13493. {
  13494. tempIndex = ((gun_index==2) ? 1: 0);
  13495. }
  13496. else
  13497. {
  13498. tempIndex = gun_index;
  13499. }
  13500. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13501. {
  13502. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13503. {
  13504. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13505. }
  13506. } // End for CHAdeMO_QUANTITY
  13507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13508. }
  13509. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13510. {
  13511. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13512. {
  13513. tempIndex = ((gun_index==2) ? 1: 0);
  13514. }
  13515. else
  13516. {
  13517. tempIndex = gun_index;
  13518. }
  13519. for (int index = 0; index < CCS_QUANTITY; index++)
  13520. {
  13521. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13522. {
  13523. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13524. }
  13525. } // END for CCS_QUANTITY
  13526. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13527. }
  13528. else if(gunType[gun_index] == 'G')
  13529. {
  13530. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13531. {
  13532. tempIndex = ((gun_index==2) ? 1: 0);
  13533. }
  13534. else
  13535. {
  13536. tempIndex = gun_index;
  13537. }
  13538. for (int index = 0; index < GB_QUANTITY; index++)
  13539. {
  13540. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13541. {
  13542. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13543. }
  13544. }// END for GB_QUANTITY
  13545. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13546. }
  13547. else
  13548. {
  13549. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13550. {
  13551. tempIndex = 2;
  13552. }
  13553. else
  13554. {
  13555. tempIndex = gun_index;
  13556. }
  13557. for (int index = 0; index < AC_QUANTITY; index++)
  13558. {
  13559. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13560. {
  13561. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13562. }
  13563. } // END for AC_QUANTITY
  13564. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13565. }
  13566. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13567. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13568. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13569. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13570. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13571. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13572. //2.4====================================== Voltage L1 ====================================================
  13573. //idx_sample=4;
  13574. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13575. if(gunType[gun_index] == 'J')
  13576. {
  13577. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13578. {
  13579. tempIndex = ((gun_index==2) ? 1: 0);
  13580. }
  13581. else
  13582. {
  13583. tempIndex = gun_index;
  13584. }
  13585. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13586. {
  13587. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13588. {
  13589. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13590. }
  13591. } // END OF FOR CHAdeMO_QUANTITY
  13592. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13593. }
  13594. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13595. {
  13596. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13597. {
  13598. tempIndex = ((gun_index==2) ? 1: 0);
  13599. }
  13600. else
  13601. {
  13602. tempIndex = gun_index;
  13603. }
  13604. for (int index = 0; index < CCS_QUANTITY; index++)
  13605. {
  13606. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13607. {
  13608. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13609. }
  13610. } // END OF FOR CCS_QUANTITY
  13611. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13612. }
  13613. else if(gunType[gun_index] == 'G')
  13614. {
  13615. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13616. {
  13617. tempIndex = ((gun_index==2) ? 1: 0);
  13618. }
  13619. else
  13620. {
  13621. tempIndex = gun_index;
  13622. }
  13623. for (int index = 0; index < GB_QUANTITY; index++)
  13624. {
  13625. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13626. {
  13627. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13628. }
  13629. } // END OF FOR GB_QUANTITY
  13630. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13631. }
  13632. else
  13633. {
  13634. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13635. {
  13636. tempIndex = 2;
  13637. }
  13638. else
  13639. {
  13640. tempIndex = gun_index;
  13641. }
  13642. for (int index = 0; index < AC_QUANTITY; index++)
  13643. {
  13644. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13645. {
  13646. 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
  13647. }
  13648. } // END OF FOR AC_QUANTITY
  13649. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13650. }
  13651. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13652. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13653. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13654. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13655. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13656. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13657. //2.5============================================== SoC =========================================================
  13658. //idx_sample=5;
  13659. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13660. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13661. {
  13662. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13663. {
  13664. tempIndex = ((gun_index==2) ? 1: 0);
  13665. }
  13666. else
  13667. {
  13668. tempIndex = gun_index;
  13669. }
  13670. if(gunType[gun_index] == 'J')
  13671. {
  13672. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13673. {
  13674. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13675. {
  13676. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13677. }
  13678. }
  13679. }
  13680. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13681. {
  13682. for (int index = 0; index < CCS_QUANTITY; index++)
  13683. {
  13684. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13685. {
  13686. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13687. }
  13688. }
  13689. }
  13690. else if(gunType[gun_index] == 'G')
  13691. {
  13692. for (int index = 0; index < GB_QUANTITY; index++)
  13693. {
  13694. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13695. {
  13696. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13697. }
  13698. }
  13699. }
  13700. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13701. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13702. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13703. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13704. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  13705. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13706. } // END FOR DC CASE
  13707. //2.6====================================== Current.Import L2 ==============================================
  13708. // idx_sample=6;
  13709. // AC 3 phase L2 current
  13710. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13711. {
  13712. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13713. {
  13714. tempIndex = 2;
  13715. }
  13716. else
  13717. {
  13718. tempIndex = gun_index;
  13719. }
  13720. for (int index = 0; index < AC_QUANTITY; index++)
  13721. {
  13722. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13723. {
  13724. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  13725. }
  13726. }// End of for AC_QUANTITY
  13727. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  13728. }
  13729. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13730. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  13731. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  13732. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  13733. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13734. //2.7====================================== Current.Import L3 ==============================================
  13735. // idx_sample=7;
  13736. // AC 3 phase L3 current
  13737. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13738. {
  13739. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13740. {
  13741. tempIndex = 2;
  13742. }
  13743. else
  13744. {
  13745. tempIndex = gun_index;
  13746. }
  13747. for (int index = 0; index < AC_QUANTITY; index++)
  13748. {
  13749. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13750. {
  13751. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  13752. }
  13753. }// End of for AC_QUANTITY
  13754. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  13755. }
  13756. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13757. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  13758. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  13759. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  13760. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13761. //2.9====================================== Voltage L2 ====================================================
  13762. //idx_sample=8;
  13763. // AC 3 phase L2 volatge
  13764. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13765. {
  13766. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13767. {
  13768. tempIndex = 2;
  13769. }
  13770. else
  13771. {
  13772. tempIndex = gun_index;
  13773. }
  13774. for (int index = 0; index < AC_QUANTITY; index++)
  13775. {
  13776. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13777. {
  13778. 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
  13779. }
  13780. } // END OF FOR AC_QUANTITY
  13781. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  13782. }
  13783. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13784. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  13785. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  13786. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  13787. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13788. //2.10====================================== Voltage L3 ====================================================
  13789. //idx_sample=9;
  13790. // AC 3 phase L3 volatge
  13791. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13792. {
  13793. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13794. {
  13795. tempIndex = 2;
  13796. }
  13797. else
  13798. {
  13799. tempIndex = gun_index;
  13800. }
  13801. for (int index = 0; index < AC_QUANTITY; index++)
  13802. {
  13803. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13804. {
  13805. 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
  13806. }
  13807. } // END OF FOR AC_QUANTITY
  13808. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  13809. }
  13810. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13811. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  13812. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  13813. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  13814. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13815. //======================================== Message create ==============================================
  13816. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13817. {
  13818. 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\"}]}]}]"
  13819. ,gun_index+1
  13820. ,MESSAGE_TYPE_CALL
  13821. ,guid
  13822. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13823. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13824. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13825. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13826. ,"PowerLoss"
  13827. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13828. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13829. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13830. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13831. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13832. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13833. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13834. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13835. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13836. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13837. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13838. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13839. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13840. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13841. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13842. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13843. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13844. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13845. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13846. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13847. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13848. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13849. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13850. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13851. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13852. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13853. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13854. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13855. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13856. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13857. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13858. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13859. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13860. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13861. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13862. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13863. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  13864. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  13865. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  13866. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  13867. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  13868. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  13869. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  13870. );
  13871. }
  13872. else
  13873. {
  13874. if(((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W')))
  13875. {
  13876. 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\"}]}]}]"
  13877. ,gun_index+1
  13878. ,MESSAGE_TYPE_CALL
  13879. ,guid
  13880. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13881. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13882. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13884. ,"PowerLoss"
  13885. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13890. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13894. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13895. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13896. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13897. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13898. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13899. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13900. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13901. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13902. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13903. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13904. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13905. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13906. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13907. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13908. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13909. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13910. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13911. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13912. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13913. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13914. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13915. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13916. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13917. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13918. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13919. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13920. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13921. );
  13922. }
  13923. else
  13924. {
  13925. 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\"}]}]}]"
  13926. ,gun_index+1
  13927. ,MESSAGE_TYPE_CALL
  13928. ,guid
  13929. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13930. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13931. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13932. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13933. ,"PowerLoss"
  13934. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13935. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13936. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13937. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13938. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13939. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13940. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13941. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13942. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13943. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13944. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13945. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13946. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13947. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13948. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13949. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13950. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13951. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13952. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13953. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13954. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13955. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13956. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13957. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13958. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13959. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13960. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13961. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13962. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13963. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13964. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13965. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13966. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13967. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13968. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13969. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13970. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  13971. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  13972. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  13973. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  13974. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  13975. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  13976. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  13977. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  13978. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  13979. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  13980. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  13981. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  13982. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  13983. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  13984. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  13985. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  13986. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  13987. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  13988. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  13989. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  13990. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  13991. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  13992. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  13993. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  13994. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  13995. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  13996. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  13997. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  13998. );
  13999. }
  14000. }
  14001. // Check File "TempStopTransaction" Exist
  14002. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  14003. {
  14004. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14005. fclose(fopen("/Storage/OCPP/TempStopTransaction", "w"));
  14006. }
  14007. else
  14008. {
  14009. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  14010. FILE *log = fopen("/Storage/OCPP/TempStopTransaction", "w+");
  14011. if(log == NULL)
  14012. {
  14013. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  14014. return ;
  14015. }
  14016. else
  14017. {
  14018. fclose(log);
  14019. }
  14020. }
  14021. //Add TempStopTransaction | Update TempStopTransaction
  14022. // open file for writing
  14023. FILE *outfile;
  14024. outfile = fopen ("/Storage/OCPP/TempStopTransaction", "a");
  14025. //DEBUG_INFO("data = %s\n", queuedata);
  14026. fputs(queuedata, outfile);
  14027. fputs("\n", outfile);
  14028. fclose (outfile);
  14029. }
  14030. void checkTempStopTransaction(int gun_index)
  14031. {
  14032. FILE *fptr1;
  14033. char ch;
  14034. char str[QUEUE_MESSAGE_LENGTH]={0};
  14035. char guid[37]={0};
  14036. char tempdata[65]={0};
  14037. char connectorStr[2]={0};
  14038. fptr1 = fopen("/Storage/OCPP/TempStopTransaction", "r");
  14039. //TempStopTransaction格式: 槍號,StopTransaction封包
  14040. if (!fptr1)
  14041. {
  14042. //printf(" File not found or unable to open the input file!!\n");
  14043. return ;
  14044. }
  14045. ch=fgetc(fptr1);
  14046. //printf(" Now the content of the file %s is : \n",fname);
  14047. rewind(fptr1);
  14048. if(ch!=EOF)
  14049. {
  14050. // copy all contents to the temporary file except the specific line
  14051. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14052. {
  14053. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14054. if(str[0]=='\0')
  14055. {
  14056. break;
  14057. }
  14058. //TempStopTransaction格式: 槍號,StopTransaction封包
  14059. strncpy(connectorStr, str, 1);
  14060. if(atoi(connectorStr) != (gun_index+1))
  14061. {
  14062. DEBUG_INFO("atoi(connectorStr) = %d\n", atoi(connectorStr));
  14063. return ;
  14064. }
  14065. //random_uuid(guid);
  14066. strncpy(guid, str+6, 36); //copy guid
  14067. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14068. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14069. {
  14070. DEBUG_INFO("StopTransaction mapitem pass\n");
  14071. }
  14072. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14073. memset(str,0,ARRAY_SIZE(str));
  14074. }
  14075. }
  14076. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14077. fclose(fptr1);
  14078. remove("/Storage/OCPP/TempStopTransaction"); // remove the original file
  14079. }
  14080. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14081. {
  14082. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14083. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14084. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14085. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14086. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14087. }
  14088. int GetWebSocketPingInterval(void)
  14089. {
  14090. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14091. }
  14092. int GetServerSign(void)
  14093. {
  14094. return server_sign;
  14095. }
  14096. void SetServerSign(int value)
  14097. {
  14098. server_sign = value;
  14099. }
  14100. int GetBootNotificationInterval(void)
  14101. {
  14102. return BootNotificationInterval;
  14103. }
  14104. int GetInternetConn(void)
  14105. {
  14106. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14107. }
  14108. void InitialSystemValue(void)
  14109. {
  14110. int connectorIndex = 0;
  14111. //int valueASCII = 0;
  14112. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14113. gunTotalNumber=0;
  14114. SystemInitial = 0;
  14115. localversion=0;
  14116. BootNotificationInterval = 0;
  14117. authorizeRetryTimes = 0;
  14118. GunStatusInterval = 10;
  14119. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14120. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14121. //Hear Beat
  14122. HeartBeatWithNOResponse = 0;
  14123. HeartBeatCountPerHour = 0;
  14124. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14125. FirstHeartBeat = 0;
  14126. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14127. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14128. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14129. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14130. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14131. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14132. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14133. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14134. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14135. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14136. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14137. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14138. memset(gunType, 0, ARRAY_SIZE(gunType));
  14139. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14140. {
  14141. //check connector / socket type (index: 8, 9, 10)
  14142. for(int index=7; index <10 ; index++)
  14143. {
  14144. if(index != 8)
  14145. {
  14146. // DC Connector
  14147. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  14148. {
  14149. SystemInitial = SystemInitial + 1;
  14150. gunTotalNumber = gunTotalNumber + 1;
  14151. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14152. connectorIndex = connectorIndex + 1;
  14153. }
  14154. }
  14155. else
  14156. {
  14157. // AC Connector
  14158. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14159. {
  14160. SystemInitial = SystemInitial + 1;
  14161. gunTotalNumber = gunTotalNumber + 1;
  14162. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14163. connectorIndex = connectorIndex + 1;
  14164. }
  14165. }
  14166. }
  14167. //DEBUG_INFO("DC ...\n");
  14168. }
  14169. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14170. {
  14171. //check connector / socket type (index: 8, 9, 10)
  14172. for(int index=7; index <10 ; index++)
  14173. {
  14174. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14175. {
  14176. SystemInitial = SystemInitial + 1;
  14177. gunTotalNumber = gunTotalNumber + 1;
  14178. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14179. connectorIndex = connectorIndex + 1;
  14180. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14181. }
  14182. }
  14183. }
  14184. //Status && ConnectorPlugIn Setting
  14185. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14186. {
  14187. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14188. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14189. }
  14190. for (int index = 0; index < CCS_QUANTITY; index++)
  14191. {
  14192. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14193. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14194. }
  14195. for (int index = 0; index < GB_QUANTITY; index++)
  14196. {
  14197. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14198. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14199. }
  14200. for (int index = 0; index < AC_QUANTITY; index++)
  14201. {
  14202. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14203. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14204. }
  14205. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14206. {
  14207. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14208. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14209. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14210. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14211. }
  14212. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14213. clientTime.Heartbeat=time((time_t*)NULL);
  14214. sleep(1);
  14215. }
  14216. void LWS_Send(char * str)
  14217. {
  14218. //=====================================================
  14219. // Check InternetConn 0: disconnected, 1: connected
  14220. //====================================================
  14221. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14222. {
  14223. DEBUG_INFO("offline now !!!\n");
  14224. return;
  14225. }
  14226. pthread_mutex_lock(&lock_send);
  14227. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14228. sprintf((char *)SendBuffer, "%s", str);
  14229. SendBufLen = strlen(str);
  14230. pthread_mutex_unlock(&lock_send);
  14231. lws_callback_on_writable(wsi_client);
  14232. //lws_service(context, 0);
  14233. //sleep(1);
  14234. }