MessageHandler.c 672 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. #define TxDefaultProfile_1_JSON "/Storage/OCPP/TxDefaultProfile_1.json"
  8. #define TxDefaultProfile_2_JSON "/Storage/OCPP/TxDefaultProfile_2.json"
  9. //TxProfile
  10. #define TxProfile_1_JSON "/Storage/OCPP/TxProfile_1.json"
  11. #define TxProfile_2_JSON "/Storage/OCPP/TxProfile_2.json"
  12. #define ChargingProfile_0_JSON "/Storage/OCPP/chargingprofile_0.json"
  13. #define ChargingProfile_1_JSON "/Storage/OCPP/chargingprofile_1.json"
  14. #define ChargingProfile_2_JSON "/Storage/OCPP/chargingprofile_2.json"
  15. #define AuthorizationCache_JSON "/Storage/OCPP/AuthorizationCache.json"
  16. #define LocalAuthorizationList_JSON "/Storage/OCPP/LocalAuthorizationList.json"
  17. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  18. struct StatusCodeData *ShmStatusCodeData;
  19. struct PsuData *ShmPsuData ;
  20. struct OCPP16Data *ShmOCPP16Data;
  21. //ConfigurationMaxKeys
  22. #define GetConfigurationMaxKeysNUM 44
  23. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  24. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  25. //=================================
  26. // StatusNotification cycle
  27. //=================================
  28. static int server_cycle_Status = 120;
  29. //===============================
  30. // Configuration: unknownkey
  31. //===============================
  32. static char unknownkey[10][20] = {0};
  33. static int UnknownKeynum = 0;
  34. //===============================
  35. // Gun Total Numbers
  36. //===============================
  37. static int gunTotalNumber = 0;
  38. static uint8_t gunType[4] = {0};
  39. //===============================
  40. // Local List Version
  41. //===============================
  42. static int localversion=0;
  43. static char idTagAuthorization[32] = {0};
  44. //===============================
  45. // OCPP sign variable
  46. //===============================
  47. static int server_sign = FALSE;
  48. int server_pending = FALSE;
  49. static int BootNotificationInterval = 0;
  50. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  51. //===============================
  52. // OCPP auth variable
  53. //===============================
  54. static int authorizeRetryTimes = 0; //number of Retry times
  55. //===============================
  56. // OCPP other variables
  57. //===============================
  58. static int HeartBeatWaitTime = 10;
  59. static int FirstHeartBeat = 0;
  60. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  61. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  62. static char CurrentChargingProfileScheduleStr[30] = {0};
  63. //========================================
  64. // OCPP status/previous related variables
  65. //========================================
  66. static int GunStatusInterval = 10;
  67. static uint8_t statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  68. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  69. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  70. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  71. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  72. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  73. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  74. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  75. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  76. static int TransactionMessageAttemptsValue = 0;
  77. static int TransactionMessageRetryIntervalValue = 0;
  78. static int TempMeterValueInterval = 0;
  79. static struct OCPPAuthLocalElemet
  80. {
  81. int listVersionInt;
  82. char idTagstr[20];
  83. char parentIdTag[20];
  84. char expiryDate[30];
  85. char idTagstatus[16];
  86. }idTagQuery;
  87. //=============================================
  88. // OCPP HeartBeat Response Not Receive Counts
  89. //============================================
  90. static int HeartBeatWithNOResponse = 0;
  91. static int HeartBeatCountPerHour = 0;
  92. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  93. extern int GetTransactionQueueNum(void);
  94. extern struct Charger_Info Charger;
  95. extern sqlite3 *db;
  96. int TransactionMessageAttemptsGet(void);
  97. int TransactionMessageRetryIntervalGet(void);
  98. int GetOcppConnStatus(void);
  99. void SetOcppConnStatus(uint8_t status);
  100. int setKeyValue(char *key, char *value);
  101. void OCPP_get_TableAuthlocalAllData(void);
  102. void processUnkownKey(void);
  103. struct StructOCPPMeterValue
  104. {
  105. unsigned char TimeStamp[28];
  106. struct StructSampledValue SampledValue[10];
  107. };
  108. struct ClientTime
  109. {
  110. unsigned int Heartbeat;
  111. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  112. unsigned int StartTransaction;
  113. unsigned int StopTransaction;
  114. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  115. }clientTime;
  116. typedef union
  117. {
  118. //Operations Initiated by Central System
  119. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  120. struct
  121. {
  122. //CsMsgValue[0]
  123. unsigned char StatusNotificationReq :1; //bit 0,
  124. unsigned char StatusNotificationConf :1; //bit 0,
  125. unsigned char :6; //bit 2~7
  126. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  127. }CpinitiateMsg;
  128. CpinitiateMsg cpinitateMsg;
  129. //GetConfiguration Array
  130. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  131. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  132. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  133. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  134. #if 0
  135. static char *ChargePointErrorCodeStr[] = {
  136. MACROSTR(ConnectorLockFailure),
  137. MACROSTR(EVCommunicationError),
  138. MACROSTR(GroundFailure),
  139. MACROSTR(HighTemperature),
  140. MACROSTR(InternalError),
  141. MACROSTR(LocalListConflict),
  142. MACROSTR(NoError),
  143. MACROSTR(OtherError),
  144. MACROSTR(OverCurrentFailure),
  145. MACROSTR(OverVoltage),
  146. MACROSTR(PowerMeterFailure),
  147. MACROSTR(PowerSwitchFailure),
  148. MACROSTR(ReaderFailure),
  149. MACROSTR(ResetFailure),
  150. MACROSTR(UnderVoltage),
  151. MACROSTR(WeakSignal)
  152. };
  153. #endif
  154. static char * ChargePointStatusStr[] = {
  155. MACROSTR(Available),
  156. MACROSTR(Preparing),
  157. MACROSTR(Charging),
  158. MACROSTR(SuspendedEVSE),
  159. MACROSTR(SuspendedEV),
  160. MACROSTR(Finishing),
  161. MACROSTR(Reserved),
  162. MACROSTR(Unavailable),
  163. MACROSTR(Faulted)
  164. };
  165. static char *RegistrationStatusStr[] = {
  166. MACROSTR(Accepted),
  167. MACROSTR(Pending),
  168. MACROSTR(Rejected)
  169. };
  170. static char *AvailabilityTypeStr[] = {
  171. MACROSTR(Inoperative),
  172. MACROSTR(Operative)
  173. };
  174. static char *AvailabilityStatusStr[] = {
  175. MACROSTR(Accepted),
  176. MACROSTR(Rejected),
  177. MACROSTR(Scheduled)
  178. };
  179. static char *ConfigurationStatusStr[] = {
  180. MACROSTR(Accepted),
  181. MACROSTR(Rejected),
  182. MACROSTR(RebootRequired),
  183. MACROSTR(NotSupported)
  184. };
  185. static char *ClearCacheStatusStr[] = {
  186. MACROSTR(Accepted),
  187. MACROSTR(Rejected)
  188. };
  189. static char *ChargingProfilePurposeTypeStr[] = {
  190. MACROSTR(ChargePointMaxProfile),
  191. MACROSTR(TxDefaultProfile),
  192. MACROSTR(TxProfile)
  193. };
  194. static char *ChargingProfileStatusStr[] = {
  195. MACROSTR(Accepted),
  196. MACROSTR(Rejected),
  197. MACROSTR(NotSupported)
  198. };
  199. static char *ClearChargingProfileStatusStr[] = {
  200. MACROSTR(Accepted),
  201. MACROSTR(Unknown)
  202. };
  203. static char *GetCompositeScheduleStatusStr[] = {
  204. MACROSTR(Accepted),
  205. MACROSTR(Rejected)
  206. };
  207. static char *UpdateTypeStr[] = {
  208. MACROSTR(Differential),
  209. MACROSTR(Full)
  210. };
  211. static char *UpdateStatusStr[] = {
  212. MACROSTR(Accepted),
  213. MACROSTR(Failed),
  214. MACROSTR(NotSupported),
  215. MACROSTR(VersionMismatch)
  216. };
  217. static char *RemoteStartStopStatusStr[] = {
  218. MACROSTR(Accepted),
  219. MACROSTR(Rejected)
  220. };
  221. static char *ReservationStatusStr[] = {
  222. MACROSTR(Accepted),
  223. MACROSTR(Faulted),
  224. MACROSTR(Occupied),
  225. MACROSTR(Rejected),
  226. MACROSTR(Unavailable)
  227. };
  228. static char *ResetTypeStr[] = {
  229. MACROSTR(Hard),
  230. MACROSTR(Soft)
  231. };
  232. static char *ResetStatusStr[] = {
  233. MACROSTR(Accepted),
  234. MACROSTR(Rejected)
  235. };
  236. static char * DiagnosticsStatusStr[] = {
  237. MACROSTR(Idle),
  238. MACROSTR(Uploaded),
  239. MACROSTR(UploadFailed),
  240. MACROSTR(Uploading)
  241. };
  242. static char * FirmwareStatusStr[] = {
  243. MACROSTR(Downloaded),
  244. MACROSTR(DownloadFailed),
  245. MACROSTR(Downloading),
  246. MACROSTR(Idle),
  247. MACROSTR(InstallationFailed),
  248. MACROSTR(Installing),
  249. MACROSTR(Installed)
  250. };
  251. static char * MessageTriggerStr[] = {
  252. MACROSTR(BootNotification),
  253. MACROSTR(DiagnosticsStatusNotification),
  254. MACROSTR(FirmwareStatusNotification),
  255. MACROSTR(Heartbeat),
  256. MACROSTR(MeterValues),
  257. MACROSTR(StatusNotification)
  258. };
  259. static char * TriggerMessageStatusStr[] = {
  260. MACROSTR(Accepted),
  261. MACROSTR(Rejected),
  262. MACROSTR(NotImplemented)
  263. };
  264. static char * UnlockStatusStr[] = {
  265. MACROSTR(Unlocked),
  266. MACROSTR(UnlockFailed),
  267. MACROSTR(NotSupported)
  268. };
  269. #if 0
  270. static char * StopTransactionReasonStr[] = {
  271. MACROSTR(EmergencyStop),
  272. MACROSTR(EVDisconnected),
  273. MACROSTR(HardReset),
  274. MACROSTR(Local),
  275. MACROSTR(Other),
  276. MACROSTR(PowerLoss),
  277. MACROSTR(Reboot),
  278. MACROSTR(Remote),
  279. MACROSTR(SoftReset),
  280. MACROSTR(UnlockCommand),
  281. MACROSTR(DeAuthorized)
  282. };
  283. #endif
  284. static char * CancelReservationStatusStr[] = {
  285. MACROSTR(Accepted),
  286. MACROSTR(Rejected)
  287. };
  288. static char * ReadingContextStr[] = {
  289. MACROSTR(Interruption.Begin),
  290. MACROSTR(Interruption.End),
  291. MACROSTR(Other),
  292. MACROSTR(Sample.Clock),
  293. MACROSTR(Sample.Periodic),
  294. MACROSTR(Transaction.Begin),
  295. MACROSTR(Transaction.End),
  296. MACROSTR(Trigger)
  297. };
  298. static char * ValueFormatStr[] = {
  299. MACROSTR(Raw),
  300. MACROSTR(SignedData)
  301. };
  302. static char * MeasurandStr[] = {
  303. MACROSTR(Current.Export),
  304. MACROSTR(Current.Import),
  305. MACROSTR(Current.Offered),
  306. MACROSTR(Energy.Active.Export.Register),
  307. MACROSTR(Energy.Active.Import.Register),
  308. MACROSTR(Energy.Reactive.Export.Register),
  309. MACROSTR(Energy.Reactive.Import.Register),
  310. MACROSTR(Energy.Active.Export.Interval),
  311. MACROSTR(Energy.Active.Import.Interval),
  312. MACROSTR(Energy.Reactive.Export.Interval),
  313. MACROSTR(Energy.Reactive.Import.Interval),
  314. MACROSTR(Frequency),
  315. MACROSTR(Power.Active.Export),
  316. MACROSTR(Power.Active.Import),
  317. MACROSTR(Power.Factor),
  318. MACROSTR(Power.Offered),
  319. MACROSTR(Power.Reactive.ExportMACROSTR),
  320. MACROSTR(Power.Reactive.Import),
  321. MACROSTR(RPM),
  322. MACROSTR(SoC),
  323. MACROSTR(Temperature),
  324. MACROSTR(Voltage)
  325. };
  326. static char * LocationStr[] = {
  327. MACROSTR(Body),
  328. MACROSTR(Cable),
  329. MACROSTR(EV),
  330. MACROSTR(Inlet),
  331. MACROSTR(Outlet)
  332. };
  333. static char * PhaseStr[] = {
  334. MACROSTR(L1),
  335. MACROSTR(L2),
  336. MACROSTR(L3),
  337. MACROSTR(N),
  338. MACROSTR(L1-N),
  339. MACROSTR(L2-N),
  340. MACROSTR(L3-N),
  341. MACROSTR(L1-L2),
  342. MACROSTR(L2-L3),
  343. MACROSTR(L3-L1)
  344. };
  345. static char * UnitOfMeasureStr[] = {
  346. MACROSTR(Wh),
  347. MACROSTR(kWh),
  348. MACROSTR(varh),
  349. MACROSTR(kvarh),
  350. MACROSTR(W),
  351. MACROSTR(kW),
  352. MACROSTR(VA),
  353. MACROSTR(kVA),
  354. MACROSTR(var),
  355. MACROSTR(kvar),
  356. MACROSTR(A),
  357. MACROSTR(V),
  358. MACROSTR(Celsius),
  359. MACROSTR(Fahrenheit),
  360. MACROSTR(K),
  361. MACROSTR(Percent)
  362. };
  363. //==========================================
  364. // Check time passed since today
  365. //==========================================
  366. long long DiffTimebWithNow(struct timeb ST)
  367. {
  368. //return milli-second
  369. struct timeb ET;
  370. long long StartTime,StopTime;
  371. ftime(&ET);
  372. StartTime=(long long)ST.time;
  373. StopTime=(long long)ET.time;
  374. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  375. }
  376. int getTimePassSinceToday()
  377. {
  378. int result = -1;
  379. time_t t;
  380. struct tm *tmStartToday;
  381. struct timeb tbStartToday;
  382. t=time(NULL);
  383. tmStartToday=localtime(&t);
  384. tmStartToday->tm_hour = 0;
  385. tmStartToday->tm_min = 0;
  386. tmStartToday->tm_sec = 0;
  387. tbStartToday.time = mktime(tmStartToday);
  388. tbStartToday.millitm = 0;
  389. result = DiffTimebWithNow(tbStartToday)/1000;
  390. return result;
  391. }
  392. //==========================================
  393. // GetCompositeSchedule logic related function
  394. //==========================================
  395. int DiffTimebSec(struct timeb ST, struct timeb ET)
  396. {
  397. //return milli-second
  398. unsigned int StartTime,StopTime;
  399. StartTime=(unsigned int)ST.time;
  400. StopTime=(unsigned int)ET.time;
  401. return (StopTime-StartTime);
  402. }
  403. int DiffTimebWithNowSec(struct timeb ST)
  404. {
  405. //return milli-second
  406. struct timeb ET;
  407. unsigned int StartTime,StopTime;
  408. ftime(&ET);
  409. StartTime=(unsigned int)ST.time;
  410. StopTime=(unsigned int)ET.time;
  411. return (StopTime-StartTime);
  412. }
  413. int getStartStop(uint8_t *start, uint8_t *stop)
  414. {
  415. int result = -1;
  416. struct tm tmStart;
  417. struct timeb tbStart;
  418. struct tm tmStop;
  419. struct timeb tbStop;
  420. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  421. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  422. {
  423. tmStart.tm_year -= 1900;
  424. tmStart.tm_mon -= 1;
  425. tbStart.time = mktime(&tmStart);
  426. tbStart.millitm = 0;
  427. tmStop.tm_year -= 1900;
  428. tmStop.tm_mon -= 1;
  429. tbStop.time = mktime(&tmStop);
  430. tbStop.millitm = 0;
  431. result = DiffTimebSec(tbStart, tbStop);
  432. }
  433. else
  434. {
  435. DEBUG_WARN("Start or stop date parsing error.\r\n");
  436. }
  437. return result;
  438. }
  439. int getStartSinceToday(uint8_t *stop)
  440. {
  441. int result = -1;
  442. time_t t;
  443. struct tm *tmStartToday;
  444. struct timeb tbStartToday;
  445. struct tm tmStop;
  446. struct timeb tbStop;
  447. if((sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  448. {
  449. t=time(NULL);
  450. tmStartToday=localtime(&t);
  451. tmStartToday->tm_hour = 0;
  452. tmStartToday->tm_min = 0;
  453. tmStartToday->tm_sec = 0;
  454. tbStartToday.time = mktime(tmStartToday);
  455. tmStop.tm_year -= 1900;
  456. tmStop.tm_mon -= 1;
  457. tbStop.time = mktime(&tmStop);
  458. tbStop.millitm = 0;
  459. result = DiffTimebSec(tbStartToday, tbStop);
  460. }
  461. return result;
  462. }
  463. int getStartSinceWeek(uint8_t *stop)
  464. {
  465. int result = -1;
  466. time_t t;
  467. struct tm *tmStartWeek;
  468. struct timeb tbStartWeek;
  469. struct tm tmStop;
  470. struct timeb tbStop;
  471. if((sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  472. {
  473. t=time(NULL);
  474. tmStartWeek=localtime(&t);
  475. t-=86400*tmStartWeek->tm_wday;
  476. tmStartWeek=localtime(&t);
  477. tmStartWeek->tm_hour = 0;
  478. tmStartWeek->tm_min = 0;
  479. tmStartWeek->tm_sec = 0;
  480. tbStartWeek.time = mktime(tmStartWeek);
  481. tmStop.tm_year -= 1900;
  482. tmStop.tm_mon -= 1;
  483. tbStop.time = mktime(&tmStop);
  484. tbStop.millitm = 0;
  485. result = DiffTimebSec(tbStartWeek, tbStop);
  486. }
  487. return result;
  488. }
  489. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  490. {
  491. FILE *fp;
  492. char profileFileName[128];
  493. char *line = NULL;
  494. size_t len = 0;
  495. time_t CurrentTime;
  496. struct tm *tmComposite;
  497. struct StructChargingProfile maxProfile;
  498. struct StructChargingProfile defaultTxProfile;
  499. struct StructChargingProfile txProfile;
  500. struct StructChargingSchedulePeriod tmpPeriod;
  501. uint8_t limitMax=0;
  502. uint8_t limitDef=0;
  503. uint8_t limitTx=0;
  504. int compositePeriodIdx = 0;
  505. CurrentTime = time(NULL);
  506. tmComposite=localtime(&CurrentTime);
  507. sprintf((char*)compositeProfile->ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  508. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  509. compositeProfile->ChargingSchedule.Duration = durationReq;
  510. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  511. {
  512. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  513. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  514. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  515. }
  516. compositeProfile->ChargingProfileId = 0;
  517. compositeProfile->StackLevel = 99 ;
  518. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  519. maxProfile.ChargingProfileId = -1;
  520. defaultTxProfile.ChargingProfileId = -1;
  521. txProfile.ChargingProfileId = -1;
  522. system("yes|rm /tmp/*.json");
  523. system("cp /Storage/OCPP/*.json /tmp");
  524. /*
  525. * Search valid charging profile
  526. */
  527. //DEBUG_INFO("====================================\n");
  528. // Search max profile
  529. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  530. if((access(profileFileName, F_OK))!=-1)
  531. {
  532. fp = fopen(profileFileName, "r");
  533. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  534. {
  535. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  536. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  537. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  538. }
  539. maxProfile.ChargingProfileId = -1;
  540. maxProfile.StackLevel = -1;
  541. while(getline(&line, &len, fp) != -1)
  542. {
  543. json_object *obj = NULL;
  544. obj = json_tokener_parse(line);
  545. if(is_error(obj))
  546. {
  547. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  548. }
  549. else
  550. {
  551. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  552. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  553. )
  554. {
  555. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  556. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  557. )
  558. {
  559. struct tm tmFrom, tmTo;
  560. struct timeb tbFrom, tbTo;
  561. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  562. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  563. {
  564. tmFrom.tm_year -= 1900;
  565. tmFrom.tm_mon -= 1;
  566. tbFrom.time = mktime(&tmFrom);
  567. tmTo.tm_year -= 1900;
  568. tmTo.tm_mon -= 1;
  569. tbTo.time = mktime(&tmTo);
  570. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  571. {
  572. if(maxProfile.ChargingProfileId == -1)
  573. DEBUG_INFO("MaxProfile found.\n");
  574. else
  575. DEBUG_INFO("MaxProfile updated.\n");
  576. // Required item
  577. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  578. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  579. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  580. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  581. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  582. {
  583. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  584. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  585. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  586. 3:
  587. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  588. }
  589. // Optional item
  590. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  591. {
  592. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  593. }
  594. else
  595. {
  596. sprintf((char*)maxProfile.ValidFrom, " ");
  597. }
  598. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  599. {
  600. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  601. }
  602. else
  603. {
  604. sprintf((char*)maxProfile.ValidTo, " ");
  605. }
  606. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  607. {
  608. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  609. }
  610. else
  611. {
  612. sprintf((char*)maxProfile.RecurrencyKind, " ");
  613. }
  614. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  615. {
  616. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  617. }
  618. else
  619. {
  620. maxProfile.TransactionId = -1;
  621. }
  622. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  623. {
  624. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  625. }
  626. else
  627. {
  628. maxProfile.ChargingSchedule.Duration = -1;
  629. }
  630. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  631. {
  632. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  633. }
  634. else
  635. {
  636. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, " ");
  637. }
  638. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  639. {
  640. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  641. }
  642. else
  643. {
  644. maxProfile.ChargingSchedule.MinChargingRate = -1;
  645. }
  646. }
  647. }
  648. }
  649. else
  650. {
  651. if(maxProfile.ChargingProfileId == -1)
  652. DEBUG_INFO("MaxProfile found.\n");
  653. else
  654. DEBUG_INFO("MaxProfile updated.\n");
  655. // Required item
  656. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  657. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  658. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  659. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  660. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  661. {
  662. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  663. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  664. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  665. 3:
  666. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  667. }
  668. // Optional item
  669. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  670. {
  671. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  672. }
  673. else
  674. {
  675. sprintf((char*)maxProfile.ValidFrom, " ");
  676. }
  677. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  678. {
  679. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  680. }
  681. else
  682. {
  683. sprintf((char*)maxProfile.ValidTo, " ");
  684. }
  685. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  686. {
  687. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  688. }
  689. else
  690. {
  691. sprintf((char*)maxProfile.RecurrencyKind, " ");
  692. }
  693. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  694. {
  695. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  696. }
  697. else
  698. {
  699. maxProfile.TransactionId = -1;
  700. }
  701. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  702. {
  703. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  704. }
  705. else
  706. {
  707. maxProfile.ChargingSchedule.Duration = -1;
  708. }
  709. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  710. {
  711. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  712. }
  713. else
  714. {
  715. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, " ");
  716. }
  717. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  718. {
  719. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  720. }
  721. else
  722. {
  723. maxProfile.ChargingSchedule.MinChargingRate = -1;
  724. }
  725. }
  726. }
  727. }
  728. json_object_put(obj);
  729. }
  730. fclose(fp);
  731. /*
  732. if(maxProfile.ChargingProfileId !=-1)
  733. {
  734. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  735. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  736. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  737. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  738. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  739. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  740. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  741. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  742. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  743. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  744. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  745. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  746. {
  747. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  748. {
  749. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  750. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  751. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  752. }
  753. }
  754. }
  755. else
  756. DEBUG_INFO("MaxProfile not found.\n");
  757. DEBUG_INFO("------------------------------------\n");*/
  758. }
  759. // Search default tx profile
  760. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  761. if((access(profileFileName, F_OK))==-1)
  762. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  763. if((access(profileFileName, F_OK))!=-1)
  764. {
  765. fp = fopen(profileFileName, "r");
  766. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  767. {
  768. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  769. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  770. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  771. }
  772. defaultTxProfile.ChargingProfileId = -1;
  773. defaultTxProfile.StackLevel = -1;
  774. while(getline(&line, &len, fp) != -1)
  775. {
  776. json_object *obj = NULL;
  777. obj = json_tokener_parse(line);
  778. if(is_error(obj))
  779. {
  780. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  781. }
  782. else
  783. {
  784. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  785. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  786. )
  787. {
  788. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  789. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  790. )
  791. {
  792. struct tm tmFrom, tmTo;
  793. struct timeb tbFrom, tbTo;
  794. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  795. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  796. {
  797. tmFrom.tm_year -= 1900;
  798. tmFrom.tm_mon -= 1;
  799. tbFrom.time = mktime(&tmFrom);
  800. tmTo.tm_year -= 1900;
  801. tmTo.tm_mon -= 1;
  802. tbTo.time = mktime(&tmTo);
  803. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  804. {
  805. if(defaultTxProfile.ChargingProfileId == -1)
  806. DEBUG_INFO("TxDefaultProfile found.\n");
  807. else
  808. DEBUG_INFO("TxDefaultProfile updated.\n");
  809. // Required item
  810. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  811. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  812. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  813. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  814. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  815. {
  816. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  817. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  818. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  819. 3:
  820. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  821. }
  822. // Optional item
  823. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  824. {
  825. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  826. }
  827. else
  828. {
  829. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  830. }
  831. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  832. {
  833. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  834. }
  835. else
  836. {
  837. sprintf((char*)defaultTxProfile.ValidTo, " ");
  838. }
  839. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  840. {
  841. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  842. }
  843. else
  844. {
  845. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  846. }
  847. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  848. {
  849. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  850. }
  851. else
  852. {
  853. defaultTxProfile.TransactionId = -1;
  854. }
  855. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  856. {
  857. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  858. }
  859. else
  860. {
  861. defaultTxProfile.ChargingSchedule.Duration = -1;
  862. }
  863. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  864. {
  865. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  866. }
  867. else
  868. {
  869. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, " ");
  870. }
  871. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  872. {
  873. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  874. }
  875. else
  876. {
  877. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  878. }
  879. }
  880. }
  881. }
  882. else
  883. {
  884. if(defaultTxProfile.ChargingProfileId == -1)
  885. DEBUG_INFO("TxDefaultProfile found.\n");
  886. else
  887. DEBUG_INFO("TxDefaultProfile updated.\n");
  888. // Required item
  889. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  890. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  891. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  892. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  893. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  894. {
  895. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  896. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  897. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  898. 3:
  899. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  900. }
  901. // Optional item
  902. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  903. {
  904. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  905. }
  906. else
  907. {
  908. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  909. }
  910. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  911. {
  912. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  913. }
  914. else
  915. {
  916. sprintf((char*)defaultTxProfile.ValidTo, " ");
  917. }
  918. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  919. {
  920. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  921. }
  922. else
  923. {
  924. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  925. }
  926. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  927. {
  928. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  929. }
  930. else
  931. {
  932. defaultTxProfile.TransactionId = -1;
  933. }
  934. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  935. {
  936. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  937. }
  938. else
  939. {
  940. defaultTxProfile.ChargingSchedule.Duration = -1;
  941. }
  942. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  943. {
  944. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  945. }
  946. else
  947. {
  948. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, " ");
  949. }
  950. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  951. {
  952. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  953. }
  954. else
  955. {
  956. maxProfile.ChargingSchedule.MinChargingRate = -1;
  957. }
  958. }
  959. }
  960. }
  961. json_object_put(obj);
  962. }
  963. fclose(fp);
  964. /*
  965. if(defaultTxProfile.ChargingProfileId != -1)
  966. {
  967. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  968. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  969. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  970. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  971. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  972. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  973. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  974. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  975. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  976. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  977. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  978. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  979. {
  980. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  981. {
  982. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  983. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  984. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  985. }
  986. }
  987. }
  988. else
  989. DEBUG_INFO("TxDefaultProfile not found.\n");
  990. DEBUG_INFO("------------------------------------\n");*/
  991. }
  992. // Search tx profile
  993. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  994. if((access(profileFileName, F_OK))!=-1)
  995. {
  996. fp = fopen(profileFileName, "r");
  997. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  998. {
  999. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1000. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1001. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1002. }
  1003. txProfile.ChargingProfileId = -1;
  1004. txProfile.StackLevel = -1;
  1005. while(getline(&line, &len, fp) != -1)
  1006. {
  1007. json_object *obj = NULL;
  1008. obj = json_tokener_parse(line);
  1009. if(is_error(obj))
  1010. {
  1011. DEBUG_ERROR("Parse txProfile from file error.\n");
  1012. }
  1013. else
  1014. {
  1015. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  1016. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1017. )
  1018. {
  1019. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1020. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1021. )
  1022. {
  1023. struct tm tmFrom, tmTo;
  1024. struct timeb tbFrom, tbTo;
  1025. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1026. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1027. {
  1028. tmFrom.tm_year -= 1900;
  1029. tmFrom.tm_mon -= 1;
  1030. tbFrom.time = mktime(&tmFrom);
  1031. tmTo.tm_year -= 1900;
  1032. tmTo.tm_mon -= 1;
  1033. tbTo.time = mktime(&tmTo);
  1034. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1035. {
  1036. if(txProfile.ChargingProfileId == -1)
  1037. DEBUG_INFO("TxProfile found.\n");
  1038. else
  1039. DEBUG_INFO("TxProfile updated.\n");
  1040. // Required item
  1041. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1042. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1043. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1044. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1045. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1046. {
  1047. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1048. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1049. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1050. 3:
  1051. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1052. }
  1053. // Optional item
  1054. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1055. {
  1056. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1057. }
  1058. else
  1059. {
  1060. sprintf((char*)txProfile.ValidFrom, " ");
  1061. }
  1062. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1063. {
  1064. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1065. }
  1066. else
  1067. {
  1068. sprintf((char*)txProfile.ValidTo, " ");
  1069. }
  1070. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1071. {
  1072. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1073. }
  1074. else
  1075. {
  1076. sprintf((char*)txProfile.RecurrencyKind, " ");
  1077. }
  1078. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1079. {
  1080. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1081. }
  1082. else
  1083. {
  1084. txProfile.TransactionId = -1;
  1085. }
  1086. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1087. {
  1088. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1089. }
  1090. else
  1091. {
  1092. txProfile.ChargingSchedule.Duration = -1;
  1093. }
  1094. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1095. {
  1096. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1097. }
  1098. else
  1099. {
  1100. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, " ");
  1101. }
  1102. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1103. {
  1104. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1105. }
  1106. else
  1107. {
  1108. txProfile.ChargingSchedule.MinChargingRate = -1;
  1109. }
  1110. }
  1111. }
  1112. }
  1113. else
  1114. {
  1115. if(txProfile.ChargingProfileId == -1)
  1116. DEBUG_INFO("TxProfile found.\n");
  1117. else
  1118. DEBUG_INFO("TxProfile updated.\n");
  1119. // Required item
  1120. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1121. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1122. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1123. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1124. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1125. {
  1126. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1127. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1128. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1129. 3:
  1130. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1131. }
  1132. // Optional item
  1133. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1134. {
  1135. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1136. }
  1137. else
  1138. {
  1139. sprintf((char*)txProfile.ValidFrom, " ");
  1140. }
  1141. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1142. {
  1143. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1144. }
  1145. else
  1146. {
  1147. sprintf((char*)txProfile.ValidTo, " ");
  1148. }
  1149. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1150. {
  1151. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1152. }
  1153. else
  1154. {
  1155. sprintf((char*)txProfile.RecurrencyKind, " ");
  1156. }
  1157. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1158. {
  1159. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1160. }
  1161. else
  1162. {
  1163. txProfile.TransactionId = -1;
  1164. }
  1165. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1166. {
  1167. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1168. }
  1169. else
  1170. {
  1171. txProfile.ChargingSchedule.Duration = -1;
  1172. }
  1173. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1174. {
  1175. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1176. }
  1177. else
  1178. {
  1179. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, " ");
  1180. }
  1181. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1182. {
  1183. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1184. }
  1185. else
  1186. {
  1187. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1188. }
  1189. }
  1190. }
  1191. }
  1192. json_object_put(obj);
  1193. }
  1194. fclose(fp);
  1195. /*
  1196. if(defaultTxProfile.ChargingProfileId != -1)
  1197. {
  1198. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1199. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1200. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1201. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1202. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1203. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1204. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1205. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1206. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1207. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1208. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1209. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1210. {
  1211. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1212. {
  1213. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1214. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1215. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1216. }
  1217. }
  1218. }
  1219. else
  1220. DEBUG_INFO("TxProfile not found.\n");*/
  1221. }
  1222. /*
  1223. * Align found profile start schedule & periods
  1224. */
  1225. //DEBUG_INFO("====================================\n");
  1226. /*
  1227. // For local test usage, force modify found profile start schedule info
  1228. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-10);
  1229. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-5);
  1230. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-3);
  1231. */
  1232. if(maxProfile.ChargingProfileId != -1)
  1233. {
  1234. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1235. {
  1236. if(maxProfile.ChargingSchedule.Duration != -1)
  1237. {
  1238. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1239. 0:
  1240. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1241. }
  1242. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1243. {
  1244. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1245. {
  1246. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1247. 0:
  1248. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1249. }
  1250. }
  1251. }
  1252. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1253. {
  1254. if(maxProfile.ChargingSchedule.Duration != -1)
  1255. {
  1256. maxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1257. 0:
  1258. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1259. }
  1260. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1261. {
  1262. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1263. {
  1264. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1265. 0:
  1266. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1267. }
  1268. }
  1269. }
  1270. else
  1271. {
  1272. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1273. {
  1274. if(maxProfile.ChargingSchedule.Duration != -1)
  1275. {
  1276. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1277. 0:
  1278. (maxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1279. }
  1280. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1281. {
  1282. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1283. {
  1284. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1285. 0:
  1286. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1287. }
  1288. }
  1289. }
  1290. else
  1291. {
  1292. if(maxProfile.ChargingSchedule.Duration != -1)
  1293. {
  1294. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1295. 0:
  1296. (maxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1297. }
  1298. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1299. {
  1300. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1301. {
  1302. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1303. 0:
  1304. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1305. }
  1306. }
  1307. }
  1308. }
  1309. /*
  1310. DEBUG_INFO("MaxProfile after align.\n");
  1311. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1312. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1313. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1314. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1315. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1316. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1317. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1318. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1319. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1320. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1321. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1322. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1323. {
  1324. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1325. {
  1326. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1327. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1328. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1329. }
  1330. }
  1331. DEBUG_INFO("------------------------------------\n");*/
  1332. }
  1333. if(defaultTxProfile.ChargingProfileId != -1)
  1334. {
  1335. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1336. {
  1337. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1338. {
  1339. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1340. 0:
  1341. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1342. }
  1343. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1344. {
  1345. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1346. {
  1347. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1348. 0:
  1349. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1350. }
  1351. }
  1352. }
  1353. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1354. {
  1355. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1356. {
  1357. defaultTxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1358. 0:
  1359. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1360. }
  1361. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1362. {
  1363. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1364. {
  1365. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1366. 0:
  1367. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1368. }
  1369. }
  1370. }
  1371. else
  1372. {
  1373. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1374. {
  1375. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1376. {
  1377. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1378. 0:
  1379. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1380. }
  1381. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1382. {
  1383. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1384. {
  1385. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1386. 0:
  1387. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1388. }
  1389. }
  1390. }
  1391. else
  1392. {
  1393. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1394. {
  1395. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1396. 0:
  1397. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1398. }
  1399. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1400. {
  1401. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1402. {
  1403. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1404. 0:
  1405. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1406. }
  1407. }
  1408. }
  1409. }
  1410. /*
  1411. DEBUG_INFO("defaultTxProfile after align.\n");
  1412. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1413. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1414. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1415. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1416. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1417. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1418. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1419. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1420. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1421. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1422. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1423. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1424. {
  1425. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1426. {
  1427. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1428. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1429. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1430. }
  1431. }
  1432. DEBUG_INFO("------------------------------------\n");*/
  1433. }
  1434. if(txProfile.ChargingProfileId != -1)
  1435. {
  1436. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1437. {
  1438. if(txProfile.ChargingSchedule.Duration != -1)
  1439. {
  1440. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1441. 0:
  1442. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1443. }
  1444. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1445. {
  1446. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1447. {
  1448. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1449. 0:
  1450. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1451. }
  1452. }
  1453. }
  1454. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1455. {
  1456. if(txProfile.ChargingSchedule.Duration != -1)
  1457. {
  1458. txProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1459. 0:
  1460. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1461. }
  1462. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1463. {
  1464. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1465. {
  1466. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1467. 0:
  1468. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1469. }
  1470. }
  1471. }
  1472. else
  1473. {
  1474. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1475. {
  1476. if(txProfile.ChargingSchedule.Duration != -1)
  1477. {
  1478. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1479. 0:
  1480. (txProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1481. }
  1482. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1483. {
  1484. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1485. {
  1486. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1487. 0:
  1488. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1489. }
  1490. }
  1491. }
  1492. else
  1493. {
  1494. if(txProfile.ChargingSchedule.Duration != -1)
  1495. {
  1496. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1497. 0:
  1498. (txProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1499. }
  1500. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1501. {
  1502. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1503. {
  1504. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1505. 0:
  1506. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1507. }
  1508. }
  1509. }
  1510. }
  1511. /*
  1512. DEBUG_INFO("txProfile after align.\n");
  1513. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1514. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1515. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1516. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1517. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1518. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1519. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1520. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1521. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1522. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1523. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1524. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1525. {
  1526. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1527. {
  1528. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1529. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1530. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1531. }
  1532. }*/
  1533. }
  1534. /*
  1535. * Merge to conposite schedule
  1536. */
  1537. //DEBUG_INFO("====================================\n");
  1538. // Find each profile period quantity
  1539. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1540. {
  1541. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1542. limitMax = idx+1;
  1543. }
  1544. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1545. {
  1546. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1547. limitDef = idx+1;
  1548. }
  1549. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1550. {
  1551. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1552. limitTx = idx+1;
  1553. }
  1554. // TxProfile found, composite schedule based on it
  1555. if(txProfile.ChargingProfileId != -1)
  1556. {
  1557. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1558. {
  1559. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1560. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  1561. (txProfile.ChargingSchedule.Duration > 0))
  1562. {
  1563. if(maxProfile.ChargingProfileId != -1)
  1564. {
  1565. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1566. {
  1567. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  1568. {
  1569. if((maxProfile.ChargingSchedule.Duration > 0))
  1570. {
  1571. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1572. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1573. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1574. }
  1575. else
  1576. {
  1577. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1578. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1579. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  1580. }
  1581. }
  1582. if(idxMaxPeriod == (limitMax-1))
  1583. {
  1584. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1585. {
  1586. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1587. {
  1588. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1589. compositePeriodIdx++;
  1590. }
  1591. else
  1592. {
  1593. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1594. }
  1595. }
  1596. }
  1597. }
  1598. }
  1599. else
  1600. {
  1601. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1602. {
  1603. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1604. compositePeriodIdx++;
  1605. }
  1606. else
  1607. {
  1608. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1609. }
  1610. }
  1611. }
  1612. if(idxTxPeriod == (limitTx-1))
  1613. {
  1614. if(defaultTxProfile.ChargingProfileId != -1)
  1615. {
  1616. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1617. {
  1618. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod > txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod) &&
  1619. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq))
  1620. {
  1621. if(maxProfile.ChargingProfileId != -1)
  1622. {
  1623. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1624. {
  1625. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1626. {
  1627. if((maxProfile.ChargingSchedule.Duration > 0))
  1628. {
  1629. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1630. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1631. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1632. }
  1633. else
  1634. {
  1635. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1636. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1637. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1638. }
  1639. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1640. {
  1641. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1642. {
  1643. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1644. compositePeriodIdx++;
  1645. }
  1646. else
  1647. {
  1648. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1649. }
  1650. }
  1651. break;
  1652. }
  1653. }
  1654. }
  1655. else
  1656. {
  1657. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1658. {
  1659. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1660. compositePeriodIdx++;
  1661. }
  1662. else
  1663. {
  1664. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1665. }
  1666. }
  1667. }
  1668. }
  1669. }
  1670. }
  1671. }
  1672. }
  1673. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1674. else if(defaultTxProfile.ChargingProfileId != -1)
  1675. {
  1676. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1677. {
  1678. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1679. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq))
  1680. {
  1681. if(maxProfile.ChargingProfileId != -1)
  1682. {
  1683. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1684. {
  1685. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1686. {
  1687. if((maxProfile.ChargingSchedule.Duration > 0))
  1688. {
  1689. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1690. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1691. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1692. }
  1693. else
  1694. {
  1695. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1696. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1697. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1698. }
  1699. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1700. {
  1701. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1702. {
  1703. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1704. compositePeriodIdx++;
  1705. }
  1706. else
  1707. {
  1708. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1709. }
  1710. }
  1711. break;
  1712. }
  1713. }
  1714. }
  1715. else
  1716. {
  1717. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1718. {
  1719. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1720. compositePeriodIdx++;
  1721. }
  1722. else
  1723. {
  1724. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1725. }
  1726. }
  1727. }
  1728. }
  1729. }
  1730. // Fill other period by MaxProfile
  1731. if(maxProfile.ChargingProfileId != -1)
  1732. {
  1733. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1734. {
  1735. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1736. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq))
  1737. {
  1738. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  1739. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1740. {
  1741. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  1742. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  1743. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1744. }
  1745. if(idxMaxPeriod == (limitMax-1))
  1746. {
  1747. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  1748. (maxProfile.ChargingSchedule.Duration > 0))
  1749. {
  1750. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  1751. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  1752. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1753. }
  1754. if(tmpPeriod.Limit != -1)
  1755. {
  1756. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1757. {
  1758. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1759. {
  1760. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1761. compositePeriodIdx++;
  1762. }
  1763. else
  1764. {
  1765. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1766. }
  1767. }
  1768. }
  1769. }
  1770. }
  1771. }
  1772. }
  1773. DEBUG_INFO("Composite schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1774. DEBUG_INFO("Composite schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1775. DEBUG_INFO("Composite rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1776. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1777. {
  1778. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1779. {
  1780. compositeProfile->ChargingProfileId = 1;
  1781. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1782. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1783. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1784. }
  1785. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1786. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1787. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1788. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1789. }
  1790. if(line)
  1791. free(line);
  1792. }
  1793. //==========================================
  1794. // Init all share memory
  1795. //==========================================
  1796. int InitShareMemory()
  1797. {
  1798. int result = PASS;
  1799. int MeterSMId;
  1800. //creat ShmSysConfigAndInfo
  1801. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1802. {
  1803. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1804. result = FAIL;
  1805. }
  1806. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1807. {
  1808. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  1809. result = FAIL;
  1810. }
  1811. else
  1812. {}
  1813. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1814. {
  1815. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1816. result = FAIL;
  1817. }
  1818. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1819. {
  1820. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1821. result = FAIL;
  1822. }
  1823. else
  1824. {}
  1825. //creat ShmPsuData
  1826. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  1827. {
  1828. DEBUG_ERROR("shmget ShmPsuData NG\n");
  1829. result = FAIL;
  1830. }
  1831. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1832. {
  1833. DEBUG_ERROR("shmat ShmPsuData NG\n");
  1834. result = FAIL;
  1835. }
  1836. else
  1837. {}
  1838. //creat ShmOCPP16Data
  1839. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1840. {
  1841. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  1842. result = FAIL;
  1843. }
  1844. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1845. {
  1846. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  1847. result = FAIL;
  1848. }
  1849. else
  1850. {}
  1851. /****************************** For Initial Settings************************************************/
  1852. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  1853. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  1854. // allocate Configuration memory address
  1855. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  1856. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  1857. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  1858. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  1859. //offline MeterValue Interval
  1860. TempMeterValueInterval = 0;
  1861. return result;
  1862. }
  1863. int ProcessShareMemory()
  1864. {
  1865. if(InitShareMemory() == FAIL)
  1866. {
  1867. DEBUG_ERROR("InitShareMemory NG\n");
  1868. if(ShmStatusCodeData!=NULL)
  1869. {
  1870. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1871. }
  1872. sleep(5);
  1873. return FAIL;
  1874. }
  1875. return PASS;
  1876. }
  1877. //---------------------common routine---------------------------//
  1878. int isOFFline(void)
  1879. {
  1880. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  1881. {
  1882. if(TempMeterValueInterval >= 2 )
  1883. {
  1884. TempMeterValueInterval = 0;
  1885. return TRUE;
  1886. }
  1887. else
  1888. {
  1889. TempMeterValueInterval = TempMeterValueInterval+ 1;
  1890. return FALSE;
  1891. }
  1892. }
  1893. else
  1894. {
  1895. return FALSE;
  1896. }
  1897. }
  1898. //---------------------------------------------
  1899. // new:
  1900. // enum SYSTEM_STATUS
  1901. // {
  1902. // SYS_MODE_BOOTING = 0,
  1903. // SYS_MODE_IDLE = 1,
  1904. // SYS_MODE_AUTHORIZING = 2,
  1905. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  1906. // SYS_MODE_REASSIGN = 4,
  1907. // SYS_MODE_PREPARING = 5,
  1908. // SYS_MODE_PREPARE_FOR_EV = 6,
  1909. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  1910. // SYS_MODE_CHARGING = 8,
  1911. // SYS_MODE_TERMINATING = 9,
  1912. // SYS_MODE_COMPLETE = 10,
  1913. // SYS_MODE_ALARM = 11,
  1914. // SYS_MODE_FAULT = 12,
  1915. // SYS_MODE_RESERVATION = 13,
  1916. // SYS_MODE_BOOKING = 14,
  1917. // SYS_MODE_MAINTAIN = 15,
  1918. // SYS_MODE_DEBUG = 16,
  1919. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  1920. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  1921. // SYS_MODE_UPDATE = 19
  1922. // };
  1923. //
  1924. //
  1925. //-----------------------------------------
  1926. void CheckSystemValue(void)
  1927. {
  1928. uint8_t reqSampleMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1929. uint8_t reqClockAlignMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1930. char filenmae[100]={0};
  1931. char str[100]={0};
  1932. int tempIndex = 0;
  1933. //===============================
  1934. // send Heartbeat
  1935. //===============================
  1936. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  1937. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  1938. {
  1939. clientTime.Heartbeat=time((time_t*)NULL);
  1940. if(server_sign == TRUE)
  1941. {
  1942. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  1943. }
  1944. else
  1945. {
  1946. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  1947. }
  1948. }
  1949. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  1950. {
  1951. //parameter for test
  1952. sendHeartbeatRequest(0);
  1953. //==============================================
  1954. // Reset Waiting Time
  1955. //==============================================
  1956. clientTime.Heartbeat=time((time_t*)NULL);
  1957. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1958. }
  1959. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1960. {
  1961. //===============================
  1962. // CSU Trigger Reset Conf
  1963. //===============================
  1964. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1965. {
  1966. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1967. }
  1968. //===============================
  1969. // CSU Trigger Authorize Request
  1970. //===============================
  1971. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  1972. {
  1973. sendAuthorizeRequest(0);
  1974. authorizeRetryTimes = authorizeRetryTimes + 1;
  1975. if(authorizeRetryTimes < 3)
  1976. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1977. }
  1978. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  1979. {
  1980. authorizeRetryTimes = 0;
  1981. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1982. server_sign = FALSE;
  1983. }
  1984. 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))
  1985. {
  1986. sendAuthorizeRequest(0);
  1987. }
  1988. //===============================
  1989. // CSU Trigger Smart Charging Profilw
  1990. //===============================
  1991. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  1992. {
  1993. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1994. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  1995. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1996. }
  1997. //==============================================
  1998. // Charger start transaction
  1999. //==============================================
  2000. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2001. {
  2002. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  2003. sendStartTransactionRequest(gun_index);
  2004. clientTime.StartTransaction = time((time_t*)NULL);
  2005. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2006. }
  2007. //==============================================
  2008. // Charger stop transaction
  2009. //==============================================
  2010. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2011. {
  2012. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  2013. sendStopTransactionRequest(gun_index);
  2014. clientTime.StopTransaction = time((time_t*)NULL);
  2015. }
  2016. //==============================================
  2017. // Charger status report
  2018. //==============================================
  2019. //--- Check Mode Change ---//
  2020. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2021. if(gunType[gun_index] == 'J')
  2022. {
  2023. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2024. {
  2025. tempIndex = ((gun_index==2) ? 1: 0);
  2026. }
  2027. else
  2028. {
  2029. tempIndex = gun_index;
  2030. }
  2031. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2032. {
  2033. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2034. {
  2035. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2036. {
  2037. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2038. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2039. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2040. statusModeChage[gun_index] = TRUE;
  2041. }
  2042. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2043. {
  2044. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2045. if((access(filenmae,F_OK))!=-1)
  2046. {
  2047. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2048. sprintf(str,"rm -f %s",filenmae);
  2049. system(str);
  2050. }
  2051. }
  2052. #if 1 // for TempStopTransaction
  2053. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2054. {
  2055. checkTempStopTransaction(gun_index);
  2056. }
  2057. #endif
  2058. }
  2059. }
  2060. }
  2061. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2062. {
  2063. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2064. {
  2065. tempIndex = ((gun_index==2) ? 1: 0);
  2066. }
  2067. else
  2068. {
  2069. tempIndex = gun_index;
  2070. }
  2071. for (int index = 0; index < CCS_QUANTITY; index++)
  2072. {
  2073. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2074. {
  2075. 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]*/ )
  2076. {
  2077. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2078. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2079. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2080. statusModeChage[gun_index] = TRUE;
  2081. }
  2082. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2083. {
  2084. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2085. if((access(filenmae,F_OK))!=-1)
  2086. {
  2087. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2088. sprintf(str,"rm -f %s",filenmae);
  2089. system(str);
  2090. }
  2091. }
  2092. #if 1 // for TempStopTransaction
  2093. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2094. {
  2095. checkTempStopTransaction(gun_index);
  2096. }
  2097. #endif
  2098. }
  2099. }
  2100. }
  2101. else if(gunType[gun_index] == 'G')
  2102. {
  2103. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2104. {
  2105. tempIndex = ((gun_index==2) ? 1: 0);
  2106. }
  2107. else
  2108. {
  2109. tempIndex = gun_index;
  2110. }
  2111. for (int index = 0; index < GB_QUANTITY; index++)
  2112. {
  2113. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2114. {
  2115. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2116. {
  2117. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2118. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2119. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2120. statusModeChage[gun_index] = TRUE;
  2121. }
  2122. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2123. {
  2124. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2125. if((access(filenmae,F_OK))!=-1)
  2126. {
  2127. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2128. sprintf(str,"rm -f %s",filenmae);
  2129. system(str);
  2130. }
  2131. }
  2132. #if 1 // for TempStopTransaction
  2133. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2134. {
  2135. checkTempStopTransaction(gun_index);
  2136. }
  2137. #endif
  2138. }
  2139. }
  2140. }
  2141. else
  2142. {
  2143. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2144. {
  2145. tempIndex = 2;
  2146. }
  2147. else
  2148. {
  2149. tempIndex = gun_index;
  2150. }
  2151. for (int index = 0; index < AC_QUANTITY; index++)
  2152. {
  2153. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2154. {
  2155. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2156. {
  2157. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2158. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2159. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2160. statusModeChage[gun_index] = TRUE;
  2161. }
  2162. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2163. {
  2164. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2165. if((access(filenmae,F_OK))!=-1)
  2166. {
  2167. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2168. sprintf(str,"rm -f %s",filenmae);
  2169. system(str);
  2170. }
  2171. }
  2172. #if 1 // for TempStopTransaction
  2173. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2174. {
  2175. checkTempStopTransaction(gun_index);
  2176. }
  2177. #endif
  2178. }
  2179. }// END
  2180. }
  2181. if(isWebsocketSendable &&
  2182. ((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)))) )
  2183. {
  2184. if(SystemInitial > 0)
  2185. SystemInitial -= 1;
  2186. sendStatusNotificationRequest(gun_index);
  2187. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2188. statusModeChage[gun_index] = FALSE;
  2189. }
  2190. //==============================================
  2191. // Meter report
  2192. //==============================================
  2193. if(/*(server_sign == TRUE) &&(isOFFline() == TRUE) ||*/
  2194. (((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)))
  2195. {
  2196. //check Transaction active
  2197. if(gunType[gun_index] == 'J')
  2198. {
  2199. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2200. {
  2201. tempIndex = ((gun_index==2) ? 1: 0);
  2202. }
  2203. else
  2204. {
  2205. tempIndex = gun_index;
  2206. }
  2207. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2208. {
  2209. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2210. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2211. {
  2212. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2213. {
  2214. reqSampleMeter[gun_index] = 1;
  2215. }
  2216. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2217. {
  2218. reqClockAlignMeter[gun_index] = 1;
  2219. }
  2220. }
  2221. }// End for CHAdeMO
  2222. }
  2223. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2224. {
  2225. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2226. {
  2227. tempIndex = ((gun_index==2) ? 1: 0);
  2228. }
  2229. else
  2230. {
  2231. tempIndex = gun_index;
  2232. }
  2233. for (int index = 0; index < CCS_QUANTITY; index++)
  2234. {
  2235. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2236. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2237. {
  2238. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2239. {
  2240. reqSampleMeter[gun_index] = 1;
  2241. }
  2242. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2243. {
  2244. reqClockAlignMeter[gun_index] = 1;
  2245. }
  2246. }
  2247. } // End for CCS
  2248. }
  2249. else if(gunType[gun_index] == 'G')
  2250. {
  2251. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2252. {
  2253. tempIndex = ((gun_index==2) ? 1: 0);
  2254. }
  2255. else
  2256. {
  2257. tempIndex = gun_index;
  2258. }
  2259. for (int index = 0; index < GB_QUANTITY; index++)
  2260. {
  2261. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2262. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2263. {
  2264. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2265. {
  2266. reqSampleMeter[gun_index] = 1;
  2267. }
  2268. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2269. {
  2270. reqClockAlignMeter[gun_index] = 1;
  2271. }
  2272. }
  2273. }// End for GB
  2274. }
  2275. else
  2276. {
  2277. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2278. {
  2279. tempIndex = 2;
  2280. }
  2281. else
  2282. {
  2283. tempIndex = gun_index;
  2284. }
  2285. for (int index = 0; index < AC_QUANTITY; index++)
  2286. {
  2287. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2288. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2289. {
  2290. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2291. {
  2292. reqSampleMeter[gun_index] = 1;
  2293. }
  2294. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2295. {
  2296. reqClockAlignMeter[gun_index] = 1;
  2297. }
  2298. }
  2299. }//End for AC
  2300. }
  2301. if(reqSampleMeter[gun_index] == 1)
  2302. {
  2303. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2304. storeTempStopTransaction(gun_index);
  2305. }
  2306. else if(reqClockAlignMeter[gun_index] == 1)
  2307. {
  2308. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2309. }
  2310. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2311. sleep(1);
  2312. }
  2313. //==============================================
  2314. // Check Connector reserved
  2315. //==============================================
  2316. //===============================
  2317. // Check if Reserve is expired
  2318. //===============================
  2319. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2320. {
  2321. double diff_t;
  2322. struct tm tp;
  2323. // current time
  2324. time_t t = time(NULL);
  2325. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2326. tp.tm_isdst = -1;
  2327. time_t utc = mktime(&tp);
  2328. diff_t = difftime(utc, t);
  2329. if(diff_t <= 0)
  2330. {
  2331. DEBUG_INFO("reserve expired.\n");
  2332. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2333. }
  2334. }//END OF Check if Reserve is expired
  2335. //==========================================
  2336. // csu trigger FirmwareStatusNotificationReq
  2337. //==========================================
  2338. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2339. {
  2340. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2341. }
  2342. //==========================================
  2343. // csu trigger CancelReservationConf
  2344. //==========================================
  2345. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2346. {
  2347. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2348. }
  2349. //==========================================
  2350. // csu trigger ChangeAvailabilityConf
  2351. //==========================================
  2352. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2353. {
  2354. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2355. }
  2356. //==========================================
  2357. // csu trigger UnlockConnectorConf
  2358. //==========================================
  2359. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2360. {
  2361. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2362. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2363. }
  2364. //==========================================
  2365. // csu trigger ReserveNowConf
  2366. //==========================================
  2367. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2368. {
  2369. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2370. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2371. }
  2372. //==========================================
  2373. // csu trigger DataTransferReq
  2374. //==========================================
  2375. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2376. {
  2377. sendDataTransferRequest(gun_index);
  2378. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2379. }
  2380. }
  2381. }
  2382. //==========================================
  2383. // send request routine
  2384. //==========================================
  2385. int sendAuthorizeRequest(int gun_index)
  2386. {
  2387. mtrace();
  2388. int result = FAIL;
  2389. char message[100]={0};
  2390. char guid[37];
  2391. char tempdata[65]={0};
  2392. DEBUG_INFO("sendAuthorizeRequest...\n");
  2393. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2394. //Local Authorize
  2395. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2396. {
  2397. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2398. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2399. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2400. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2401. result = PASS;
  2402. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2403. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2404. authorizeRetryTimes = 0;
  2405. return result;
  2406. }
  2407. 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))||
  2408. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2409. {
  2410. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2411. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2412. {
  2413. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2414. {
  2415. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2416. }
  2417. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2418. {
  2419. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2420. }
  2421. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  2422. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2423. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2424. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2425. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2426. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2427. authorizeRetryTimes = 0;
  2428. return result;
  2429. }
  2430. else
  2431. {
  2432. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  2433. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2434. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2435. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2436. result = PASS;
  2437. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2438. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2439. authorizeRetryTimes = 0;
  2440. return result;
  2441. }
  2442. }
  2443. //initailize struct Authorize
  2444. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2445. //get data from shared memory
  2446. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2447. random_uuid(guid);
  2448. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2449. LWS_Send(message);
  2450. sprintf(tempdata, "Authorize,%d", gun_index);
  2451. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2452. {
  2453. result = PASS;
  2454. DEBUG_INFO("Authorize mapItem pass\n");
  2455. }
  2456. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2457. return result;
  2458. }
  2459. int sendBootNotificationRequest(void)
  2460. {
  2461. mtrace();
  2462. int result = FAIL;
  2463. char message[500]={0}, payload[700]={0};
  2464. char guid[37]={0};
  2465. char tempdata[65]={0};
  2466. /*
  2467. int IsGunCharging = FALSE;
  2468. //check Transaction active
  2469. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2470. {
  2471. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2472. {
  2473. IsGunCharging = TRUE;
  2474. }
  2475. }
  2476. for (int index = 0; index < CCS_QUANTITY; index++)
  2477. {
  2478. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2479. {
  2480. IsGunCharging = TRUE;
  2481. }
  2482. }
  2483. for (int index = 0; index < GB_QUANTITY; index++)
  2484. {
  2485. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2486. {
  2487. IsGunCharging = TRUE;
  2488. }
  2489. }
  2490. for (int index = 0; index < AC_QUANTITY; index++)
  2491. {
  2492. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2493. {
  2494. IsGunCharging = TRUE;
  2495. }
  2496. }
  2497. if(IsGunCharging == TRUE)
  2498. {
  2499. server_sign = TRUE;
  2500. return result;
  2501. }
  2502. */
  2503. // Fill BootNotification fields
  2504. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2505. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2506. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2507. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2508. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2509. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2510. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2511. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2512. ShmOCPP16Data->ChargeBoxId
  2513. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2514. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2515. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2516. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2517. ,ShmOCPP16Data->BootNotification.CpIccid
  2518. ,ShmOCPP16Data->BootNotification.CpImsi);
  2519. random_uuid(guid);
  2520. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2521. LWS_Send(message);
  2522. sprintf(tempdata, "BootNotification,0");
  2523. 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*/)
  2524. {
  2525. result = PASS;
  2526. }
  2527. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2528. strcpy(queuedata,message);
  2529. return result;
  2530. }
  2531. int sendDataTransferRequest(int gun_index)
  2532. {
  2533. mtrace();
  2534. char message[1000]={0};
  2535. char guid[37]={0};
  2536. char tempdata[65]={0};
  2537. int result = FAIL;
  2538. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2539. random_uuid(guid);
  2540. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2541. MESSAGE_TYPE_CALL,
  2542. guid,
  2543. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2544. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2545. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2546. LWS_Send(message);
  2547. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2548. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2549. {
  2550. result = PASS;
  2551. DEBUG_INFO("DataTransfer mapItem pass\n");
  2552. }
  2553. return result;
  2554. }
  2555. int sendDiagnosticsStatusNotificationRequest(char *status)
  2556. {
  2557. mtrace();
  2558. int result = FAIL;
  2559. char message[110]={0};
  2560. char guid[37]={0};
  2561. char tempdata[65]={0};
  2562. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2563. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2564. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2565. random_uuid(guid);
  2566. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2567. LWS_Send(message);
  2568. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2569. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2570. {
  2571. result = PASS;
  2572. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2573. }
  2574. //#ifdef SystemLogMessage
  2575. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2576. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2577. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2578. //#endif
  2579. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2580. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2581. //record status
  2582. if(strcmp(status,"Idle")==0)
  2583. {
  2584. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2585. }
  2586. else if(strcmp(status,"Uploaded")==0)
  2587. {
  2588. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2589. }
  2590. else if(strcmp(status,"UploadFailed")==0)
  2591. {
  2592. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2593. }
  2594. else if(strcmp(status,"Uploading")==0)
  2595. {
  2596. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2597. }
  2598. return result;
  2599. }
  2600. int sendFirmwareStatusNotificationRequest(char *status)
  2601. {
  2602. mtrace();
  2603. int result = FAIL;
  2604. char message[110]={0};
  2605. char guid[37]={0};
  2606. char tempdata[65]={0};
  2607. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2608. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2609. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2610. random_uuid(guid);
  2611. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2612. LWS_Send(message);
  2613. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2614. 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*/)
  2615. {
  2616. result = PASS;
  2617. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2618. }
  2619. //#ifdef SystemLogMessage
  2620. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2621. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2622. //#endif
  2623. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2624. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2625. //record status
  2626. if(strcmp(status,"Downloaded")==0)
  2627. {
  2628. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2629. }
  2630. else if(strcmp(status,"DownloadFailed")==0)
  2631. {
  2632. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  2633. }
  2634. else if(strcmp(status,"Downloading")==0)
  2635. {
  2636. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2637. }
  2638. else if(strcmp(status,"Idle")==0)
  2639. {
  2640. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2641. }
  2642. else if(strcmp(status,"InstallationFailed")==0)
  2643. {
  2644. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2645. }
  2646. else if(strcmp(status,"Installing")==0)
  2647. {
  2648. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2649. }
  2650. else if(strcmp(status,"Installed")==0)
  2651. {
  2652. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2653. }
  2654. return result;
  2655. }
  2656. int sendHeartbeatRequest(int gun_index)
  2657. {
  2658. mtrace();
  2659. int result = FAIL;
  2660. char message[80]={0};
  2661. char guid[37]={0};
  2662. char tempdata[65]={0};
  2663. random_uuid(guid);
  2664. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2665. , MESSAGE_TYPE_CALL
  2666. , guid );
  2667. LWS_Send(message);
  2668. sprintf(tempdata, "Heartbeat,%d", 0);
  2669. 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*/)
  2670. {
  2671. result = PASS;
  2672. }
  2673. return result;
  2674. }
  2675. int sendStartTransactionRequest(int gun_index)
  2676. {
  2677. mtrace();
  2678. int result = FAIL;
  2679. char message[250]={0};
  2680. char guid[37]={0};
  2681. struct timeval tmnow;
  2682. struct tm *tm;
  2683. char buf[28];//, usec_buf[6];
  2684. char tempdata[65]={0};
  2685. int tempIndex = 0;
  2686. DEBUG_INFO("sendStartTransactionRequest...\n");
  2687. gettimeofday(&tmnow, NULL);
  2688. time_t t;
  2689. t = time(NULL);
  2690. /*UTC time and date*/
  2691. tm = gmtime(&t);
  2692. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2693. #if 0 // remove temporally
  2694. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2695. strcat(buf,".");
  2696. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2697. strcat(buf,usec_buf);
  2698. #endif
  2699. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2700. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2701. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2702. // clear StartTransaction Response
  2703. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2704. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2705. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2706. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2707. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2708. if(gunType[gun_index] == 'J')
  2709. {
  2710. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2711. {
  2712. tempIndex = ((gun_index==2) ? 1: 0);
  2713. }
  2714. else
  2715. {
  2716. tempIndex = gun_index;
  2717. }
  2718. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2719. {
  2720. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2721. {
  2722. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  2723. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2724. }
  2725. }
  2726. }
  2727. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2728. {
  2729. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2730. {
  2731. tempIndex = ((gun_index==2) ? 1: 0);
  2732. }
  2733. else
  2734. {
  2735. tempIndex = gun_index;
  2736. }
  2737. for (int index = 0; index < CCS_QUANTITY; index++)
  2738. {
  2739. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2740. {
  2741. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  2742. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  2743. }
  2744. }
  2745. }
  2746. else if(gunType[gun_index] == 'G')
  2747. {
  2748. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2749. {
  2750. tempIndex = ((gun_index==2) ? 1: 0);
  2751. }
  2752. else
  2753. {
  2754. tempIndex = gun_index;
  2755. }
  2756. for (int index = 0; index < GB_QUANTITY; index++)
  2757. {
  2758. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2759. {
  2760. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  2761. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  2762. }
  2763. }
  2764. }
  2765. else
  2766. {
  2767. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2768. {
  2769. tempIndex = 2;
  2770. }
  2771. else
  2772. {
  2773. tempIndex = gun_index;
  2774. }
  2775. for (int index = 0; index < AC_QUANTITY; index++)
  2776. {
  2777. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2778. {
  2779. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  2780. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  2781. }
  2782. }
  2783. }
  2784. random_uuid(guid);
  2785. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  2786. {
  2787. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  2788. , gun_index +1
  2789. , MESSAGE_TYPE_CALL
  2790. , guid
  2791. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2792. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2793. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2794. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2795. }
  2796. else
  2797. {
  2798. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  2799. , gun_index +1
  2800. , MESSAGE_TYPE_CALL
  2801. , guid
  2802. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2803. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2804. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2805. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  2806. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2807. }
  2808. #if 1
  2809. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  2810. 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*/)
  2811. {
  2812. result = PASS;
  2813. }
  2814. #endif
  2815. strcpy(queuedata, message);
  2816. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2817. /*
  2818. if(GetTransactionQueueNum() == 1)
  2819. {
  2820. LWS_Send(message + 2);
  2821. }*/
  2822. return result;
  2823. }
  2824. int sendStatusNotificationRequest(int gun_index)
  2825. {
  2826. mtrace();
  2827. int result = FAIL;
  2828. char message[600]={0};
  2829. char guid[37];
  2830. int currentStatus = 0;
  2831. struct timeval tmnow;
  2832. struct tm *tm;
  2833. char buf[28];//, usec_buf[6];
  2834. char tempdata[65]={0};
  2835. int tempIndex = 0;
  2836. gettimeofday(&tmnow, NULL);
  2837. time_t t;
  2838. t = time(NULL);
  2839. /*UTC time and date*/
  2840. tm = gmtime(&t);
  2841. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2842. #if 0 // remove temporally
  2843. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2844. strcat(buf,".");
  2845. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2846. strcat(buf,usec_buf);
  2847. #endif
  2848. printf("%s",buf);
  2849. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  2850. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  2851. // it's option
  2852. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  2853. /*
  2854. enum _SYSTEM_STATUS
  2855. {
  2856. S_BOOTING = 0,
  2857. S_IDLE, = 1
  2858. S_AUTHORIZING, =2
  2859. S_REASSIGN_CHECK, =3
  2860. S_REASSIGN, =4
  2861. S_PRECHARGE, =5
  2862. S_PREPARING_FOR_EV, =6
  2863. S_PREPARING_FOR_EVSE, =7
  2864. S_CHARGING, =8
  2865. S_TERMINATING, =9
  2866. S_COMPLETE, =10
  2867. S_ALARM, =11
  2868. S_FAULT =12
  2869. }
  2870. */
  2871. //check Transaction active
  2872. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2873. if(gunType[gun_index] == 'J')
  2874. {
  2875. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2876. {
  2877. tempIndex = ((gun_index==2) ? 1: 0);
  2878. }
  2879. else
  2880. {
  2881. tempIndex = gun_index;
  2882. }
  2883. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2884. {
  2885. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  2886. {
  2887. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  2888. {
  2889. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  2890. {
  2891. currentStatus = 1; //OCPP Status: Preparing
  2892. }
  2893. else
  2894. {
  2895. currentStatus = 0; //OCPP Status: Available
  2896. }
  2897. }
  2898. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  2899. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  2900. ) //S_PRECHARGE
  2901. {
  2902. currentStatus = 1; //OCPP Status: Preparing
  2903. }
  2904. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2905. {
  2906. currentStatus = 2; //OCPP Status: Charging
  2907. }
  2908. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  2909. {
  2910. currentStatus = 5; //OCPP Status: Finishing
  2911. }
  2912. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  2913. {
  2914. currentStatus = 4; //OCPP Status: SuspendedEV
  2915. }
  2916. 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
  2917. {
  2918. currentStatus = 7; //OCPP Status: Unavailable
  2919. }
  2920. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  2921. {
  2922. currentStatus = 8; //OCPP Status: Faulted
  2923. }
  2924. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  2925. {
  2926. currentStatus = 6; //OCPP Status: Reserved
  2927. }
  2928. } //end of the same index
  2929. }//end of for CHAdeMO_QUANTITY
  2930. }
  2931. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2932. {
  2933. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2934. {
  2935. tempIndex = ((gun_index==2) ? 1: 0);
  2936. }
  2937. else
  2938. {
  2939. tempIndex = gun_index;
  2940. }
  2941. for (int index = 0; index < CCS_QUANTITY; index++)
  2942. {
  2943. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2944. {
  2945. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  2946. {
  2947. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  2948. {
  2949. currentStatus = 1; //OCPP Status: Preparing
  2950. }
  2951. else
  2952. {
  2953. currentStatus = 0; //OCPP Status: Available
  2954. }
  2955. }
  2956. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  2957. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  2958. ) //S_PRECHARGE
  2959. {
  2960. currentStatus = 1; //OCPP Status: Preparing
  2961. }
  2962. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2963. {
  2964. currentStatus = 2; //OCPP Status: Charging
  2965. }
  2966. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  2967. {
  2968. currentStatus = 5; //OCPP Status: Finishing
  2969. }
  2970. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  2971. {
  2972. currentStatus = 4; //OCPP Status: SuspendedEV
  2973. }
  2974. 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
  2975. {
  2976. currentStatus = 7; //OCPP Status : Unavailable
  2977. }
  2978. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  2979. {
  2980. currentStatus = 8; //OCPP Status: Faulted
  2981. }
  2982. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  2983. {
  2984. currentStatus = 6; //OCPP Status: Reserved
  2985. }
  2986. } //end of the same index
  2987. } // end of for CCS_QUANTITY
  2988. }
  2989. else if(gunType[gun_index] == 'G')
  2990. {
  2991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2992. {
  2993. tempIndex = ((gun_index==2) ? 1: 0);
  2994. }
  2995. else
  2996. {
  2997. tempIndex = gun_index;
  2998. }
  2999. for (int index = 0; index < GB_QUANTITY; index++)
  3000. {
  3001. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3002. {
  3003. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3004. {
  3005. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3006. {
  3007. currentStatus = 1; //OCPP Status: Preparing
  3008. }
  3009. else
  3010. {
  3011. currentStatus = 0; //OCPP Status: Available
  3012. }
  3013. }
  3014. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3015. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3016. ) //S_PRECHARGE
  3017. {
  3018. currentStatus = 1; //OCPP Status: Preparing
  3019. }
  3020. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3021. {
  3022. currentStatus = 2; //OCPP Status: Charging
  3023. }
  3024. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3025. {
  3026. currentStatus = 5; //OCPP Status: Finishing
  3027. }
  3028. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3029. {
  3030. currentStatus = 4; //OCPP Status: SuspendedEV
  3031. }
  3032. 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
  3033. {
  3034. currentStatus = 7; //OCPP Status: Unavailable
  3035. }
  3036. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3037. {
  3038. currentStatus = 8; //OCPP Status: Faulted
  3039. }
  3040. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3041. {
  3042. currentStatus = 6; //OCPP Status: Reserved
  3043. }
  3044. } //end of the same index
  3045. } // end of for GB_QUANTITY
  3046. }
  3047. else
  3048. {
  3049. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3050. {
  3051. tempIndex = 2;
  3052. }
  3053. else
  3054. {
  3055. tempIndex = gun_index;
  3056. }
  3057. for (int index = 0; index < AC_QUANTITY; index++)
  3058. {
  3059. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3060. {
  3061. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3062. {
  3063. 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))
  3064. {
  3065. currentStatus = 1; //OCPP Status: Preparing
  3066. }
  3067. else
  3068. {
  3069. currentStatus = 0; //OCPP Status: Available
  3070. }
  3071. }
  3072. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3073. {
  3074. currentStatus = 1; //OCPP Status: Preparing
  3075. }
  3076. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3077. {
  3078. currentStatus = 2; //OCPP Status: Charging
  3079. }
  3080. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3081. {
  3082. currentStatus = 5; //OCPP Status: Finishing
  3083. }
  3084. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3085. {
  3086. currentStatus = 4; //OCPP Status: SuspendedEV
  3087. }
  3088. 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
  3089. {
  3090. currentStatus = 7; //OCPP Status: Unavailable
  3091. }
  3092. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3093. {
  3094. currentStatus = 8; //OCPP Status: Faulted
  3095. }
  3096. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3097. {
  3098. currentStatus = 6; //OCPP Status: Reserved
  3099. }
  3100. }//end of the same index
  3101. }//end of for AC_QUANTITY
  3102. }
  3103. //it's option
  3104. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3105. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3106. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3107. random_uuid(guid);
  3108. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3109. , MESSAGE_TYPE_CALL
  3110. , guid
  3111. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3112. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3113. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3114. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3115. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3116. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3117. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3118. LWS_Send(message);
  3119. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3120. 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*/)
  3121. {
  3122. //DEBUG_ERROR("statusNotification mapitem pass");
  3123. result = PASS;
  3124. }
  3125. return result;
  3126. }
  3127. int sendStopTransactionRequest(int gun_index)
  3128. {
  3129. mtrace();
  3130. int result = FAIL;
  3131. //char message[1500]={0};
  3132. char guid[37]={0};
  3133. char tempdata[65]={0};
  3134. int tempIndex = 0;
  3135. //int idx_sample=0;
  3136. DEBUG_ERROR("sendStopTransactionRequest \n");
  3137. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3138. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3139. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3140. if(gunType[gun_index] == 'J')
  3141. {
  3142. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3143. {
  3144. tempIndex = ((gun_index==2) ? 1: 0);
  3145. }
  3146. else
  3147. {
  3148. tempIndex = gun_index;
  3149. }
  3150. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3151. {
  3152. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3153. {
  3154. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3155. }
  3156. }// END OF CHAdeMO_QUANTITY
  3157. }
  3158. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3159. {
  3160. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3161. {
  3162. tempIndex = ((gun_index==2) ? 1: 0);
  3163. }
  3164. else
  3165. {
  3166. tempIndex = gun_index;
  3167. }
  3168. for (int index = 0; index < CCS_QUANTITY; index++)
  3169. {
  3170. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3171. {
  3172. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3173. }
  3174. }// END OF CCS_QUANTITY
  3175. }
  3176. else if(gunType[gun_index] == 'G')
  3177. {
  3178. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3179. {
  3180. tempIndex = ((gun_index==2) ? 1: 0);
  3181. }
  3182. else
  3183. {
  3184. tempIndex = gun_index;
  3185. }
  3186. for (int index = 0; index < GB_QUANTITY; index++)
  3187. {
  3188. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3189. {
  3190. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3191. }
  3192. }// END OF GB_QUANTITY
  3193. }
  3194. else
  3195. {
  3196. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3197. {
  3198. tempIndex = 2;
  3199. }
  3200. else
  3201. {
  3202. tempIndex = gun_index;
  3203. }
  3204. for (int index = 0; index < AC_QUANTITY; index++)
  3205. {
  3206. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3207. {
  3208. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3209. }
  3210. }// END OF AC_QUANTITY
  3211. }
  3212. //====================================== Stop Transaction Time =====================================================
  3213. struct timeval tmnow;
  3214. struct tm *tm;
  3215. char buf[28];//, usec_buf[6];
  3216. gettimeofday(&tmnow, NULL);
  3217. time_t t;
  3218. t = time(NULL);
  3219. /*UTC time and date*/
  3220. tm = gmtime(&t);
  3221. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3222. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3223. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3224. random_uuid(guid);
  3225. /***********************************transactionData******************************************************/
  3226. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3227. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3228. //=================================
  3229. // Transaction_Begin
  3230. //=================================
  3231. //============================================ Energy.Active.Import.Interval ================================
  3232. //idx_sample=0;
  3233. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  3234. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3235. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3236. 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*/]);
  3237. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3238. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3239. {
  3240. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3241. }
  3242. else
  3243. {
  3244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3245. }
  3246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3247. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3248. //=================================
  3249. // Transaction_End
  3250. //=================================
  3251. // ================================= Current.Import L1 ===============================================
  3252. //idx_sample=1;
  3253. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3254. if(gunType[gun_index] == 'J')
  3255. {
  3256. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3257. {
  3258. tempIndex = ((gun_index==2) ? 1: 0);
  3259. }
  3260. else
  3261. {
  3262. tempIndex = gun_index;
  3263. }
  3264. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3265. {
  3266. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3267. {
  3268. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3269. }
  3270. }// End of for CHAdeMO_QUANTITY
  3271. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3272. }
  3273. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3274. {
  3275. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3276. {
  3277. tempIndex = ((gun_index==2) ? 1: 0);
  3278. }
  3279. else
  3280. {
  3281. tempIndex = gun_index;
  3282. }
  3283. for (int index = 0; index < CCS_QUANTITY; index++)
  3284. {
  3285. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3286. {
  3287. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3288. }
  3289. }// End of for CCS_QUANTITY
  3290. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3291. }
  3292. else if(gunType[gun_index] == 'G')
  3293. {
  3294. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3295. {
  3296. tempIndex = ((gun_index==2) ? 1: 0);
  3297. }
  3298. else
  3299. {
  3300. tempIndex = gun_index;
  3301. }
  3302. for (int index = 0; index < GB_QUANTITY; index++)
  3303. {
  3304. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3305. {
  3306. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3307. }
  3308. }// End of for GB_QUANTITY
  3309. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3310. }
  3311. else
  3312. {
  3313. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3314. {
  3315. tempIndex = 2;
  3316. }
  3317. else
  3318. {
  3319. tempIndex = gun_index;
  3320. }
  3321. for (int index = 0; index < AC_QUANTITY; index++)
  3322. {
  3323. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3324. {
  3325. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3326. }
  3327. }// End of for AC_QUANTITY
  3328. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3329. }
  3330. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3331. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3332. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3333. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3334. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3335. // ================================= Energy.Active.Import.Interval ==============================================
  3336. //idx_sample=2;
  3337. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3338. if(gunType[gun_index] == 'J')
  3339. {
  3340. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3341. {
  3342. tempIndex = ((gun_index==2) ? 1: 0);
  3343. }
  3344. else
  3345. {
  3346. tempIndex = gun_index;
  3347. }
  3348. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3349. {
  3350. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3351. {
  3352. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3353. }
  3354. }// END OF CHAdeMO_QUANTITY
  3355. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3356. }
  3357. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3358. {
  3359. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3360. {
  3361. tempIndex = ((gun_index==2) ? 1: 0);
  3362. }
  3363. else
  3364. {
  3365. tempIndex = gun_index;
  3366. }
  3367. for (int index = 0; index < CCS_QUANTITY; index++)
  3368. {
  3369. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3370. {
  3371. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3372. }
  3373. }// END OF CCS_QUANTITY
  3374. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3375. }
  3376. else if(gunType[gun_index] == 'G')
  3377. {
  3378. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3379. {
  3380. tempIndex = ((gun_index==2) ? 1: 0);
  3381. }
  3382. else
  3383. {
  3384. tempIndex = gun_index;
  3385. }
  3386. for (int index = 0; index < GB_QUANTITY; index++)
  3387. {
  3388. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3389. {
  3390. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3391. }
  3392. }// END OF GB_QUANTITY
  3393. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3394. }
  3395. else
  3396. {
  3397. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3398. {
  3399. tempIndex = 2;
  3400. }
  3401. else
  3402. {
  3403. tempIndex = gun_index;
  3404. }
  3405. for (int index = 0; index < AC_QUANTITY; index++)
  3406. {
  3407. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3408. {
  3409. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3410. }
  3411. }// END OF AC_QUANTITY
  3412. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3413. }
  3414. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3415. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3416. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3417. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3418. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3419. //=================================== Power.Active.Import ==================================================
  3420. //idx_sample=3;
  3421. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3422. if(gunType[gun_index] == 'J')
  3423. {
  3424. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3425. {
  3426. tempIndex = ((gun_index==2) ? 1: 0);
  3427. }
  3428. else
  3429. {
  3430. tempIndex = gun_index;
  3431. }
  3432. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3433. {
  3434. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3435. {
  3436. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3437. }
  3438. } // End for CHAdeMO_QUANTITY
  3439. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3440. }
  3441. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3442. {
  3443. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3444. {
  3445. tempIndex = ((gun_index==2) ? 1: 0);
  3446. }
  3447. else
  3448. {
  3449. tempIndex = gun_index;
  3450. }
  3451. for (int index = 0; index < CCS_QUANTITY; index++)
  3452. {
  3453. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3454. {
  3455. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3456. }
  3457. } // END for CCS_QUANTITY
  3458. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3459. }
  3460. else if(gunType[gun_index] == 'G')
  3461. {
  3462. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3463. {
  3464. tempIndex = ((gun_index==2) ? 1: 0);
  3465. }
  3466. else
  3467. {
  3468. tempIndex = gun_index;
  3469. }
  3470. for (int index = 0; index < GB_QUANTITY; index++)
  3471. {
  3472. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3473. {
  3474. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3475. }
  3476. }// END for GB_QUANTITY
  3477. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3478. }
  3479. else
  3480. {
  3481. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3482. {
  3483. tempIndex = 2;
  3484. }
  3485. else
  3486. {
  3487. tempIndex = gun_index;
  3488. }
  3489. for (int index = 0; index < AC_QUANTITY; index++)
  3490. {
  3491. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3492. {
  3493. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3494. }
  3495. } // END for AC_QUANTITY
  3496. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3497. }
  3498. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3499. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3500. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3501. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3502. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3503. //============================ Voltage L1 ====================================
  3504. //idx_sample=4;
  3505. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3506. if(gunType[gun_index] == 'J')
  3507. {
  3508. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3509. {
  3510. tempIndex = ((gun_index==2) ? 1: 0);
  3511. }
  3512. else
  3513. {
  3514. tempIndex = gun_index;
  3515. }
  3516. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3517. {
  3518. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3519. {
  3520. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3521. }
  3522. } // END OF FOR CHAdeMO_QUANTITY
  3523. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3524. }
  3525. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3526. {
  3527. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3528. {
  3529. tempIndex = ((gun_index==2) ? 1: 0);
  3530. }
  3531. else
  3532. {
  3533. tempIndex = gun_index;
  3534. }
  3535. for (int index = 0; index < CCS_QUANTITY; index++)
  3536. {
  3537. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3538. {
  3539. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3540. }
  3541. } // END OF FOR CCS_QUANTITY
  3542. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3543. }
  3544. else if(gunType[gun_index] == 'G')
  3545. {
  3546. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3547. {
  3548. tempIndex = ((gun_index==2) ? 1: 0);
  3549. }
  3550. else
  3551. {
  3552. tempIndex = gun_index;
  3553. }
  3554. for (int index = 0; index < GB_QUANTITY; index++)
  3555. {
  3556. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3557. {
  3558. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3559. }
  3560. } // END OF FOR GB_QUANTITY
  3561. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3562. }
  3563. else
  3564. {
  3565. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3566. {
  3567. tempIndex = 2;
  3568. }
  3569. else
  3570. {
  3571. tempIndex = gun_index;
  3572. }
  3573. for (int index = 0; index < AC_QUANTITY; index++)
  3574. {
  3575. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3576. {
  3577. 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
  3578. }
  3579. } // END OF FOR AC_QUANTITY
  3580. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3581. }
  3582. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3583. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3584. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3585. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3586. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3587. //====================== SoC ================================
  3588. //idx_sample=5;
  3589. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3590. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3591. {
  3592. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3593. {
  3594. tempIndex = ((gun_index==2) ? 1: 0);
  3595. }
  3596. else
  3597. {
  3598. tempIndex = gun_index;
  3599. }
  3600. if(gunType[gun_index] == 'J')
  3601. {
  3602. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3603. {
  3604. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3605. {
  3606. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3607. }
  3608. }
  3609. }
  3610. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3611. {
  3612. for (int index = 0; index < CCS_QUANTITY; index++)
  3613. {
  3614. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3615. {
  3616. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3617. }
  3618. }
  3619. }
  3620. else if(gunType[gun_index] == 'G')
  3621. {
  3622. for (int index = 0; index < GB_QUANTITY; index++)
  3623. {
  3624. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3625. {
  3626. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  3627. }
  3628. }
  3629. }
  3630. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3631. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  3632. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  3633. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  3634. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  3635. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  3636. } // END FOR DC CASE
  3637. // ================================= Current.Import L2 ===============================================
  3638. //idx_sample=6;
  3639. // AC 3 phse L2 current
  3640. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3641. {
  3642. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3643. {
  3644. tempIndex = 2;
  3645. }
  3646. else
  3647. {
  3648. tempIndex = gun_index;
  3649. }
  3650. for (int index = 0; index < AC_QUANTITY; index++)
  3651. {
  3652. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3653. {
  3654. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  3655. }
  3656. }// End of for AC_QUANTITY
  3657. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  3658. }
  3659. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3660. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  3661. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  3662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  3663. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3664. // ================================= Current.Import L3 ===============================================
  3665. //idx_sample=7;
  3666. // AC 3 phse L3 current
  3667. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3668. {
  3669. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3670. {
  3671. tempIndex = 2;
  3672. }
  3673. else
  3674. {
  3675. tempIndex = gun_index;
  3676. }
  3677. for (int index = 0; index < AC_QUANTITY; index++)
  3678. {
  3679. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3680. {
  3681. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  3682. }
  3683. }// End of for AC_QUANTITY
  3684. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  3685. }
  3686. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3687. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  3688. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  3689. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  3690. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3691. //============================ Voltage L2 ====================================
  3692. //idx_sample=8;
  3693. // AC 3 phse L2 voltage
  3694. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3695. {
  3696. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3697. {
  3698. tempIndex = 2;
  3699. }
  3700. else
  3701. {
  3702. tempIndex = gun_index;
  3703. }
  3704. for (int index = 0; index < AC_QUANTITY; index++)
  3705. {
  3706. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3707. {
  3708. 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
  3709. }
  3710. } // END OF FOR AC_QUANTITY
  3711. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  3712. }
  3713. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3714. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  3715. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  3716. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  3717. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3718. //============================ Voltage L3 ====================================
  3719. //idx_sample=8;
  3720. // AC 3 phse L3 voltage
  3721. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3722. {
  3723. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3724. {
  3725. tempIndex = 2;
  3726. }
  3727. else
  3728. {
  3729. tempIndex = gun_index;
  3730. }
  3731. for (int index = 0; index < AC_QUANTITY; index++)
  3732. {
  3733. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3734. {
  3735. 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
  3736. }
  3737. } // END OF FOR AC_QUANTITY
  3738. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  3739. }
  3740. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3741. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  3742. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  3743. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  3744. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3745. //================================================ Message create ====================================================
  3746. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3747. {
  3748. 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\"}]}]}]"
  3749. ,gun_index+1
  3750. ,MESSAGE_TYPE_CALL
  3751. ,guid
  3752. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3753. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3754. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3755. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3756. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3757. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3758. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3759. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3760. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3761. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3762. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3763. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3764. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3765. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3766. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3767. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3768. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3769. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3770. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3771. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3772. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3773. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3774. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3775. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3776. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3777. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3778. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3779. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3780. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3781. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3782. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3783. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3784. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3785. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3786. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3787. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3788. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3789. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3790. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3791. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3792. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3793. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  3794. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  3795. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  3796. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  3797. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  3798. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  3799. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  3800. );
  3801. }
  3802. else
  3803. {
  3804. if((ShmSysConfigAndInfo->SysConfig.ModelName[2]!='Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2]!='W'))
  3805. {
  3806. 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\"}]}]}]"
  3807. ,gun_index+1
  3808. ,MESSAGE_TYPE_CALL
  3809. ,guid
  3810. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3811. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3812. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3813. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3814. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3815. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3816. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3817. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3818. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3819. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3820. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3821. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3822. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3823. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3824. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3825. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3826. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3827. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3828. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3829. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3830. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3831. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3832. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3833. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3834. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3835. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3836. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3837. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3838. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3839. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3840. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3841. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3842. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3843. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3844. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3845. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3846. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3847. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3848. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3849. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3850. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3851. );
  3852. }
  3853. else
  3854. {
  3855. 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\"}]}]}]"
  3856. ,gun_index+1
  3857. ,MESSAGE_TYPE_CALL
  3858. ,guid
  3859. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3860. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3861. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3862. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3863. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3864. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3865. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3866. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3867. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3868. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3869. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3870. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3871. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3890. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3894. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3895. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3896. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3897. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3898. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3899. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3900. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  3901. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  3902. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  3903. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  3904. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  3905. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  3906. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  3907. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  3908. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  3909. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  3910. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  3911. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  3912. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  3913. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  3914. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  3915. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  3916. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  3917. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  3918. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  3919. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  3920. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  3921. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  3922. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  3923. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  3924. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  3925. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  3926. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  3927. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  3928. );
  3929. }
  3930. }
  3931. #if 1 // for TempStopTransaction
  3932. //Delete TempStopTransaction
  3933. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  3934. {
  3935. remove("/Storage/OCPP/TempStopTransaction"); // remove file "TempStopTransaction"
  3936. }
  3937. #endif
  3938. #if 1
  3939. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  3940. if(hashmap_operation(0, guid, tempdata) == 1)
  3941. {
  3942. result = PASS;
  3943. DEBUG_INFO("StopTransaction mapitem pass\n");
  3944. }
  3945. #endif
  3946. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3947. /*
  3948. if(GetTransactionQueueNum() == 1)
  3949. {
  3950. LWS_Send(queuedata+2);
  3951. }*/
  3952. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  3953. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  3954. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  3955. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  3956. {
  3957. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  3958. }
  3959. //for test
  3960. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3961. return result;
  3962. }
  3963. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  3964. {
  3965. mtrace();
  3966. int result = FAIL;
  3967. char guid[37]={0};
  3968. char tempdata[65]={0};
  3969. int tempIndex = 0;
  3970. DEBUG_INFO("sendMeterValuesRequest ...\n");
  3971. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  3972. /*
  3973. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0) && (ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  3974. {
  3975. DEBUG_INFO("NOT SENT METER Vlaue\n");
  3976. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  3977. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  3978. return result;
  3979. }*/
  3980. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  3981. {
  3982. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  3983. }
  3984. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3985. //set value
  3986. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  3987. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) ? ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId : 0);
  3988. random_uuid(guid);
  3989. //UTC Date time
  3990. struct timeval tmnow;
  3991. struct tm *tm;
  3992. char buf[28];//, usec_buf[6];
  3993. gettimeofday(&tmnow, NULL);
  3994. time_t t;
  3995. t = time(NULL);
  3996. /*UTC time and date*/
  3997. tm = gmtime(&t);
  3998. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3999. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4000. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4001. //idx_sample=0;
  4002. //********************************(1)Current.Import L1************************************************/
  4003. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4004. if(gunType[gun_index] == 'J')
  4005. {
  4006. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4007. {
  4008. tempIndex = ((gun_index==2) ? 1: 0);
  4009. }
  4010. else
  4011. {
  4012. tempIndex = gun_index;
  4013. }
  4014. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4015. {
  4016. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4017. {
  4018. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4019. }
  4020. }
  4021. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4022. }
  4023. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4024. {
  4025. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4026. {
  4027. tempIndex = ((gun_index==2) ? 1: 0);
  4028. }
  4029. else
  4030. {
  4031. tempIndex = gun_index;
  4032. }
  4033. for (int index = 0; index < CCS_QUANTITY; index++)
  4034. {
  4035. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4036. {
  4037. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4038. }
  4039. }
  4040. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4041. }
  4042. else if(gunType[gun_index] == 'G')
  4043. {
  4044. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4045. {
  4046. tempIndex = ((gun_index==2) ? 1: 0);
  4047. }
  4048. else
  4049. {
  4050. tempIndex = gun_index;
  4051. }
  4052. for (int index = 0; index < GB_QUANTITY; index++)
  4053. {
  4054. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4055. {
  4056. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4057. }
  4058. }
  4059. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4060. }
  4061. else
  4062. {
  4063. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4064. {
  4065. tempIndex = 2;
  4066. }
  4067. else
  4068. {
  4069. tempIndex = gun_index;
  4070. }
  4071. for (int index = 0; index < AC_QUANTITY; index++)
  4072. {
  4073. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4074. {
  4075. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4076. }
  4077. }
  4078. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4079. }
  4080. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4081. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4082. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4083. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4084. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4085. //idx_sample=1;
  4086. //********************************(2)Energy.Active.Import.Register ************************************************/
  4087. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4088. if(gunType[gun_index] == 'J')
  4089. {
  4090. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4091. {
  4092. tempIndex = ((gun_index==2) ? 1: 0);
  4093. }
  4094. else
  4095. {
  4096. tempIndex = gun_index;
  4097. }
  4098. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4099. {
  4100. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4101. {
  4102. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4103. }
  4104. }
  4105. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4106. }
  4107. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4108. {
  4109. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4110. {
  4111. tempIndex = ((gun_index==2) ? 1: 0);
  4112. }
  4113. else
  4114. {
  4115. tempIndex = gun_index;
  4116. }
  4117. for (int index = 0; index < CCS_QUANTITY; index++)
  4118. {
  4119. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4120. {
  4121. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4122. }
  4123. }
  4124. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4125. }
  4126. else if(gunType[gun_index] == 'G')
  4127. {
  4128. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4129. {
  4130. tempIndex = ((gun_index==2) ? 1: 0);
  4131. }
  4132. else
  4133. {
  4134. tempIndex = gun_index;
  4135. }
  4136. for (int index = 0; index < GB_QUANTITY; index++)
  4137. {
  4138. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4139. {
  4140. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4141. }
  4142. }
  4143. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4144. }
  4145. else
  4146. {
  4147. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4148. {
  4149. tempIndex = 2;
  4150. }
  4151. else
  4152. {
  4153. tempIndex = gun_index;
  4154. }
  4155. for (int index = 0; index < AC_QUANTITY; index++)
  4156. {
  4157. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4158. {
  4159. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4160. }
  4161. }
  4162. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4163. }
  4164. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4165. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4166. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4167. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4168. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4169. //idx_sample=2;
  4170. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4171. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4172. if(gunType[gun_index] == 'J')
  4173. {
  4174. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4175. {
  4176. tempIndex = ((gun_index==2) ? 1: 0);
  4177. }
  4178. else
  4179. {
  4180. tempIndex = gun_index;
  4181. }
  4182. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4183. {
  4184. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4185. {
  4186. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4187. }
  4188. } // END OF FOR CHAdeMO_QUANTITY
  4189. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4190. }
  4191. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4192. {
  4193. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4194. {
  4195. tempIndex = ((gun_index==2) ? 1: 0);
  4196. }
  4197. else
  4198. {
  4199. tempIndex = gun_index;
  4200. }
  4201. for (int index = 0; index < CCS_QUANTITY; index++)
  4202. {
  4203. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4204. {
  4205. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4206. }
  4207. } // END OF CCS_QUANTITY
  4208. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4209. }
  4210. else if(gunType[gun_index] == 'G')
  4211. {
  4212. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4213. {
  4214. tempIndex = ((gun_index==2) ? 1: 0);
  4215. }
  4216. else
  4217. {
  4218. tempIndex = gun_index;
  4219. }
  4220. for (int index = 0; index < GB_QUANTITY; index++)
  4221. {
  4222. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4223. {
  4224. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4225. }
  4226. } // END OF GB_QUANTITY
  4227. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4228. }
  4229. else
  4230. {
  4231. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4232. {
  4233. tempIndex = 2;
  4234. }
  4235. else
  4236. {
  4237. tempIndex = gun_index;
  4238. }
  4239. for (int index = 0; index < AC_QUANTITY; index++)
  4240. {
  4241. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4242. {
  4243. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4244. }
  4245. }
  4246. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4247. }
  4248. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4249. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4250. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4251. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4252. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4253. //idx_sample=3;
  4254. //********************************(4)Power.Active.Import************************************************/
  4255. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4256. if(gunType[gun_index] == 'J')
  4257. {
  4258. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4259. {
  4260. tempIndex = ((gun_index==2) ? 1: 0);
  4261. }
  4262. else
  4263. {
  4264. tempIndex = gun_index;
  4265. }
  4266. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4267. {
  4268. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4269. {
  4270. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4271. }
  4272. } // END OF FOR
  4273. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4274. }
  4275. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4276. {
  4277. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4278. {
  4279. tempIndex = ((gun_index==2) ? 1: 0);
  4280. }
  4281. else
  4282. {
  4283. tempIndex = gun_index;
  4284. }
  4285. for (int index = 0; index < CCS_QUANTITY; index++)
  4286. {
  4287. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4288. {
  4289. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4290. }
  4291. }
  4292. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4293. }
  4294. else if(gunType[gun_index] == 'G')
  4295. {
  4296. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4297. {
  4298. tempIndex = ((gun_index==2) ? 1: 0);
  4299. }
  4300. else
  4301. {
  4302. tempIndex = gun_index;
  4303. }
  4304. for (int index = 0; index < GB_QUANTITY; index++)
  4305. {
  4306. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4307. {
  4308. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4309. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4310. }
  4311. }
  4312. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4313. }
  4314. else
  4315. {
  4316. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4317. {
  4318. tempIndex = 2;
  4319. }
  4320. else
  4321. {
  4322. tempIndex = gun_index;
  4323. }
  4324. for (int index = 0; index < AC_QUANTITY; index++)
  4325. {
  4326. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4327. {
  4328. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4329. }
  4330. }
  4331. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4332. }
  4333. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4334. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4335. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4336. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4337. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4338. //idx_sample=4;
  4339. //***********************************************(5)VOLTAGE L1******************************************************/
  4340. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4341. if(gunType[gun_index] == 'J')
  4342. {
  4343. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4344. {
  4345. tempIndex = ((gun_index==2) ? 1: 0);
  4346. }
  4347. else
  4348. {
  4349. tempIndex = gun_index;
  4350. }
  4351. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4352. {
  4353. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4354. {
  4355. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4356. }
  4357. }
  4358. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4359. }
  4360. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4361. {
  4362. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4363. {
  4364. tempIndex = ((gun_index==2) ? 1: 0);
  4365. }
  4366. else
  4367. {
  4368. tempIndex = gun_index;
  4369. }
  4370. for (int index = 0; index < CCS_QUANTITY; index++)
  4371. {
  4372. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4373. {
  4374. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4375. }
  4376. }
  4377. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4378. }
  4379. else if(gunType[gun_index] == 'G')
  4380. {
  4381. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4382. {
  4383. tempIndex = ((gun_index==2) ? 1: 0);
  4384. }
  4385. else
  4386. {
  4387. tempIndex = gun_index;
  4388. }
  4389. for (int index = 0; index < GB_QUANTITY; index++)
  4390. {
  4391. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4392. {
  4393. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4394. }
  4395. }
  4396. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4397. }
  4398. else
  4399. {
  4400. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4401. {
  4402. tempIndex = 2;
  4403. }
  4404. else
  4405. {
  4406. tempIndex = gun_index;
  4407. }
  4408. for (int index = 0; index < AC_QUANTITY; index++)
  4409. {
  4410. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4411. {
  4412. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4413. }
  4414. }
  4415. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4416. }
  4417. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4418. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4419. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4420. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4421. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4422. //***********************************************(6)SOC******************************************************/
  4423. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4424. {
  4425. //idx_sample=5;
  4426. //sampledValue = NULL;
  4427. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4428. {
  4429. tempIndex = ((gun_index==2) ? 1: 0);
  4430. }
  4431. else
  4432. {
  4433. tempIndex = gun_index;
  4434. }
  4435. if(gunType[gun_index] == 'J')
  4436. {
  4437. //tempIndex = ((gun_index==2) ? 1: 0);
  4438. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4439. {
  4440. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4441. {
  4442. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4443. }
  4444. }
  4445. }
  4446. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4447. {
  4448. //tempIndex = ((gun_index==2) ? 1: 0);
  4449. for (int index = 0; index < CCS_QUANTITY; index++)
  4450. {
  4451. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4452. {
  4453. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4454. }
  4455. }
  4456. }
  4457. else if(gunType[gun_index] == 'G')
  4458. {
  4459. //tempIndex = ((gun_index==2) ? 1: 0);
  4460. for (int index = 0; index < GB_QUANTITY; index++)
  4461. {
  4462. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4463. {
  4464. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4465. }
  4466. }
  4467. }
  4468. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4469. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4470. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4471. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4472. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_Outlet]);
  4473. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4474. }
  4475. //********************************(7)Current.Import L2************************************************/
  4476. // Only for AC 3 phase
  4477. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4478. {
  4479. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4480. {
  4481. tempIndex = 2;
  4482. }
  4483. else
  4484. {
  4485. tempIndex = gun_index;
  4486. }
  4487. for (int index = 0; index < AC_QUANTITY; index++)
  4488. {
  4489. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4490. {
  4491. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  4492. }
  4493. }
  4494. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  4495. }
  4496. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  4497. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  4498. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  4499. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  4500. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4501. //********************************(8)Current.Import L3************************************************/
  4502. // Only for AC 3 phase
  4503. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4504. {
  4505. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4506. {
  4507. tempIndex = 2;
  4508. }
  4509. else
  4510. {
  4511. tempIndex = gun_index;
  4512. }
  4513. for (int index = 0; index < AC_QUANTITY; index++)
  4514. {
  4515. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4516. {
  4517. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  4518. }
  4519. }
  4520. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  4521. }
  4522. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  4523. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  4524. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  4525. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  4526. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4527. //***********************************************(9)VOLTAGE L2******************************************************/
  4528. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4529. {
  4530. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4531. {
  4532. tempIndex = 2;
  4533. }
  4534. else
  4535. {
  4536. tempIndex = gun_index;
  4537. }
  4538. for (int index = 0; index < AC_QUANTITY; index++)
  4539. {
  4540. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4541. {
  4542. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  4543. }
  4544. }
  4545. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  4546. }
  4547. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  4548. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  4549. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  4550. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  4551. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4552. //***********************************************(10)VOLTAGE L3******************************************************/
  4553. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4554. {
  4555. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4556. {
  4557. tempIndex = 2;
  4558. }
  4559. else
  4560. {
  4561. tempIndex = gun_index;
  4562. }
  4563. for (int index = 0; index < AC_QUANTITY; index++)
  4564. {
  4565. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4566. {
  4567. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  4568. }
  4569. }
  4570. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  4571. }
  4572. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  4573. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  4574. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  4575. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  4576. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4577. // Message create ====================================================================================================
  4578. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4579. {
  4580. 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\"}]}]}]"
  4581. ,gun_index + 1
  4582. ,MESSAGE_TYPE_CALL
  4583. ,guid
  4584. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4585. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4586. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4587. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4588. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4589. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4590. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4591. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4592. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4593. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4594. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4595. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4596. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4597. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4598. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4599. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4600. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4601. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4602. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4603. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4604. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4605. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4606. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4607. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4608. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4609. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4610. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4611. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4612. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4613. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4614. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4615. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4616. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4617. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4618. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4619. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4620. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4621. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4622. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value
  4623. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context
  4624. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format
  4625. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand
  4626. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase
  4627. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location
  4628. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit
  4629. );
  4630. }
  4631. else
  4632. {
  4633. if((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W'))
  4634. {
  4635. 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\"}]}]}]"
  4636. ,gun_index + 1
  4637. ,MESSAGE_TYPE_CALL
  4638. ,guid
  4639. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4640. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4641. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4642. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4643. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4644. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4645. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4646. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4647. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4648. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4649. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4650. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4651. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4652. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4653. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4654. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4655. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4656. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4657. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4658. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4659. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4660. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4661. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4662. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4663. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4664. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4665. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4666. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4667. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4668. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4669. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4670. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4671. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4672. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4673. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4674. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4675. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4676. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4677. );
  4678. }
  4679. else
  4680. {
  4681. 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\"}]}]}]"
  4682. ,gun_index + 1
  4683. ,MESSAGE_TYPE_CALL
  4684. ,guid
  4685. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4686. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4687. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4688. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4689. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4690. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4691. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4692. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4693. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4694. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4695. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4696. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4697. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4698. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4699. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4700. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4701. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4702. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4703. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4704. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4705. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4706. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4707. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4708. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4709. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4710. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4711. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4712. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4713. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4714. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4715. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4716. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4717. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4718. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4719. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4720. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4721. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4722. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4723. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value
  4724. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context
  4725. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format
  4726. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand
  4727. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase
  4728. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location
  4729. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit
  4730. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value
  4731. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context
  4732. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format
  4733. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand
  4734. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase
  4735. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location
  4736. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit
  4737. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value
  4738. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context
  4739. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format
  4740. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand
  4741. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase
  4742. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location
  4743. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit
  4744. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value
  4745. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context
  4746. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format
  4747. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand
  4748. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase
  4749. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location
  4750. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit
  4751. );
  4752. }
  4753. }
  4754. // Put request guid to hash map
  4755. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4756. 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*/)
  4757. {
  4758. result = PASS;
  4759. DEBUG_INFO("MeterValues mapitem pass\n");
  4760. }
  4761. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4762. /*
  4763. if(GetTransactionQueueNum() == 1)
  4764. {
  4765. LWS_Send(queuedata +2);
  4766. }*/
  4767. return result;
  4768. }
  4769. //==========================================
  4770. // send confirm routine
  4771. //==========================================
  4772. int sendCancelReservationConfirmation(char *uuid,char *payload)
  4773. {
  4774. mtrace();
  4775. int result = FAIL;
  4776. char message[100]={0};
  4777. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  4778. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4779. LWS_Send(message);
  4780. result = TRUE;
  4781. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  4782. return result;
  4783. }
  4784. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  4785. {
  4786. mtrace();
  4787. int result = FAIL;
  4788. char message[100]={0};
  4789. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  4790. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4791. LWS_Send(message);
  4792. result = TRUE;
  4793. return result;
  4794. }
  4795. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  4796. {
  4797. mtrace();
  4798. int result = FAIL;
  4799. char message[100]={0};
  4800. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  4801. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4802. LWS_Send(message);
  4803. result = TRUE;
  4804. return result;
  4805. }
  4806. int sendClearCacheConfirmation(char *uuid,char *payload)
  4807. {
  4808. mtrace();
  4809. int result = FAIL;
  4810. char message[500]={0};
  4811. DEBUG_INFO("sendClearCacheConfirmation...\n");
  4812. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4813. LWS_Send(message);
  4814. return result;
  4815. }
  4816. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  4817. {
  4818. mtrace();
  4819. int result = FAIL;
  4820. char message[500]={0};
  4821. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  4822. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4823. LWS_Send(message);
  4824. return result;
  4825. }
  4826. int sendDataTransferConfirmation(char *uuid,char *payload)
  4827. {
  4828. mtrace();
  4829. char statusStr[20]={0};
  4830. char dataStr[10]={0};
  4831. char sstr[20]={0};
  4832. int c = 0;
  4833. char *loc;
  4834. int result = FAIL;
  4835. DEBUG_INFO("sendDataTransferConfirmation...\n");
  4836. /**********************status**************************/
  4837. loc = strstr(payload, "status");
  4838. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4839. c = 0;
  4840. while (loc[3+strlen("status")+c] != '\"')
  4841. {
  4842. sstr[c] = loc[3+strlen("status")+c];
  4843. c++;
  4844. }
  4845. sstr[c] = '\0';
  4846. strcpy(statusStr, sstr);
  4847. /**********************data**************************/
  4848. loc = strstr(payload, "data");
  4849. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4850. c = 0;
  4851. while (loc[3+strlen("data")+c] != '\"')
  4852. {
  4853. sstr[c] = loc[3+strlen("data")+c];
  4854. c++;
  4855. }
  4856. sstr[c] = '\0';
  4857. strcpy(dataStr, sstr);
  4858. return result;
  4859. }
  4860. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  4861. {
  4862. mtrace();
  4863. int result = FAIL;
  4864. char message[1000]={0};
  4865. int CompositeScheduleIndex = 0;
  4866. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  4867. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  4868. if(nPeriod == 0)
  4869. {
  4870. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  4871. {
  4872. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  4873. ,MESSAGE_TYPE_CALLRESULT
  4874. ,uuid
  4875. ,payload
  4876. ,connectorIdInt);
  4877. }
  4878. else
  4879. {
  4880. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  4881. ,MESSAGE_TYPE_CALLRESULT
  4882. ,uuid
  4883. ,payload
  4884. ,connectorIdInt
  4885. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4886. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4887. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4888. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  4889. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  4890. }
  4891. }
  4892. else
  4893. {
  4894. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  4895. ,MESSAGE_TYPE_CALLRESULT
  4896. ,uuid
  4897. ,payload
  4898. ,connectorIdInt
  4899. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4900. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4901. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4902. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  4903. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  4904. {
  4905. if (idx_sample == 0)
  4906. {
  4907. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4908. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4909. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4910. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4911. }
  4912. else
  4913. {
  4914. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4915. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4916. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4917. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4918. }
  4919. }
  4920. sprintf(message + strlen(message), "]}}]");
  4921. }
  4922. LWS_Send(message);
  4923. result = TRUE;
  4924. return result;
  4925. }
  4926. int sendGetConfigurationConfirmation(char *uuid)
  4927. {
  4928. mtrace();
  4929. int result = FAIL;
  4930. int MaxKeySupported = 0;
  4931. int sentConfigurationNumber= 0;
  4932. int sentunConfigurationNumber= 0;
  4933. char message[4000]={0};
  4934. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  4935. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  4936. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  4937. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  4938. ,MESSAGE_TYPE_CALLRESULT
  4939. ,uuid );
  4940. //configuration key
  4941. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  4942. {
  4943. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  4944. {
  4945. if (sentConfigurationNumber == 0)
  4946. {
  4947. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  4948. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  4949. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  4950. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  4951. }
  4952. else
  4953. {
  4954. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  4955. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  4956. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  4957. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  4958. }
  4959. sentConfigurationNumber = sentConfigurationNumber + 1;
  4960. }
  4961. }
  4962. sprintf(message + strlen(message), "]");
  4963. if(UnknownKeynum != 0)
  4964. {
  4965. sprintf(message + strlen(message), ",\"unknownKey\":[");
  4966. //unkown key
  4967. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  4968. {
  4969. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  4970. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  4971. if(sentunConfigurationNumber == 0)
  4972. {
  4973. sprintf(message + strlen(message), "\"%s\""
  4974. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  4975. }
  4976. else
  4977. {
  4978. sprintf(message + strlen(message), ",\"%s\""
  4979. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  4980. }
  4981. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  4982. }
  4983. sprintf(message + strlen(message), "]");
  4984. }
  4985. sprintf(message + strlen(message), "}]");
  4986. LWS_Send(message);
  4987. return result;
  4988. }
  4989. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  4990. {
  4991. mtrace();
  4992. int result = FAIL;
  4993. char message[400]={0};
  4994. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  4995. if(strcmp(payload,"")==0)
  4996. {
  4997. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  4998. }
  4999. else
  5000. {
  5001. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5002. }
  5003. LWS_Send(message);
  5004. result = TRUE;
  5005. return result;
  5006. }
  5007. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5008. {
  5009. mtrace();
  5010. int result = FAIL;
  5011. char message[80]={0};
  5012. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5013. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5014. LWS_Send(message);
  5015. result = TRUE;
  5016. return result;
  5017. }
  5018. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5019. {
  5020. mtrace();
  5021. int result = FAIL;
  5022. char message[80]={0};
  5023. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5024. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5025. LWS_Send(message);
  5026. result = TRUE;
  5027. return result;
  5028. }
  5029. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5030. {
  5031. mtrace();
  5032. int result = FAIL;
  5033. char message[80]={0};
  5034. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5035. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5036. LWS_Send(message);
  5037. result = TRUE;
  5038. return result;
  5039. }
  5040. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5041. {
  5042. mtrace();
  5043. int result = FAIL;
  5044. char message[80]={0};
  5045. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5046. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5047. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5048. LWS_Send(message);
  5049. result = TRUE;
  5050. return result;
  5051. }
  5052. int sendResetConfirmation(char *uuid,char *payload)
  5053. {
  5054. mtrace();
  5055. int result = FAIL;
  5056. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5057. char message[80]={0};
  5058. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5059. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5060. LWS_Send(message);
  5061. result = TRUE;
  5062. return result;
  5063. }
  5064. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5065. {
  5066. mtrace();
  5067. int result = FAIL;
  5068. char message[500]={0};
  5069. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5070. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5071. LWS_Send(message);
  5072. result = TRUE;
  5073. return result;
  5074. }
  5075. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5076. {
  5077. mtrace();
  5078. int result = FAIL;
  5079. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5080. char message[80]={0};
  5081. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5082. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5083. LWS_Send(message);
  5084. result = TRUE;
  5085. return result;
  5086. }
  5087. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5088. {
  5089. mtrace();
  5090. int result = FAIL;
  5091. char message[80]={0};
  5092. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5093. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5094. LWS_Send(message);
  5095. result = TRUE;
  5096. return result;
  5097. }
  5098. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5099. {
  5100. mtrace();
  5101. int result = FAIL;
  5102. char message[80]={0};
  5103. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5104. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5105. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5106. LWS_Send(message);
  5107. result = TRUE;
  5108. return result;
  5109. }
  5110. int sendUpdateFirmwareConfirmation(char *uuid)
  5111. {
  5112. mtrace();
  5113. int result = FAIL;
  5114. char message[60]={0};
  5115. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5116. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5117. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5118. LWS_Send(message);
  5119. result = TRUE;
  5120. return result;
  5121. }
  5122. //==========================================
  5123. // send CallError routine
  5124. //==========================================
  5125. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5126. {
  5127. mtrace();
  5128. char message[220]={0};
  5129. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5130. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5131. LWS_Send(message);
  5132. }
  5133. //==========================================
  5134. // Handle server request routine Start
  5135. //==========================================
  5136. int handleCancelReservationRequest(char *uuid, char *payload)
  5137. {
  5138. mtrace();
  5139. int result = FAIL;
  5140. int gunNO = 0;
  5141. int reservationIdInt =0;
  5142. char comfirmstr[20];
  5143. DEBUG_INFO("handleCancelReservationRequest...\n");
  5144. json_object *CancelReservation;
  5145. CancelReservation = json_tokener_parse(payload);
  5146. if(!is_error(CancelReservation))
  5147. {
  5148. // Required data
  5149. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5150. }
  5151. json_object_put(CancelReservation);
  5152. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5153. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5154. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5155. //check Transaction active
  5156. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5157. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5158. {
  5159. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5160. {
  5161. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5162. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5163. if(gunType[2] == 'J')
  5164. {
  5165. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5166. }
  5167. else
  5168. {
  5169. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5170. }
  5171. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5172. goto end;
  5173. }
  5174. }
  5175. for (int index = 0; index < CCS_QUANTITY; index++)
  5176. {
  5177. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5178. {
  5179. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5180. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5181. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5182. {
  5183. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5184. }
  5185. else
  5186. {
  5187. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5188. }
  5189. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5190. goto end;
  5191. }
  5192. }
  5193. for (int index = 0; index < GB_QUANTITY; index++)
  5194. {
  5195. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5196. {
  5197. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5198. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5199. if(gunType[2] == 'G')
  5200. {
  5201. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5202. }
  5203. else
  5204. {
  5205. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5206. }
  5207. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5208. goto end;
  5209. }
  5210. }
  5211. for (int index = 0; index < AC_QUANTITY; index++)
  5212. {
  5213. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5214. {
  5215. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5216. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5217. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5218. {
  5219. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5220. }
  5221. else
  5222. {
  5223. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5224. }
  5225. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5226. goto end;
  5227. }
  5228. }
  5229. //The reservationId does NOT match the reservationId
  5230. sendCancelReservationConfirmation(uuid, comfirmstr);
  5231. end:
  5232. // Fill in ocpp packet uuid
  5233. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5234. return result;
  5235. }
  5236. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5237. {
  5238. mtrace();
  5239. int result = FAIL;
  5240. int gunIndex = 0;
  5241. char typeStr[16]={0};
  5242. char comfirmstr[20];
  5243. int specificId = FALSE;
  5244. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5245. json_object *ChangeAvailability;
  5246. ChangeAvailability = json_tokener_parse(payload);
  5247. if(!is_error(ChangeAvailability))
  5248. {
  5249. // Required data
  5250. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5251. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5252. }
  5253. json_object_put(ChangeAvailability);
  5254. if(gunIndex != 0)
  5255. {
  5256. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5257. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5258. }
  5259. else
  5260. {
  5261. for(int i=0; i < gunTotalNumber; i++)
  5262. {
  5263. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5264. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5265. }
  5266. }
  5267. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5268. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5269. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  5270. {
  5271. specificId = TRUE;
  5272. }
  5273. if(specificId == FALSE)
  5274. goto end;
  5275. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5276. {
  5277. //----------------------gunIndex is 0 ------------------------------------------------//
  5278. if(gunIndex == 0)
  5279. {
  5280. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5281. {
  5282. for(int i=0; i < gunTotalNumber; i++)
  5283. {
  5284. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5285. {
  5286. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5287. {
  5288. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5289. {
  5290. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5291. goto end;
  5292. }
  5293. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5294. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5295. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5296. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5297. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5298. {
  5299. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5300. goto end;
  5301. }
  5302. }
  5303. }//END FOR CHAdeMO_QUANTITY
  5304. for (int index = 0; index < CCS_QUANTITY; index++)
  5305. {
  5306. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5307. {
  5308. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5309. {
  5310. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5311. goto end;
  5312. }
  5313. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5314. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5315. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5316. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5317. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5318. {
  5319. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5320. goto end;
  5321. }
  5322. }
  5323. }//END FOR CCS_QUANTITY
  5324. for (int index = 0; index < GB_QUANTITY; index++)
  5325. {
  5326. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5327. {
  5328. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5329. {
  5330. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5331. goto end;
  5332. }
  5333. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5334. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5335. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5336. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5337. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5338. {
  5339. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5340. goto end;
  5341. }
  5342. }
  5343. }// END FOR GB_QUANTITY
  5344. for (int index = 0; index < AC_QUANTITY; index++)
  5345. {
  5346. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5347. {
  5348. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5349. {
  5350. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5351. goto end;
  5352. }
  5353. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5354. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5355. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5356. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5357. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5358. {
  5359. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5360. goto end;
  5361. }
  5362. }
  5363. }//END FOR AC_QUANTITY
  5364. }// END FOR gunTotalNumber
  5365. }
  5366. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5367. {
  5368. for(int i=0; i < gunTotalNumber; i++)
  5369. {
  5370. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5371. {
  5372. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5373. goto end;
  5374. }
  5375. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5376. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5377. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5378. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5379. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5380. {
  5381. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5382. goto end;
  5383. }
  5384. }
  5385. }
  5386. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5387. goto end;
  5388. }
  5389. //----------------------gunIndex is not 0 ------------------------------------------------//
  5390. //check Transaction active
  5391. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5392. {
  5393. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5394. {
  5395. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5396. {
  5397. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5398. goto end;
  5399. }
  5400. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5401. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5402. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5403. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5404. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5405. {
  5406. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5407. goto end;
  5408. }
  5409. else
  5410. {
  5411. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5412. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5413. goto end;
  5414. }
  5415. }
  5416. }//END FOR CHAdeMO_QUANTITY
  5417. for (int index = 0; index < CCS_QUANTITY; index++)
  5418. {
  5419. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5420. {
  5421. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5422. {
  5423. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5424. goto end;
  5425. }
  5426. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5427. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5428. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5429. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5430. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5431. {
  5432. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5433. goto end;
  5434. }
  5435. else
  5436. {
  5437. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5438. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5439. goto end;
  5440. }
  5441. }
  5442. }//END FOR CCS_QUANTITY
  5443. for (int index = 0; index < GB_QUANTITY; index++)
  5444. {
  5445. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5446. {
  5447. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5448. {
  5449. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5450. goto end;
  5451. }
  5452. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5453. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5454. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5455. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5456. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5457. {
  5458. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5459. goto end;
  5460. }
  5461. else
  5462. {
  5463. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5464. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5465. goto end;
  5466. }
  5467. }
  5468. }// END FOR GB_QUANTITY
  5469. for (int index = 0; index < AC_QUANTITY; index++)
  5470. {
  5471. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5472. {
  5473. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5474. {
  5475. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5476. goto end;
  5477. }
  5478. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5479. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5480. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5481. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5482. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5483. {
  5484. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5485. goto end;
  5486. }
  5487. else
  5488. {
  5489. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5490. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5491. goto end;
  5492. }
  5493. }
  5494. }//END FOR AC_QUANTITY
  5495. }//END FOR AvailabilityTypeStr[Inoperative]
  5496. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5497. {
  5498. //----------------------gunIndex is 0 ------------------------------------------------//
  5499. if(gunIndex == 0)
  5500. {
  5501. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5502. {
  5503. for(int i=0; i < gunTotalNumber; i++)
  5504. {
  5505. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5506. {
  5507. 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
  5508. {
  5509. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5510. goto end;
  5511. }
  5512. }//END FOR CHAdeMO_QUANTITY
  5513. for (int index = 0; index < CCS_QUANTITY; index++)
  5514. {
  5515. 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
  5516. {
  5517. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5518. goto end;
  5519. }
  5520. }//END FOR CCS_QUANTITY
  5521. for (int index = 0; index < GB_QUANTITY; index++)
  5522. {
  5523. 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
  5524. {
  5525. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5526. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5527. goto end;
  5528. }
  5529. }// END FOR GB_QUANTITY
  5530. for (int index = 0; index < AC_QUANTITY; index++)
  5531. {
  5532. 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
  5533. {
  5534. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5535. goto end;
  5536. }
  5537. }//END FOR CHAdeMO_QUANTITY
  5538. }// END FOR gunTotalNumber
  5539. }
  5540. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5541. {
  5542. for(int i=0; i < gunTotalNumber; i++)
  5543. {
  5544. for (int index = 0; index < AC_QUANTITY; index++)
  5545. {
  5546. 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
  5547. {
  5548. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5549. goto end;
  5550. }
  5551. }//END FOR CHAdeMO_QUANTITY
  5552. } // END FOR gunTotalNumber
  5553. }
  5554. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5555. goto end;
  5556. }
  5557. //----------------------gunIndex is not 0 ------------------------------------------------//
  5558. //check Transaction active
  5559. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5560. {
  5561. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5562. {
  5563. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5564. goto end;
  5565. }
  5566. }//END FOR CHAdeMO_QUANTITY
  5567. for (int index = 0; index < CCS_QUANTITY; index++)
  5568. {
  5569. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5570. {
  5571. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5572. goto end;
  5573. }
  5574. }//END FOR CCS_QUANTITY
  5575. for (int index = 0; index < GB_QUANTITY; index++)
  5576. {
  5577. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5578. {
  5579. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5580. goto end;
  5581. }
  5582. }// END FOR GB_QUANTITY
  5583. for (int index = 0; index < AC_QUANTITY; index++)
  5584. {
  5585. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5586. {
  5587. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5588. goto end;
  5589. }
  5590. }//END FOR AC_QUANTITY
  5591. }//END FOR AvailabilityTypeStr[Operative]
  5592. end:
  5593. if(gunIndex != 0)
  5594. {
  5595. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5596. }
  5597. else
  5598. {
  5599. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5600. }
  5601. if(gunIndex != 0)
  5602. {
  5603. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5604. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5605. }
  5606. else
  5607. {
  5608. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5609. {
  5610. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5611. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5612. }
  5613. }
  5614. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5615. return result;
  5616. }
  5617. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5618. {
  5619. mtrace();
  5620. int result = FAIL;
  5621. char keystr[40]={0};
  5622. char valuestr[100]={0};
  5623. char comfirmstr[20]={0};
  5624. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5625. json_object *ChangeConfiguration;
  5626. ChangeConfiguration = json_tokener_parse(payload);
  5627. if(!is_error(ChangeConfiguration))
  5628. {
  5629. // Required data
  5630. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5631. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5632. }
  5633. json_object_put(ChangeConfiguration);
  5634. if((uuid==NULL) || (payload ==NULL) )
  5635. {
  5636. DEBUG_ERROR("Payload is null\n");
  5637. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5638. }
  5639. else
  5640. {
  5641. int status = setKeyValue(keystr, valuestr);
  5642. switch(status)
  5643. {
  5644. case ConfigurationStatus_Accepted:
  5645. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5646. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5647. StoreConfigurationTable();
  5648. break;
  5649. case ConfigurationStatus_Rejected:
  5650. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5651. break;
  5652. case RebootRequired:
  5653. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5654. StoreConfigurationTable();
  5655. break;
  5656. case NotSupported:
  5657. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5658. break;
  5659. default:
  5660. break;
  5661. }
  5662. }
  5663. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5664. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5665. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5666. {
  5667. ChageWebSocketPingInterval(atoi(valuestr));
  5668. }
  5669. return result;
  5670. }
  5671. int handleClearCacheRequest(char *uuid, char *payload)
  5672. {
  5673. mtrace();
  5674. int result = FAIL;
  5675. char comfirmstr[20];
  5676. int fd;
  5677. char rmFileCmd[100]={0};
  5678. struct stat stats;
  5679. DEBUG_INFO("handleClearCacheRequest...\n");
  5680. stat("/Storage/OCPP", &stats);
  5681. // Check for directory existence
  5682. if (S_ISDIR(stats.st_mode) == 1)
  5683. {}
  5684. else
  5685. {
  5686. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  5687. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  5688. system(rmFileCmd);
  5689. }
  5690. memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
  5691. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  5692. {
  5693. DEBUG_INFO("AuthorizationCache file exist.\n");
  5694. }
  5695. else
  5696. {
  5697. DEBUG_INFO("AuthorizationCache file not exist\n");
  5698. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  5699. if(log == NULL)
  5700. {
  5701. DEBUG_INFO("AuthorizationCache file is NULL\n");
  5702. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5703. goto end;
  5704. }
  5705. else
  5706. {
  5707. fclose(log);
  5708. }
  5709. }
  5710. if((fd = open(AuthorizationCache_JSON,O_RDWR)) < 0)
  5711. {
  5712. DEBUG_INFO("open AuthorizationCache file failed\n");
  5713. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5714. }
  5715. else
  5716. {
  5717. DEBUG_INFO("open AuthorizationCache file successful\n");
  5718. ftruncate(fd,0);
  5719. lseek(fd,0,SEEK_SET);
  5720. close(fd);
  5721. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  5722. }
  5723. end:
  5724. sendClearCacheConfirmation(uuid, comfirmstr);
  5725. return result;
  5726. }
  5727. int handleClearChargingProfileRequest(char *uuid, char *payload)
  5728. {
  5729. mtrace();
  5730. int result = FAIL;
  5731. int resultRename;
  5732. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  5733. char chargingProfilePurposeStr[26]={0};
  5734. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  5735. char tempchargingProfilePurposeStr[26]={0};
  5736. char sstr[160]={0};
  5737. char str[100]={0};
  5738. int c = 0;
  5739. char *loc;
  5740. char fname[200]={0};
  5741. char comfirmstr[20]={0};
  5742. char word[1600]={0};
  5743. int clearflag = FALSE;
  5744. int chargingProfileIdIsNULL = FALSE;
  5745. int connectorIsNULL = FALSE;
  5746. int chargingProfilePurposeIsNULL = FALSE;
  5747. int stackLevelIsNULL = FALSE;
  5748. //int GotoEnd = FALSE;
  5749. FILE *fptr1, *fptr2;
  5750. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  5751. int n_chargingProfile=0;
  5752. int isEmptyFile = FALSE;
  5753. char sLineWord[1600]={0};
  5754. char chargingProfiles[10][100]={0};
  5755. int ChargeProfileCount = 0;
  5756. char ch;
  5757. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  5758. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  5759. json_object *ClearChargingProfile;
  5760. ClearChargingProfile = json_tokener_parse(payload);
  5761. if(!is_error(ClearChargingProfile))
  5762. {
  5763. // Optional data
  5764. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  5765. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  5766. else
  5767. chargingProfileIdIsNULL = TRUE;
  5768. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  5769. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  5770. else
  5771. connectorIsNULL = TRUE;
  5772. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  5773. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  5774. else
  5775. chargingProfilePurposeIsNULL = TRUE;
  5776. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  5777. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  5778. else
  5779. stackLevelIsNULL = TRUE;
  5780. }
  5781. json_object_put(ClearChargingProfile);
  5782. if(connectorIsNULL == FALSE)
  5783. {
  5784. switch(connectorIdInt)
  5785. {
  5786. case 0:
  5787. if(chargingProfilePurposeIsNULL == TRUE)
  5788. {
  5789. int l = 0;
  5790. strcpy(fname, ChargePointMaxProfile_JSON);
  5791. if((access(fname,F_OK))!=-1)
  5792. {
  5793. strcpy(chargingProfiles[l], fname);
  5794. l = l + 1;
  5795. }
  5796. strcpy(fname, TxDefaultProfile_0_JSON);
  5797. if((access(fname,F_OK))!=-1)
  5798. {
  5799. strcpy(chargingProfiles[l], fname);
  5800. l = l + 1;
  5801. }
  5802. ChargeProfileCount = l;
  5803. }
  5804. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  5805. {
  5806. strcpy(fname, ChargePointMaxProfile_JSON);
  5807. if((access(fname,F_OK))!=-1)
  5808. {
  5809. strcpy(chargingProfiles[0], fname);
  5810. ChargeProfileCount = 1;
  5811. }
  5812. }
  5813. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5814. {
  5815. strcpy(fname, TxDefaultProfile_0_JSON);
  5816. if((access(fname,F_OK))!=-1)
  5817. {
  5818. strcpy(chargingProfiles[0], fname);
  5819. ChargeProfileCount = 1;
  5820. }
  5821. }
  5822. break;
  5823. default:
  5824. if(chargingProfilePurposeIsNULL == TRUE)
  5825. {
  5826. int m = 0;
  5827. memset(fname, 0, ARRAY_SIZE(fname));
  5828. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5829. if((access(fname,F_OK))!=-1)
  5830. {
  5831. strcpy(chargingProfiles[m], fname);
  5832. m = m + 1;
  5833. }
  5834. memset(fname, 0, ARRAY_SIZE(fname));
  5835. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5836. if((access(fname,F_OK))!=-1)
  5837. {
  5838. strcpy(chargingProfiles[m], fname);
  5839. m = m + 1;
  5840. }
  5841. ChargeProfileCount = m;
  5842. }
  5843. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5844. {
  5845. //strcpy(fname, TxDefaultProfile_1_JSON);
  5846. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5847. if((access(fname,F_OK))!=-1)
  5848. {
  5849. strcpy(chargingProfiles[0], fname);
  5850. ChargeProfileCount = 1;
  5851. }
  5852. }
  5853. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  5854. {
  5855. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5856. if((access(fname,F_OK))!=-1)
  5857. {
  5858. strcpy(chargingProfiles[0], fname);
  5859. ChargeProfileCount = 1;
  5860. }
  5861. //strcpy(fname, TxProfile_1_JSON);
  5862. }
  5863. //strcpy(fname, ChargePointMaxProfile_JSON );
  5864. break;
  5865. }
  5866. }
  5867. else // Check all Charging Profiles
  5868. {
  5869. int i = 0;
  5870. char fnametemp[200]={0};
  5871. ChargeProfileCount = 0;
  5872. //Check ChargePointMaxProfile.json exit
  5873. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  5874. {
  5875. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  5876. i = i + 1;
  5877. }
  5878. //Check TxDefaultProfile_0.json exit
  5879. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  5880. {
  5881. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  5882. i = i + 1;
  5883. }
  5884. //Check TxDefaultProfile_%d.json
  5885. for(int j=1; j <= gunTotalNumber; j++)
  5886. {
  5887. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5888. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  5889. if((access(fnametemp,F_OK))!=-1)
  5890. {
  5891. strcpy(chargingProfiles[i], fnametemp);
  5892. i = i + 1;
  5893. }
  5894. }
  5895. //Check TxProfile_%d.json
  5896. for(int j=1; j <= gunTotalNumber; j++)
  5897. {
  5898. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5899. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  5900. if((access(fnametemp,F_OK))!=-1)
  5901. {
  5902. strcpy(chargingProfiles[i], fnametemp);
  5903. i = i + 1;
  5904. }
  5905. }
  5906. ChargeProfileCount = i;
  5907. }// End connectorIsNULL is TRUE
  5908. if(ChargeProfileCount == 0)
  5909. {
  5910. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5911. goto end;
  5912. }
  5913. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  5914. {
  5915. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5916. goto end;
  5917. }
  5918. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  5919. {
  5920. memset(str, 0, ARRAY_SIZE(str));
  5921. // clear temp file
  5922. sprintf(str,"rm -f %s",temp);
  5923. system(str);
  5924. for(int k=0; k < ChargeProfileCount; k++)
  5925. {
  5926. memset(str, 0, ARRAY_SIZE(str));
  5927. //clear file in C
  5928. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5929. system(str);
  5930. }
  5931. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5932. goto end;
  5933. }
  5934. else if(connectorIsNULL == TRUE)
  5935. {
  5936. for(int k=0; k < ChargeProfileCount; k++)
  5937. {
  5938. fptr1 = fopen(chargingProfiles[k], "r");
  5939. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  5940. //Check Charging Profile Count
  5941. while(fscanf(fptr1, "%s", word) != EOF)
  5942. {
  5943. //DEBUG_INFO("word=%s\n",word);
  5944. if(strstr(word, "chargingProfileId")!= NULL)
  5945. {
  5946. //DEBUG_INFO("test chargingProfileId \n");
  5947. n_chargingProfile = n_chargingProfile + 1;
  5948. //DEBUG_INFO("chargingProfileId Found\n");
  5949. }
  5950. }
  5951. rewind(fptr1);
  5952. //search Charging Profile Element
  5953. //int i= 0;
  5954. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  5955. {
  5956. //------------------------tempconnectorIdInt------------------------//
  5957. loc = strstr(sLineWord, "connectorId");
  5958. c = 0;
  5959. memset(sstr ,0, sizeof(sstr) );
  5960. while (loc[strlen("connectorId")+2+c] != ',')
  5961. {
  5962. sstr[c] = loc[strlen("connectorId")+2+c];
  5963. c++;
  5964. }
  5965. sstr[c] = '\0';
  5966. tempconnectorIdInt = atoi(sstr);
  5967. printf("file's gun number is %d\n", tempconnectorIdInt);
  5968. //--------------------------chargingProfileId--------------------//
  5969. c = 0;
  5970. loc = strstr(sLineWord, "chargingProfileId");
  5971. memset(sstr ,0, ARRAY_SIZE(sstr));
  5972. while (loc[strlen("chargingProfileId")+2+c] != ',')
  5973. {
  5974. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5975. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5976. c++;
  5977. }
  5978. sstr[c] = '\0';
  5979. tempchargingProfileIdInt = atoi(sstr);
  5980. //stackLevel
  5981. c = 0;
  5982. loc = strstr(sLineWord, "stackLevel");
  5983. memset(sstr ,0, ARRAY_SIZE(sstr));
  5984. while (loc[strlen("stackLevel")+2+c] != ',')
  5985. {
  5986. sstr[c] = loc[strlen("stackLevel")+2+c];
  5987. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5988. c++;
  5989. }
  5990. sstr[c] = '\0';
  5991. tempstackLevelInt = atoi(sstr);
  5992. c = 0;
  5993. loc = strstr(sLineWord, "chargingProfilePurpose");
  5994. memset(sstr ,0, ARRAY_SIZE(sstr));
  5995. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5996. {
  5997. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5998. c++;
  5999. }
  6000. sstr[c] = '\0';
  6001. strcpy(tempchargingProfilePurposeStr, sstr);
  6002. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6003. {
  6004. //------- not write to fptr2-------//
  6005. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6006. //clearflag = TRUE;
  6007. }
  6008. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6009. {
  6010. //------- not write to fptr2-------//
  6011. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6012. }
  6013. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6014. {
  6015. //------- not write to fptr2-------//
  6016. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6017. }
  6018. else
  6019. {
  6020. fprintf(fptr2, sLineWord);//writing data into file
  6021. }
  6022. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6023. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6024. if(clearflag == TRUE)
  6025. {
  6026. fclose(fptr1);
  6027. fclose(fptr2);
  6028. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6029. system(str);
  6030. // clear temp file
  6031. sprintf(str,"rm -f %s",temp);
  6032. system(str);
  6033. }
  6034. else
  6035. {
  6036. fclose(fptr1);
  6037. fclose(fptr2);
  6038. memset(str, 0, ARRAY_SIZE(str));
  6039. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6040. system(str);
  6041. resultRename = rename(temp, chargingProfiles[k]);
  6042. if(resultRename == 0)
  6043. {
  6044. DEBUG_INFO("File ChargingProfile renamed successfully");
  6045. }
  6046. else
  6047. {
  6048. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6049. }
  6050. if(comfirmstr[0]== 0)
  6051. {
  6052. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6053. }
  6054. //Check chargingProfile is empty file
  6055. /*------ Read the file ----------------*/
  6056. fptr1=fopen(chargingProfiles[k],"r");
  6057. ch=fgetc(fptr1);
  6058. rewind(fptr1);
  6059. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6060. if(ch!=EOF)
  6061. {
  6062. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6063. {
  6064. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6065. if(sLineWord[0]=='\0')
  6066. {
  6067. isEmptyFile = TRUE;
  6068. break;
  6069. }
  6070. else
  6071. {
  6072. isEmptyFile = FALSE;
  6073. break;
  6074. }
  6075. }
  6076. }
  6077. fclose(fptr1);
  6078. if(isEmptyFile == TRUE)
  6079. {
  6080. memset(str, 0, ARRAY_SIZE(str));
  6081. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6082. system(str);
  6083. }
  6084. }
  6085. }// End of while(int k=0; k < ChargePointCount; k++)
  6086. }
  6087. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6088. {
  6089. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6090. for(int k=0; k < ChargeProfileCount; k++)
  6091. {
  6092. fptr1 = fopen(chargingProfiles[k], "r");
  6093. fptr2 = fopen(temp, "w+");
  6094. //Check Charging Profile Count
  6095. while(fscanf(fptr1, "%s", word) != EOF)
  6096. {
  6097. //DEBUG_INFO("word=%s\n",word);
  6098. if(strstr(word, "chargingProfileId")!= NULL)
  6099. {
  6100. n_chargingProfile = n_chargingProfile + 1;
  6101. }
  6102. }
  6103. rewind(fptr1);
  6104. //search Charging Profile Element
  6105. //int i= 0;
  6106. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6107. {
  6108. //*************************tempconnectorIdInt*********************************/
  6109. loc = strstr(sLineWord, "connectorId");
  6110. c = 0;
  6111. memset(sstr ,0, ARRAY_SIZE(sstr));
  6112. while (loc[strlen("connectorId")+2+c] != ',')
  6113. {
  6114. sstr[c] = loc[strlen("connectorId")+2+c];
  6115. c++;
  6116. }
  6117. sstr[c] = '\0';
  6118. tempconnectorIdInt = atoi(sstr);
  6119. //chargingProfileId
  6120. c = 0;
  6121. loc = strstr(sLineWord, "chargingProfileId");
  6122. memset(sstr ,0, ARRAY_SIZE(sstr));
  6123. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6124. {
  6125. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6126. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6127. c++;
  6128. }
  6129. sstr[c] = '\0';
  6130. tempchargingProfileIdInt = atoi(sstr);
  6131. //stackLevel
  6132. c = 0;
  6133. loc = strstr(sLineWord, "stackLevel");
  6134. memset(sstr ,0, ARRAY_SIZE(sstr));
  6135. while (loc[strlen("stackLevel")+2+c] != ',')
  6136. {
  6137. sstr[c] = loc[strlen("stackLevel")+2+c];
  6138. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6139. c++;
  6140. }
  6141. sstr[c] = '\0';
  6142. tempstackLevelInt = atoi(sstr);
  6143. c = 0;
  6144. loc = strstr(sLineWord, "chargingProfilePurpose");
  6145. memset(sstr ,0, ARRAY_SIZE(sstr));
  6146. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6147. {
  6148. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6149. c++;
  6150. }
  6151. sstr[c] = '\0';
  6152. strcpy(tempchargingProfilePurposeStr, sstr);
  6153. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6154. {
  6155. //------- not write to fptr2-------//
  6156. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6157. //clearflag = TRUE;
  6158. }
  6159. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6160. {
  6161. //------- not write to fptr2-------//
  6162. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6163. }
  6164. else if(stackLevelIsNULL == TRUE)
  6165. {
  6166. //Clear Whole File
  6167. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6168. clearflag = TRUE;
  6169. break;
  6170. }
  6171. else
  6172. {
  6173. fprintf(fptr2, sLineWord);//writing data into file
  6174. }
  6175. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6176. }
  6177. if(clearflag == TRUE)
  6178. {
  6179. fclose(fptr1);
  6180. fclose(fptr2);
  6181. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6182. system(str);
  6183. // clear temp file
  6184. sprintf(str,"rm -f %s",temp);
  6185. system(str);
  6186. }
  6187. else
  6188. {
  6189. fclose(fptr1);
  6190. fclose(fptr2);
  6191. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6192. system(str);
  6193. resultRename = rename(temp, chargingProfiles[k]);
  6194. if(resultRename == 0)
  6195. {
  6196. DEBUG_INFO("File ChargingProfile renamed successfully");
  6197. }
  6198. else
  6199. {
  6200. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6201. }
  6202. if(comfirmstr[0]== 0)
  6203. {
  6204. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6205. }
  6206. //Check chargingProfile is empty file
  6207. /*------ Read the file ----------------*/
  6208. fptr1=fopen(chargingProfiles[k],"r");
  6209. ch=fgetc(fptr1);
  6210. rewind(fptr1);
  6211. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6212. if(ch!=EOF)
  6213. {
  6214. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6215. {
  6216. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6217. if(sLineWord[0]=='\0')
  6218. {
  6219. isEmptyFile = TRUE;
  6220. break;
  6221. }
  6222. else
  6223. {
  6224. isEmptyFile = FALSE;
  6225. break;
  6226. }
  6227. }
  6228. }
  6229. fclose(fptr1);
  6230. if(isEmptyFile == TRUE)
  6231. {
  6232. memset(str, 0, ARRAY_SIZE(str));
  6233. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6234. system(str);
  6235. }
  6236. /*------- End of reading ---------------*/
  6237. }
  6238. } // while(int k=0; k < ChargeProfileCount; k++)
  6239. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6240. end:
  6241. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6242. return result;
  6243. }
  6244. void createFirmwareVersionByDataTransfer(void)
  6245. {
  6246. json_object *FirmwareDataTransfer = json_object_new_object();
  6247. // AC & DC model
  6248. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6249. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6250. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6251. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6252. // DC model
  6253. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6254. {
  6255. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6256. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6257. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6258. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6259. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6260. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6261. }
  6262. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6263. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6264. {
  6265. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6266. }
  6267. // 4G model
  6268. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  6269. {
  6270. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6271. }
  6272. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6273. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6274. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string(FirmwareDataTransfer));
  6275. }
  6276. int handleDataTransferRequest(char *uuid, char *payload)
  6277. {
  6278. mtrace();
  6279. json_object *response = json_object_new_object();
  6280. int result = FAIL;
  6281. char tempvendorId[255]={0};
  6282. char tempmessageId[50]={0};
  6283. char tempdata[512]={0};
  6284. char message[2048]={0};
  6285. DEBUG_INFO("handleDataTransferRequest...\n");
  6286. if((uuid != NULL) && (payload != NULL))
  6287. {
  6288. json_object *DataTransfer;
  6289. DataTransfer = json_tokener_parse(payload);
  6290. if(!is_error(DataTransfer))
  6291. {
  6292. // Required data
  6293. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6294. // Optional data
  6295. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6296. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6297. if(json_object_object_get(DataTransfer, "data") != NULL)
  6298. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6299. result = PASS;
  6300. }
  6301. json_object_put(DataTransfer);
  6302. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6303. {
  6304. // Send all moudle firmware version on EVSE
  6305. system("/usr/bin/run_tmate_restart.sh");
  6306. createFirmwareVersionByDataTransfer();
  6307. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6308. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6309. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6310. }
  6311. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6312. {
  6313. json_object *data;
  6314. data = json_tokener_parse(tempdata);
  6315. if(!is_error(data))
  6316. {
  6317. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6318. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6319. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6320. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6321. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6322. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6323. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6324. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6325. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6326. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6327. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6328. }
  6329. else
  6330. {
  6331. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6332. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6333. }
  6334. json_object_put(data);
  6335. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6336. }
  6337. else
  6338. {
  6339. // Can not find valid message id
  6340. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6341. }
  6342. }
  6343. else
  6344. {
  6345. // Payload is null
  6346. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6347. }
  6348. LWS_Send(message);
  6349. return result;
  6350. }
  6351. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6352. {
  6353. mtrace();
  6354. int result = FAIL;
  6355. int connectorIdInt, durationInt;
  6356. char chargingRateUnitStr[4]={0};
  6357. char comfirmstr[20];
  6358. int confirmPeriods = 0;
  6359. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6360. json_object *GetCompositeSchedule;
  6361. GetCompositeSchedule = json_tokener_parse(payload);
  6362. if(!is_error(GetCompositeSchedule))
  6363. {
  6364. // Required data
  6365. connectorIdInt= json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6366. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6367. // Optional data
  6368. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6369. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6370. }
  6371. json_object_put(GetCompositeSchedule);
  6372. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6373. if((connectorIdInt == 0) ||
  6374. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6375. {
  6376. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6377. struct StructChargingProfile tmpProfile[1];
  6378. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6379. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6380. {
  6381. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6382. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6383. }
  6384. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6385. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6386. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6387. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6388. {
  6389. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6390. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6391. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6392. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6393. {
  6394. confirmPeriods = idx;
  6395. break;
  6396. }
  6397. }
  6398. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6399. }
  6400. else
  6401. {
  6402. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6403. }
  6404. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6405. return result;
  6406. }
  6407. int handleGetConfigurationRequest(char *uuid, char *payload)
  6408. {
  6409. mtrace();
  6410. int result = FAIL;
  6411. int MaxKeySupported = 0;
  6412. int n_keys = 0;
  6413. char requestKey[43][50]={0};
  6414. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6415. json_object *GetConfiguration;
  6416. GetConfiguration = json_tokener_parse(payload);
  6417. if(!is_error(GetConfiguration))
  6418. {
  6419. // Optional data
  6420. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6421. {
  6422. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6423. {
  6424. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6425. n_keys = idx + 1;
  6426. }
  6427. }
  6428. }
  6429. json_object_put(GetConfiguration);
  6430. UnknownKeynum = 0;
  6431. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6432. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6433. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6434. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6435. if(n_keys != 0)
  6436. {
  6437. for(int i=0;i<n_keys;i++)
  6438. {
  6439. getKeyValue(requestKey[i]);
  6440. }
  6441. }
  6442. else
  6443. {
  6444. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6445. getKeyValue("");
  6446. }
  6447. processUnkownKey();
  6448. sendGetConfigurationConfirmation(uuid);
  6449. return result;
  6450. }
  6451. static char fnamePlusPath[100]={0};
  6452. static char fnamePWithNoPath[60]={0};
  6453. void checkUploadLog(void)
  6454. {
  6455. FILE *fp;
  6456. /* Open the command for reading. */
  6457. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6458. if (fp == NULL) {
  6459. printf("Failed to run command\n" );
  6460. exit(1);
  6461. }
  6462. int ftppathlen = 0;
  6463. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6464. int i = 0;
  6465. /* Read the output a line at a time - output it. */
  6466. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6467. if(i==0)
  6468. {
  6469. ftppathlen = strlen(fnamePlusPath);
  6470. printf("%s\n", fnamePlusPath);
  6471. fnamePlusPath[ftppathlen]='\0';
  6472. break;
  6473. }
  6474. i= i+1;
  6475. }
  6476. /* close */
  6477. pclose(fp);
  6478. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6479. {
  6480. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6481. {
  6482. fnamePlusPath[k]='\0';
  6483. }
  6484. }
  6485. i=1;
  6486. //char fname[60]={0};
  6487. while(i < ftppathlen)
  6488. {
  6489. int len=ftppathlen-i;
  6490. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6491. {
  6492. printf("compare '/' all right\n");
  6493. break;
  6494. }
  6495. i=i+1;
  6496. }
  6497. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6498. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6499. fnamePWithNoPath[i+1] = '\0';
  6500. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6501. {
  6502. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6503. {
  6504. fnamePWithNoPath[j]='\0';
  6505. }
  6506. }
  6507. FILE* fp1 = fopen(fnamePlusPath, "r");
  6508. if (fp1)
  6509. {
  6510. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6511. // file exists
  6512. fclose(fp1);
  6513. }
  6514. else
  6515. {
  6516. // file doesn't exist
  6517. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6518. }
  6519. }
  6520. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6521. {
  6522. mtrace();
  6523. int result = FAIL;
  6524. char cmdBuf[512];
  6525. char fName[258];
  6526. time_t CurrentTime;
  6527. struct tm *tm;
  6528. system("/usr/bin/run_tmate_restart.sh");
  6529. pthread_t th_Status;
  6530. CurrentTime = time(NULL);
  6531. tm = localtime(&CurrentTime);
  6532. 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);
  6533. sendGetDiagnosticsConfirmation(uuid, fName);
  6534. system("exec /root/logPackTools 'log' 6");
  6535. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", fName);
  6536. system(cmdBuf);
  6537. checkUploadLog();
  6538. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6539. return result;
  6540. }
  6541. void* GetDiagnosticsProcess(void* data)
  6542. {
  6543. pthread_detach(pthread_self());
  6544. mtrace();
  6545. int retriesInt=0, retryIntervalInt=0;
  6546. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6547. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6548. 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};
  6549. int port=0;
  6550. char sstr[260]={ 0 };
  6551. int c = 0;
  6552. char *loc;
  6553. int isSuccess = FALSE;
  6554. char ftpbuf[200]={0};
  6555. char * pch;
  6556. char str[300]={ 0 };
  6557. strcpy(str,(const char*)data);
  6558. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6559. DEBUG_INFO("GetDiagnosticsProcess...%s\n", str);
  6560. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6561. //****************location*******************/
  6562. c = 0;
  6563. memset(sstr ,0, ARRAY_SIZE(sstr));
  6564. loc = strstr(str, "location");
  6565. while (loc[3+strlen("location")+c] != '\"')
  6566. {
  6567. sstr[c] = loc[3+strlen("location")+c];
  6568. c++;
  6569. }
  6570. sstr[c] = '\0';
  6571. strcpy(locationstr,sstr);
  6572. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6573. if(strcmp(locationstr,"")==0)
  6574. {
  6575. DEBUG_INFO("location is <Empty>!\n");
  6576. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6577. goto end;
  6578. }
  6579. //****************retries*******************/
  6580. c = 0;
  6581. loc = strstr(str, "retries");
  6582. if(loc == NULL)
  6583. {
  6584. retriesIsNULL = TRUE;
  6585. }
  6586. else
  6587. {
  6588. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6589. {
  6590. sstr[c] = loc[strlen("retries")+2+c];
  6591. c++;
  6592. }
  6593. sstr[c] = '\0';
  6594. retriesInt = atoi(sstr);
  6595. }
  6596. if(retriesIsNULL == TRUE)
  6597. {
  6598. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6599. }
  6600. //****************retryInterval*******************/
  6601. c = 0;
  6602. loc = strstr(str, "retryInterval");
  6603. if(loc == NULL)
  6604. {
  6605. retryIntervalIsNULL = TRUE;
  6606. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6607. }
  6608. else
  6609. {
  6610. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6611. {
  6612. sstr[c] = loc[strlen("retryInterval")+2+c];
  6613. c++;
  6614. }
  6615. sstr[c] = '\0';
  6616. retryIntervalInt = atoi(sstr);
  6617. }
  6618. //****************startTime*******************/
  6619. c = 0;
  6620. memset(sstr ,0, ARRAY_SIZE(sstr));
  6621. loc = strstr(str, "startTime");
  6622. if(loc == NULL)
  6623. {
  6624. startTimeIsNULL = TRUE;
  6625. }
  6626. else
  6627. {
  6628. while (loc[3+strlen("startTime")+c] != '\"')
  6629. {
  6630. sstr[c] = loc[3+strlen("startTime")+c];
  6631. c++;
  6632. }
  6633. sstr[c] = '\0';
  6634. strcpy(startTimestr,sstr);
  6635. }
  6636. //****************stopTime*******************/
  6637. c = 0;
  6638. memset(sstr ,0, ARRAY_SIZE(sstr));
  6639. loc = strstr(str, "stopTime");
  6640. if(loc == NULL)
  6641. {
  6642. stopTimeIsNULL = TRUE;
  6643. }
  6644. else
  6645. {
  6646. while (loc[3+strlen("stopTime")+c] != '\"')
  6647. {
  6648. sstr[c] = loc[3+strlen("stopTime")+c];
  6649. c++;
  6650. }
  6651. sstr[c] = '\0';
  6652. strcpy(stopTimestr,sstr);
  6653. }
  6654. memset(protocol, 0, ARRAY_SIZE(protocol));
  6655. memset(user, 0, ARRAY_SIZE(user) );
  6656. memset(password, 0, ARRAY_SIZE(password));
  6657. memset(host, 0, ARRAY_SIZE(host));
  6658. memset(path, 0, ARRAY_SIZE(path));
  6659. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  6660. memset(host1, 0, ARRAY_SIZE(host1));
  6661. memset(path1, 0, ARRAY_SIZE(path1));
  6662. /*location: ftp://user:password@host:port/path*/
  6663. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6664. if((access(fnamePlusPath,F_OK))!=-1)
  6665. {
  6666. DEBUG_INFO("fnamePlusPath exist.\n");
  6667. }
  6668. else
  6669. {
  6670. DEBUG_INFO("fnamePlusPath not exist!\n");
  6671. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6672. goto end;
  6673. }
  6674. pch=strchr(locationstr,'@');
  6675. if(pch==NULL)
  6676. {
  6677. sscanf(locationstr,
  6678. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6679. protocol, host, &port, path);
  6680. strcpy(user,"anonymous");
  6681. strcpy(password,"");
  6682. }
  6683. else
  6684. {
  6685. //DEBUG_INFO("pch=%s\n", pch);
  6686. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6687. protocol, user, password, host, &port, path);
  6688. }
  6689. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6690. {
  6691. DEBUG_INFO("protocol is not ftp/http ! \n");
  6692. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6693. goto end;
  6694. }
  6695. if(strncmp(locationstr,"http", 4) == 0)
  6696. {
  6697. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6698. sprintf(ftppath,"/%s", path);
  6699. do{
  6700. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6701. sleep(retryIntervalInt);
  6702. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6703. if(!isSuccess)
  6704. {
  6705. DEBUG_INFO("Diagnostics fail.\n");
  6706. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6707. }
  6708. else
  6709. {
  6710. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6711. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6712. }
  6713. }
  6714. else
  6715. {
  6716. sscanf(host,"%[^/]%s",host1, path1);
  6717. sprintf(ftppath,"%s", path1);
  6718. int ftppathlen=strlen(ftppath);
  6719. int i=1;
  6720. char filenametemp[50];
  6721. while(i < ftppathlen)
  6722. {
  6723. int len=ftppathlen-i;
  6724. if(ftppath[len]== 47) // '/' ascll code: 47
  6725. {
  6726. DEBUG_INFO("find '/' all right\n");
  6727. break;
  6728. }
  6729. i=i+1;
  6730. }
  6731. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  6732. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6733. filenametemp[i+1] = 0;
  6734. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  6735. if(port == 0)
  6736. port = 21;
  6737. do{
  6738. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6739. sleep(retryIntervalInt);
  6740. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6741. if(!isSuccess)
  6742. {
  6743. DEBUG_INFO("Diagnostics fail.\n");
  6744. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6745. }
  6746. else
  6747. {
  6748. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6749. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6750. }
  6751. }
  6752. end:
  6753. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  6754. pthread_exit(NULL);
  6755. }
  6756. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6757. {
  6758. mtrace();
  6759. int result = FAIL;
  6760. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6761. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6762. {
  6763. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6764. localversion = -1;
  6765. }
  6766. else
  6767. {
  6768. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6769. OCPP_getListVerion();
  6770. }
  6771. //from db.OCPP_getListVerion
  6772. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6773. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6774. sendGetLocalListVersionConfirmation(uuid,"");
  6775. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6776. return result;
  6777. }
  6778. int handleRemoteStartRequest(char *uuid, char *payload)
  6779. {
  6780. mtrace();
  6781. int result = FAIL;
  6782. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6783. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6784. int tempIndex = 0;
  6785. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6786. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6787. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6788. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6789. int chargingSchedulePeriodCount = 0;
  6790. char sstr[30]={ 0 },sstrtemp[1600]={ 0 };//sstr[200]={ 0 };
  6791. int c = 0;
  6792. char *loc;
  6793. char comfirmstr[20]={0};
  6794. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6795. if(server_pending == TRUE)
  6796. {
  6797. return 0;
  6798. }
  6799. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6800. strcpy(sstrtemp, stringtrimspace(payload));
  6801. //**********connectorId****************/
  6802. c = 0;
  6803. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6804. loc = strstr(sstrtemp, "connectorId");
  6805. if(loc == NULL)
  6806. {
  6807. connectorIdIsNULL = TRUE;
  6808. }
  6809. else
  6810. {
  6811. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6812. {
  6813. sstr[c] = loc[strlen("connectorId")+2+c];
  6814. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6815. c++;
  6816. }
  6817. sstr[c] = '\0';
  6818. connectorIdInt = atoi(sstr);
  6819. }
  6820. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6821. {
  6822. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6823. goto end;
  6824. }
  6825. //****************idTag*******************/
  6826. c = 0;
  6827. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6828. loc = strstr(sstrtemp, "idTag");
  6829. while (loc[3+strlen("idTag")+c] != '\"')
  6830. {
  6831. sstr[c] = loc[3+strlen("idTag")+c];
  6832. c++;
  6833. }
  6834. sstr[c] = '\0';
  6835. strcpy(idTagstr,sstr);
  6836. //****************chargingProfile*******************/
  6837. c = 0;
  6838. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6839. loc = strstr(sstrtemp, "chargingProfile");
  6840. if(loc == NULL)
  6841. {
  6842. chargingProfileIsNULL = TRUE;
  6843. }
  6844. else
  6845. {
  6846. //****************chargingProfileId*******************/
  6847. c=0;
  6848. loc = strstr(sstrtemp, "chargingProfileId");
  6849. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6850. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6851. {
  6852. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6853. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6854. c++;
  6855. }
  6856. sstr[c] = '\0';
  6857. chargingProfileIdInt = atoi(sstr);
  6858. //****************transactionId*******************/
  6859. loc = strstr(sstrtemp, "transactionId");
  6860. if(loc == NULL)
  6861. {
  6862. transactionIdIsNULL = TRUE;
  6863. }
  6864. else
  6865. {
  6866. c=0;
  6867. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6868. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6869. {
  6870. sstr[c] = loc[strlen("transactionId")+2+c];
  6871. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6872. c++;
  6873. }
  6874. sstr[c] = '\0';
  6875. transactionIdInt = atoi(sstr);
  6876. }
  6877. //****************stackLevel*******************/
  6878. c=0;
  6879. loc = strstr(sstrtemp, "stackLevel");
  6880. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6881. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6882. {
  6883. sstr[c] = loc[strlen("stackLevel")+2+c];
  6884. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6885. c++;
  6886. }
  6887. sstr[c] = '\0';
  6888. stackLevelInt = atoi(sstr);
  6889. //****************chargingProfilePurpose*******************/
  6890. c = 0;
  6891. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6892. loc = strstr(sstrtemp, "chargingProfilePurpose");
  6893. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6894. {
  6895. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6896. c++;
  6897. }
  6898. sstr[c] = '\0';
  6899. strcpy(chargingProfilePurposestr,sstr);
  6900. //****************chargingProfileKind*******************/
  6901. c = 0;
  6902. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6903. loc = strstr(sstrtemp, "chargingProfileKind");
  6904. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6905. {
  6906. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6907. c++;
  6908. }
  6909. sstr[c] = '\0';
  6910. strcpy(chargingProfileKindstr,sstr);
  6911. //****************recurrencyKind*******************/
  6912. loc = strstr(sstrtemp, "recurrencyKind");
  6913. if(loc == NULL)
  6914. {
  6915. recurrencyKindIsNULL = TRUE;
  6916. }
  6917. else
  6918. {
  6919. c = 0;
  6920. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6921. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6922. {
  6923. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6924. c++;
  6925. }
  6926. sstr[c] = '\0';
  6927. strcpy(recurrencyKindstr,sstr);
  6928. }
  6929. //****************validFrom*******************/
  6930. loc = strstr(sstrtemp, "validFrom");
  6931. if(loc == NULL)
  6932. {
  6933. validFromIsNULL = TRUE;
  6934. }
  6935. else
  6936. {
  6937. c = 0;
  6938. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6939. while (loc[3+strlen("validFrom")+c] != '\"')
  6940. {
  6941. sstr[c] = loc[3+strlen("validFrom")+c];
  6942. c++;
  6943. }
  6944. sstr[c] = '\0';
  6945. strcpy(validFromstr,sstr);
  6946. }
  6947. //****************validTo*******************/
  6948. loc = strstr(sstrtemp, "validTo");
  6949. if(loc == NULL)
  6950. {
  6951. validToIsNULL = TRUE;
  6952. }
  6953. else
  6954. {
  6955. c = 0;
  6956. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6957. while (loc[3+strlen("validTo")+c] != '\"')
  6958. {
  6959. sstr[c] = loc[3+strlen("validTo")+c];
  6960. c++;
  6961. }
  6962. sstr[c] = '\0';
  6963. strcpy(validTostr,sstr);
  6964. }
  6965. //****************chargingSchedule*******************/
  6966. loc = strstr(sstrtemp, "chargingSchedule");
  6967. if(loc != NULL)
  6968. {
  6969. //****************duration*******************/
  6970. loc = strstr(sstrtemp, "duration");
  6971. if(loc == NULL)
  6972. {
  6973. durationIsNULL = TRUE;
  6974. }
  6975. else
  6976. {
  6977. c=0;
  6978. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6979. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6980. {
  6981. sstr[c] = loc[strlen("duration")+2+c];
  6982. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6983. c++;
  6984. }
  6985. sstr[c] = '\0';
  6986. durationInt = atoi(sstr);
  6987. }
  6988. //****************startSchedule******************/
  6989. loc = strstr(sstrtemp, "startSchedule");
  6990. if(loc == NULL)
  6991. {
  6992. startScheduleIsNULL = TRUE;
  6993. }
  6994. else
  6995. {
  6996. c = 0;
  6997. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6998. while (loc[3+strlen("startSchedule")+c] != '\"')
  6999. {
  7000. sstr[c] = loc[3+strlen("startSchedule")+c];
  7001. c++;
  7002. }
  7003. sstr[c] = '\0';
  7004. strcpy(startSchedulestr,sstr);
  7005. }
  7006. //****************chargingRateUnit*******************/
  7007. c = 0;
  7008. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7009. loc = strstr(sstrtemp, "chargingRateUnit");
  7010. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7011. {
  7012. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7013. c++;
  7014. }
  7015. sstr[c] = '\0';
  7016. strcpy(chargingRateUnitstr,sstr);
  7017. //****************minChargingRate*******************/
  7018. loc = strstr(sstrtemp, "minChargingRate");
  7019. if(loc == NULL)
  7020. {
  7021. minChargingRateIsNULL = TRUE;
  7022. }
  7023. else
  7024. {
  7025. c=0;
  7026. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7027. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  7028. {
  7029. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7030. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7031. c++;
  7032. }
  7033. sstr[c] = '\0';
  7034. minChargingRateflaot = atof(sstr);
  7035. }
  7036. //****************chargingSchedulePeriod count*******************/
  7037. int what_len = strlen("startPeriod");
  7038. char *where = sstrtemp;
  7039. while ((where = strstr(where, "startPeriod"))) {
  7040. where += what_len;
  7041. chargingSchedulePeriodCount++;
  7042. }
  7043. where = sstrtemp;
  7044. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7045. {
  7046. //****************startPeriod*******************/
  7047. c=0;
  7048. loc = strstr(where, "startPeriod");
  7049. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7050. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7051. {
  7052. sstr[c] = loc[strlen("startPeriod")+2+c];
  7053. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7054. c++;
  7055. }
  7056. sstr[c] = '\0';
  7057. startPeriodInt[periodNums] = atoi(sstr);
  7058. //****************limit*******************/
  7059. c=0;
  7060. loc = strstr(where, "limit");
  7061. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7062. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7063. {
  7064. sstr[c] = loc[strlen("limit")+2+c];
  7065. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7066. c++;
  7067. }
  7068. sstr[c] = '\0';
  7069. limitflaot[periodNums] = atof(sstr);
  7070. //****************numberPhases*******************/
  7071. loc = strstr(where, "numberPhases");
  7072. if(loc == NULL)
  7073. {
  7074. numberPhasesIsNULL = TRUE;
  7075. }
  7076. else
  7077. {
  7078. c=0;
  7079. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7080. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7081. {
  7082. sstr[c] = loc[strlen("numberPhases")+2+c];
  7083. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7084. c++;
  7085. }
  7086. sstr[c] = '\0';
  7087. numberPhasesInt[periodNums] = atoi(sstr);
  7088. }
  7089. where = loc;
  7090. } // END FOR chargingSchedulePeriodCount
  7091. }// END IF chargingSchedule
  7092. } // END chargingProfile
  7093. /*
  7094. enum _SYSTEM_STATUS
  7095. {
  7096. S_BOOTING = 0,
  7097. S_IDLE, = 1
  7098. S_AUTHORIZING, =2
  7099. S_REASSIGN_CHECK, =3
  7100. S_REASSIGN, =4
  7101. S_PRECHARGE, =5
  7102. S_PREPARING_FOR_EV, =6
  7103. S_PREPARING_FOR_EVSE, =7
  7104. S_CHARGING, =8
  7105. S_TERMINATING, =9
  7106. S_COMPLETE, =10
  7107. S_ALARM, =11
  7108. S_FAULT =12
  7109. }
  7110. */
  7111. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7112. {
  7113. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  7114. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7115. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  7116. //check Transaction active
  7117. if(gunType[connectorIdInt -1] == 'J')
  7118. {
  7119. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7120. {
  7121. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7122. }
  7123. else
  7124. {
  7125. tempIndex = connectorIdInt -1;
  7126. }
  7127. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7128. {
  7129. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7130. {
  7131. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7132. {
  7133. //Reserved
  7134. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7135. }
  7136. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7137. {
  7138. //Reserved
  7139. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7140. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7141. goto end;
  7142. }
  7143. else
  7144. {
  7145. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7146. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7147. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7148. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7149. {
  7150. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7151. goto end;
  7152. }
  7153. }//END FOR ELSE
  7154. }
  7155. }// END FOR CHAdeMO_QUANTITY
  7156. }
  7157. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7158. {
  7159. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7160. {
  7161. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7162. }
  7163. else
  7164. {
  7165. tempIndex = connectorIdInt -1;
  7166. }
  7167. for (int index = 0; index < CCS_QUANTITY; index++)
  7168. {
  7169. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7170. {
  7171. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7172. {
  7173. //Reserved
  7174. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7175. }
  7176. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7177. {
  7178. //Reserved
  7179. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7180. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7181. goto end;
  7182. }
  7183. else
  7184. {
  7185. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7186. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7187. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7188. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7189. {
  7190. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7191. goto end;
  7192. }
  7193. }// END FOR ELSE
  7194. }
  7195. }// END FOR CCS_QUANTITY
  7196. }
  7197. else if(gunType[connectorIdInt -1] == 'G')
  7198. {
  7199. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7200. {
  7201. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7202. }
  7203. else
  7204. {
  7205. tempIndex = connectorIdInt -1;
  7206. }
  7207. for (int index = 0; index < GB_QUANTITY; index++)
  7208. {
  7209. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7210. {
  7211. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7212. {
  7213. //Reserved
  7214. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7215. }
  7216. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7217. {
  7218. //Reserved
  7219. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7220. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7221. goto end;
  7222. }
  7223. else
  7224. {
  7225. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7226. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7227. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7228. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7229. {
  7230. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7231. goto end;
  7232. }
  7233. }// END FOR ELSE
  7234. }
  7235. } // END FOR GB_QUANTITY
  7236. }
  7237. else
  7238. {
  7239. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7240. {
  7241. tempIndex = 2;
  7242. }
  7243. else
  7244. {
  7245. tempIndex = connectorIdInt -1;
  7246. }
  7247. for (int index = 0; index < AC_QUANTITY; index++)
  7248. {
  7249. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7250. {
  7251. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7252. {
  7253. //Reserved
  7254. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7255. }
  7256. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7257. {
  7258. //Reserved
  7259. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7260. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7261. goto end;
  7262. }
  7263. else
  7264. {
  7265. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7266. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7267. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7268. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7269. {
  7270. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7271. goto end;
  7272. }
  7273. }//END FOR ELSE
  7274. }
  7275. }// END FOR AC_QUANTITY
  7276. }
  7277. if(chargingProfileIsNULL == FALSE)
  7278. {
  7279. //ChargingProfile
  7280. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7281. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  7282. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  7283. if(recurrencyKindIsNULL == FALSE) //OPTION
  7284. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  7285. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7286. if(transactionIdIsNULL == FALSE) // OPTION
  7287. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7288. if(validFromIsNULL == FALSE) // OPTION
  7289. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  7290. if(validToIsNULL == FALSE) //OPTION
  7291. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  7292. //ChargingSchedule
  7293. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  7294. if(durationIsNULL == FALSE) //OPTION
  7295. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7296. if(minChargingRateIsNULL == FALSE) //OPTION
  7297. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  7298. if(startScheduleIsNULL == FALSE) //OPTION
  7299. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  7300. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7301. {
  7302. //ChargingSchedulePeriod
  7303. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  7304. if(numberPhasesIsNULL == FALSE)
  7305. {
  7306. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7307. }
  7308. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7309. }
  7310. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7311. {
  7312. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7313. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7314. //memset idTag
  7315. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7316. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7317. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7318. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7319. }
  7320. else
  7321. {
  7322. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7323. }
  7324. }
  7325. else
  7326. {
  7327. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7328. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7329. //memset idTag
  7330. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7331. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7332. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7333. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7334. }
  7335. }
  7336. else
  7337. {
  7338. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7339. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7340. }
  7341. end:
  7342. if(connectorIdIsNULL == FALSE)
  7343. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7344. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7345. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7346. //OCPP send RemoteStartConfirmation by first.
  7347. sendRemoteStartConfirmation(uuid, comfirmstr);
  7348. return result;
  7349. }
  7350. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7351. {
  7352. mtrace();
  7353. int result = FAIL;
  7354. int match = FALSE;
  7355. int GunNO = 0;
  7356. int tempIndex = 0;
  7357. int transactionIdInt=0;
  7358. int transactionIdIsNULL= FALSE;
  7359. char sstr[16]={ 0 },sstrtemp[50]={ 0 };//sstr[200]={ 0 };
  7360. int c = 0;
  7361. char *loc;
  7362. char comfirmstr[20];
  7363. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7364. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7365. if(server_pending == TRUE)
  7366. {
  7367. return 0;
  7368. }
  7369. strcpy(sstrtemp, stringtrimspace(payload));
  7370. c=0;
  7371. loc = strstr(sstrtemp, "transactionId");
  7372. if(loc == NULL)
  7373. {
  7374. transactionIdIsNULL= TRUE;
  7375. }
  7376. else
  7377. {
  7378. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7379. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  7380. {
  7381. sstr[c] = loc[strlen("transactionId")+2+c];
  7382. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7383. c++;
  7384. }
  7385. sstr[c] = '\0';
  7386. transactionIdInt = atoi(sstr);
  7387. }
  7388. if(transactionIdIsNULL == FALSE)
  7389. {
  7390. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7391. {
  7392. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7393. {
  7394. //check Transaction active
  7395. if(gunType[gun_index] == 'J')
  7396. {
  7397. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7398. {
  7399. tempIndex = ((gun_index==2) ? 1: 0);
  7400. }
  7401. else
  7402. {
  7403. tempIndex = gun_index;
  7404. }
  7405. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7406. {
  7407. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7408. {
  7409. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7410. {
  7411. match = TRUE;
  7412. GunNO = gun_index;
  7413. }
  7414. }
  7415. }// END FOR CHAdeMO_QUANTITY
  7416. }
  7417. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7418. {
  7419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7420. {
  7421. tempIndex = ((gun_index==2) ? 1: 0);
  7422. }
  7423. else
  7424. {
  7425. tempIndex = gun_index;
  7426. }
  7427. for (int index = 0; index < CCS_QUANTITY; index++)
  7428. {
  7429. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7430. {
  7431. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7432. {
  7433. match = TRUE;
  7434. GunNO = gun_index;
  7435. }
  7436. }
  7437. }// END FOR CCS_QUANTITY
  7438. }
  7439. else if(gunType[gun_index] == 'G')
  7440. {
  7441. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7442. {
  7443. tempIndex = ((gun_index==2) ? 1: 0);
  7444. }
  7445. else
  7446. {
  7447. tempIndex = gun_index;
  7448. }
  7449. for (int index = 0; index < GB_QUANTITY; index++)
  7450. {
  7451. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7452. {
  7453. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7454. {
  7455. match = TRUE;
  7456. GunNO = gun_index;
  7457. }
  7458. }
  7459. }// END FOR GB_QUANTITY
  7460. }
  7461. else
  7462. {
  7463. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7464. {
  7465. tempIndex = 2;
  7466. }
  7467. else
  7468. {
  7469. tempIndex = gun_index;
  7470. }
  7471. for (int index = 0; index < AC_QUANTITY; index++)
  7472. {
  7473. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7474. {
  7475. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7476. {
  7477. match = TRUE;
  7478. GunNO = gun_index;
  7479. }
  7480. }
  7481. }// END FOR CHAdeMO_QUANTITY
  7482. } // END FOR AC ELSE
  7483. }// CHECK IF ResponseTransactionId == transactionIdInt
  7484. }//END FOR
  7485. if( match == TRUE)
  7486. {
  7487. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7488. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7489. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7490. }
  7491. else
  7492. {
  7493. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7494. }
  7495. }
  7496. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7497. return result;
  7498. }
  7499. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7500. {
  7501. mtrace();
  7502. int result = FAIL;
  7503. int connectorIdInt=0, reservationIdInt=0;
  7504. int tempIndex = 0;
  7505. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7506. char comfirmstr[20]={0};
  7507. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7508. int c = 0;
  7509. char *loc;
  7510. //char *ptr;
  7511. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7512. strcpy(sstrtemp, stringtrimspace(payload));
  7513. //***(1)connectorId ****/
  7514. c=0;
  7515. loc = strstr(sstrtemp, "connectorId");
  7516. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7517. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7518. {
  7519. sstr[c] = loc[strlen("connectorId")+2+c];
  7520. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7521. c++;
  7522. }
  7523. sstr[c] = '\0';
  7524. connectorIdInt = atoi(sstr);
  7525. //***(2)expiryDate ****/
  7526. loc = strstr(sstrtemp, "expiryDate");
  7527. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7528. c = 0;
  7529. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7530. {
  7531. sstr[c] = loc[3+strlen("expiryDate")+c];
  7532. c++;
  7533. }
  7534. sstr[c] = '\0';
  7535. strcpy(expiryDatestr, sstr);
  7536. //***(3)idTag ****/
  7537. loc = strstr(sstrtemp, "idTag");
  7538. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7539. c = 0;
  7540. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7541. {
  7542. sstr[c] = loc[3+strlen("idTag")+c];
  7543. c++;
  7544. }
  7545. sstr[c] = '\0';
  7546. strcpy(idTagstr, sstr);
  7547. //***(4)parentIdTag ****/
  7548. loc = strstr(sstrtemp, "parentIdTag");
  7549. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7550. c = 0;
  7551. if(loc == NULL)
  7552. {
  7553. strcpy(parentIdTagstr, "");
  7554. }
  7555. else
  7556. {
  7557. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7558. {
  7559. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7560. c++;
  7561. }
  7562. sstr[c] = '\0';
  7563. strcpy(parentIdTagstr, sstr);
  7564. }
  7565. //***(5)reservationId ****/
  7566. c=0;
  7567. loc = strstr(sstrtemp, "reservationId");
  7568. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7569. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7570. {
  7571. sstr[c] = loc[strlen("reservationId")+2+c];
  7572. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7573. c++;
  7574. }
  7575. sstr[c] = '\0';
  7576. reservationIdInt = atoi(sstr);
  7577. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7578. /*
  7579. enum SYSTEM_STATUS
  7580. {
  7581. SYS_MODE_BOOTING = 0,
  7582. SYS_MODE_IDLE = 1,
  7583. SYS_MODE_AUTHORIZING = 2,
  7584. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7585. SYS_MODE_REASSIGN = 4,
  7586. SYS_MODE_PREPARING = 5,
  7587. SYS_MODE_PREPARE_FOR_EV = 6,
  7588. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7589. SYS_MODE_CHARGING = 8,
  7590. SYS_MODE_TERMINATING = 9,
  7591. SYS_MODE_COMPLETE = 10,
  7592. SYS_MODE_ALARM = 11,
  7593. SYS_MODE_FAULT = 12,
  7594. SYS_MODE_RESERVATION = 13,
  7595. SYS_MODE_BOOKING = 14,
  7596. SYS_MODE_MAINTAIN = 15,
  7597. SYS_MODE_DEBUG = 16,
  7598. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7599. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7600. SYS_MODE_UPDATE = 19
  7601. };
  7602. */
  7603. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7604. {
  7605. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7606. goto end;
  7607. }
  7608. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7609. {
  7610. //check Transaction active
  7611. if(gunType[connectorIdInt -1] == 'J')
  7612. {
  7613. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7614. {
  7615. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7616. }
  7617. else
  7618. {
  7619. tempIndex = connectorIdInt -1;
  7620. }
  7621. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7622. {
  7623. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7624. {
  7625. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7626. {
  7627. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7628. {
  7629. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7630. {
  7631. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7632. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7633. }
  7634. 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'))
  7635. {
  7636. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7637. }
  7638. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7639. {
  7640. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7641. }
  7642. else
  7643. {
  7644. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7645. }
  7646. }
  7647. 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
  7648. {
  7649. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7650. }
  7651. }
  7652. else
  7653. {
  7654. //replace reservation
  7655. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7656. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7657. }
  7658. }
  7659. } // END FOR CHAdeMO_QUANTITY
  7660. }
  7661. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7662. {
  7663. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7664. {
  7665. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7666. }
  7667. else
  7668. {
  7669. tempIndex = connectorIdInt -1;
  7670. }
  7671. for (int index = 0; index < CCS_QUANTITY; index++)
  7672. {
  7673. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7674. {
  7675. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7676. {
  7677. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7678. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7679. {
  7680. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7681. {
  7682. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7683. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7684. }
  7685. 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'))
  7686. {
  7687. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7688. }
  7689. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7690. {
  7691. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7692. }
  7693. else
  7694. {
  7695. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7696. }
  7697. }
  7698. 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
  7699. {
  7700. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7701. }
  7702. }
  7703. else
  7704. {
  7705. //replace reservation
  7706. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7707. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7708. }
  7709. }
  7710. } // END FOR CCS_QUANTITY
  7711. }
  7712. else if(gunType[connectorIdInt -1] == 'G')
  7713. {
  7714. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7715. {
  7716. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7717. }
  7718. else
  7719. {
  7720. tempIndex = connectorIdInt -1;
  7721. }
  7722. for (int index = 0; index < GB_QUANTITY; index++)
  7723. {
  7724. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7725. {
  7726. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7727. {
  7728. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7729. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7730. {
  7731. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7732. {
  7733. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7734. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7735. }
  7736. 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'))
  7737. {
  7738. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7739. }
  7740. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7741. {
  7742. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7743. }
  7744. else
  7745. {
  7746. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7747. }
  7748. }
  7749. 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
  7750. {
  7751. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7752. }
  7753. }
  7754. else
  7755. {
  7756. //replace reservation
  7757. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7758. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7759. }
  7760. }
  7761. }// END FOR GB_QUANTITY
  7762. }
  7763. else
  7764. {
  7765. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7766. {
  7767. tempIndex = 2;
  7768. }
  7769. else
  7770. {
  7771. tempIndex = (connectorIdInt -1);
  7772. }
  7773. for (int index = 0; index < AC_QUANTITY; index++)
  7774. {
  7775. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7776. {
  7777. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7778. {
  7779. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7780. {
  7781. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7782. {
  7783. 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))
  7784. {
  7785. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7786. }
  7787. else
  7788. {
  7789. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7790. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7791. }
  7792. }
  7793. 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'))
  7794. {
  7795. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7796. }
  7797. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7798. {
  7799. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7800. }
  7801. else
  7802. {
  7803. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7804. }
  7805. }
  7806. 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
  7807. {
  7808. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7809. }
  7810. }
  7811. else
  7812. {
  7813. //replace reservation
  7814. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7815. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7816. }
  7817. }
  7818. } // END FOR AC_QUANTITY
  7819. }
  7820. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7821. }
  7822. else if(connectorIdInt == 0)
  7823. {
  7824. //check Transaction active
  7825. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7826. {
  7827. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7828. {
  7829. 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'))
  7830. {
  7831. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7832. goto end;
  7833. }
  7834. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7835. {
  7836. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7837. goto end;
  7838. }
  7839. 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
  7840. {
  7841. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7842. goto end;
  7843. }
  7844. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7845. {
  7846. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7847. goto end;
  7848. }
  7849. }
  7850. }// END FOR CHAdeMO_QUANTITY
  7851. for (int index = 0; index < CCS_QUANTITY; index++)
  7852. {
  7853. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7854. {
  7855. 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'))
  7856. {
  7857. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7858. goto end;
  7859. }
  7860. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7861. {
  7862. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7863. goto end;
  7864. }
  7865. 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
  7866. {
  7867. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7868. goto end;
  7869. }
  7870. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7871. {
  7872. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7873. goto end;
  7874. }
  7875. }
  7876. } // END FOR CCS_QUANTITY
  7877. for (int index = 0; index < GB_QUANTITY; index++)
  7878. {
  7879. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7880. {
  7881. 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'))
  7882. {
  7883. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7884. goto end;
  7885. }
  7886. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7887. {
  7888. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7889. goto end;
  7890. }
  7891. 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
  7892. {
  7893. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7894. goto end;
  7895. }
  7896. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7897. {
  7898. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7899. goto end;
  7900. }
  7901. }
  7902. } // END FOR GB_QUANTITY
  7903. for (int index = 0; index < AC_QUANTITY; index++)
  7904. {
  7905. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7906. {
  7907. 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'))
  7908. {
  7909. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7910. goto end;
  7911. }
  7912. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7913. {
  7914. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7915. goto end;
  7916. }
  7917. 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
  7918. {
  7919. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7920. goto end;
  7921. }
  7922. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7923. {
  7924. 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))
  7925. {
  7926. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7927. goto end;
  7928. }
  7929. }
  7930. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7931. {
  7932. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7933. goto end;
  7934. }
  7935. }
  7936. }// END FOR AC_QUANTITY
  7937. //The connectorId is 0
  7938. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7939. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7940. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7941. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7942. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7943. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7944. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7945. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7946. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7947. result = TRUE;
  7948. return result;
  7949. }
  7950. else
  7951. {
  7952. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7953. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7954. }
  7955. if(strcmp(comfirmstr,"Accepted") == 0)
  7956. {
  7957. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7958. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7959. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7960. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7961. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7962. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7963. result = TRUE;
  7964. return result;
  7965. }
  7966. end:
  7967. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7968. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7969. return result;
  7970. }
  7971. int handleResetRequest(char *uuid, char *payload)
  7972. {
  7973. mtrace();
  7974. int result = FAIL;
  7975. char sstr[10]={0},sstrtemp[30]={ 0 };
  7976. char typestr[10]={0};
  7977. char comfirmstr[20]={0};
  7978. int c = 0;
  7979. char *loc;
  7980. DEBUG_INFO("handleResetRequest...\n");
  7981. strcpy(sstrtemp, stringtrimspace(payload));
  7982. loc = strstr(sstrtemp, "type");
  7983. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7984. c = 0;
  7985. while (loc[3+strlen("type")+c] != '\"')
  7986. {
  7987. sstr[c] = loc[3+strlen("type")+c];
  7988. c++;
  7989. }
  7990. sstr[c] = '\0';
  7991. strcpy(typestr,sstr);
  7992. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7993. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7994. {
  7995. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7996. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7997. result = TRUE;
  7998. return result;
  7999. }
  8000. else
  8001. {
  8002. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  8003. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  8004. goto errorend;
  8005. }
  8006. errorend:
  8007. sendResetConfirmation(uuid, comfirmstr);
  8008. return result;
  8009. }
  8010. int handleSendLocalListRequest(char *uuid, char *payload)
  8011. {
  8012. mtrace();
  8013. int result = FAIL;
  8014. int listVersionInt;
  8015. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  8016. char listsearch[]="listVersion";
  8017. char updateTypesearch[]="updateType";
  8018. char localAuthorizationListsearch[]="localAuthorizationList";
  8019. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  8020. char CardList[500][160]={0};
  8021. char updateTypestr[15]={0};
  8022. char idTagstr[20]={0};
  8023. char parentIdTag[20]={0};
  8024. char expiryDate[30]={0};
  8025. char idTagstatus[16]={0};
  8026. int c = 0;
  8027. int i = 0;
  8028. char *delim1 = "}";
  8029. char * pch;
  8030. char *loc;
  8031. //char *ptr;
  8032. char comfirmstr[20];
  8033. //int n_localAuthorizations = 0;
  8034. int checkState_Faulted = FALSE;
  8035. DEBUG_INFO("handleSendLocalListRequest...\n");
  8036. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  8037. {
  8038. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8039. goto end;
  8040. }
  8041. //check Charge Point state
  8042. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8043. {
  8044. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8045. {
  8046. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8047. }
  8048. }
  8049. for (int index = 0; index < CCS_QUANTITY; index++)
  8050. {
  8051. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8052. {
  8053. checkState_Faulted = TRUE; //OCPP Status
  8054. }
  8055. }
  8056. for (int index = 0; index < GB_QUANTITY; index++)
  8057. {
  8058. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8059. {
  8060. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8061. }
  8062. }
  8063. //check Charge Point state
  8064. for (int index = 0; index < AC_QUANTITY; index++)
  8065. {
  8066. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8067. {
  8068. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8069. }
  8070. }
  8071. if(checkState_Faulted == TRUE)
  8072. {
  8073. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8074. goto end;
  8075. }
  8076. //Filter payload space
  8077. strcpy(sstrtemp, stringtrimspace(payload));
  8078. //listVersion
  8079. c = 0;
  8080. loc = strstr(sstrtemp, listsearch);
  8081. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8082. {
  8083. sstr[c] = loc[strlen("listVersion")+2+c];
  8084. c++;
  8085. }
  8086. sstr[c] = '\0';
  8087. listVersionInt = atoi(sstr);
  8088. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8089. //updateType
  8090. loc = strstr(sstrtemp, updateTypesearch);
  8091. c = 0;
  8092. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8093. {
  8094. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8095. c++;
  8096. }
  8097. sstr[c] = '\0';
  8098. strcpy(updateTypestr, sstr);
  8099. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8100. //localAuthorizationList
  8101. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8102. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8103. if(loc != NULL) // localAuthorizationList is not NULL
  8104. {
  8105. //Check UpdateType
  8106. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8107. {
  8108. //Local list full update
  8109. printf("Local list full update.\n");
  8110. OCPP_getListVerion();
  8111. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8112. {
  8113. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8114. goto end;
  8115. }
  8116. OCPP_cleanLocalList();
  8117. }
  8118. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8119. {
  8120. //Local list different update
  8121. printf("Local list different update.\n");
  8122. OCPP_getListVerion();
  8123. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8124. {
  8125. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8126. goto end;
  8127. }
  8128. }
  8129. else
  8130. {
  8131. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8132. goto end;
  8133. }
  8134. c = 0;
  8135. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8136. {
  8137. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8138. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8139. c++;
  8140. }
  8141. sstr[c] = '\0';
  8142. //DEBUG_INFO("sstr=%s\n", sstr);
  8143. //parsing strings to words
  8144. i = 0;
  8145. pch = strtok(sstr,delim1);
  8146. while (pch != NULL)
  8147. {
  8148. strcpy(CardList[i], pch);
  8149. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8150. pch = strtok (NULL, delim1);
  8151. i = i + 1;
  8152. }
  8153. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8154. //local Authorizations List Numbers
  8155. //n_localAuthorizations = i;
  8156. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8157. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8158. c= 0;
  8159. while(c < i) // i is CardList Number
  8160. {
  8161. //Search "IdToken"
  8162. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8163. loc = strstr(CardList[c], "idTag");
  8164. int j = 0;
  8165. while (loc[3+strlen("idTag")+j] != '\"')
  8166. {
  8167. sstr[j] = loc[3+strlen("idTag")+j];
  8168. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8169. j++;
  8170. }
  8171. sstr[j] = '\0';
  8172. strcpy(idTagstr, sstr);
  8173. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8174. //Search "expiryDate"
  8175. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8176. loc = strstr(CardList[c], "expiryDate");
  8177. j = 0;
  8178. if(loc != NULL)
  8179. {
  8180. while (loc[3+strlen("expiryDate")+j] != '\"')
  8181. {
  8182. sstr[j] = loc[3+strlen("expiryDate")+j];
  8183. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8184. j++;
  8185. }
  8186. sstr[j] = '\0';
  8187. strcpy(expiryDate, sstr);
  8188. }
  8189. else
  8190. {
  8191. strcpy(expiryDate, "");
  8192. }
  8193. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8194. //Search "parentIdTag"
  8195. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8196. loc = strstr(CardList[c], "parentIdTag");
  8197. j = 0;
  8198. if(loc != NULL)
  8199. {
  8200. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8201. {
  8202. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8203. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8204. j++;
  8205. }
  8206. sstr[j] = '\0';
  8207. strcpy(parentIdTag, sstr);
  8208. }
  8209. else
  8210. {
  8211. strcpy(parentIdTag, "");
  8212. }
  8213. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8214. //Search "status"
  8215. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8216. loc = strstr(CardList[c], "status");
  8217. j = 0;
  8218. while (loc[3+strlen("status")+j] != '\"')
  8219. {
  8220. sstr[j] = loc[3+strlen("status")+j];
  8221. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8222. j++;
  8223. }
  8224. sstr[j] = '\0';
  8225. strcpy(idTagstatus, sstr);
  8226. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8227. OCPP_getIdTag(idTagstr);
  8228. //OCPP_getIdTag("test"); For Test
  8229. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8230. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8231. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8232. {
  8233. //Local list full update
  8234. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8235. // update list
  8236. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8237. //DEBUG_INFO("Local list full update. 1\n");
  8238. //OCPP_get_TableAuthlocalAllData();
  8239. //DEBUG_INFO("Local list full update. 2\n");
  8240. }
  8241. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8242. {
  8243. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8244. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8245. }
  8246. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8247. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8248. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8249. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8250. c++;
  8251. }
  8252. }
  8253. else
  8254. {
  8255. //Check UpdateType
  8256. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8257. {
  8258. //Local list full update
  8259. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8260. OCPP_cleanLocalList();
  8261. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8262. goto end;
  8263. }
  8264. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8265. {
  8266. //Local list different update
  8267. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8268. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8269. goto end;
  8270. }
  8271. }
  8272. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8273. end:
  8274. sendSendLocalListConfirmation(uuid, comfirmstr);
  8275. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8276. return result;
  8277. }
  8278. #define MAX 200
  8279. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8280. {
  8281. mtrace();
  8282. int result = FAIL;
  8283. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8284. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8285. char chargingProfilePurposeStr[30]={0};
  8286. char chargingProfileKindStr[16]={0};
  8287. char recurrencyKindStr[10]={0};
  8288. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8289. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8290. int chargingSchedulePeriodCount = 0;
  8291. //int updateflag = FALSE;
  8292. char comfirmstr[20]={0};
  8293. int meet= FALSE;
  8294. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8295. int c = 0;
  8296. char *loc;
  8297. FILE *fptr1;//, *fptr2;
  8298. //int lno=0;//, linectr = 0;
  8299. //int modifyflag = FALSE;
  8300. char filename[MAX]={0};
  8301. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8302. //int resultRename=0;
  8303. char rmFileCmd[50]={0};
  8304. char tempchargingProfilePurposeStr[30]={0};
  8305. char word[1600]={0};
  8306. int n_chargingProfile = 0;
  8307. //[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}}}]
  8308. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8309. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8310. //Filter string space
  8311. strcpy(sstrtemp, stringtrimspace(payload));
  8312. //*********************connectorId***************************/
  8313. loc = strstr(sstrtemp, "connectorId");
  8314. c = 0;
  8315. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8316. while (loc[strlen("connectorId")+2+c] != ',')
  8317. {
  8318. sstr[c] = loc[strlen("connectorId")+2+c];
  8319. c++;
  8320. }
  8321. sstr[c] = '\0';
  8322. connectorIdInt = atoi(sstr);
  8323. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8324. {
  8325. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8326. }
  8327. else
  8328. {
  8329. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8330. }
  8331. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8332. //*********************chargingProfileId***************************/
  8333. loc = strstr(sstrtemp, "chargingProfileId");
  8334. c = 0;
  8335. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8336. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8337. {
  8338. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8339. c++;
  8340. }
  8341. sstr[c] = '\0';
  8342. chargingProfileIdInt = atoi(sstr);
  8343. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8344. {
  8345. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8346. }
  8347. else
  8348. {
  8349. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8350. }
  8351. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8352. //*********************transactionId***************************/
  8353. loc = strstr(sstrtemp, "transactionId");
  8354. if(loc != NULL)
  8355. {
  8356. c = 0;
  8357. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8358. while (loc[strlen("transactionId")+2+c] != ',')
  8359. {
  8360. sstr[c] = loc[strlen("transactionId")+2+c];
  8361. c++;
  8362. }
  8363. sstr[c] = '\0';
  8364. transactionIdInt = atoi(sstr);
  8365. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8366. {
  8367. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8368. }
  8369. else
  8370. {
  8371. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8372. }
  8373. }
  8374. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8375. //*********************stackLevel***************************/
  8376. loc = strstr(sstrtemp, "stackLevel");
  8377. c = 0;
  8378. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8379. while (loc[strlen("stackLevel")+2+c] != ',')
  8380. {
  8381. sstr[c] = loc[strlen("stackLevel")+2+c];
  8382. c++;
  8383. }
  8384. sstr[c] = '\0';
  8385. stackLevelInt = atoi(sstr);
  8386. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8387. {
  8388. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8389. }
  8390. else
  8391. {
  8392. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8393. }
  8394. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8395. //*********************chargingProfilePurpose***************************/
  8396. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8397. c = 0;
  8398. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8399. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8400. {
  8401. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8402. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8403. c++;
  8404. }
  8405. sstr[c] = '\0';
  8406. strcpy(chargingProfilePurposeStr,sstr);
  8407. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8408. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8409. {
  8410. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8411. }
  8412. else
  8413. {
  8414. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8415. }
  8416. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8417. //*********************chargingProfileKind***************************/
  8418. loc = strstr(sstrtemp, "chargingProfileKind");
  8419. c = 0;
  8420. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8421. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8422. {
  8423. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8424. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8425. c++;
  8426. }
  8427. sstr[c] = '\0';
  8428. strcpy(chargingProfileKindStr,sstr);
  8429. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8430. {
  8431. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8432. }
  8433. else
  8434. {
  8435. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8436. }
  8437. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8438. //*********************recurrencyKind***************************/
  8439. loc = strstr(sstrtemp, "recurrencyKind");
  8440. if(loc != NULL)
  8441. {
  8442. c = 0;
  8443. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8444. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8445. {
  8446. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8447. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8448. c++;
  8449. }
  8450. sstr[c] = '\0';
  8451. strcpy(recurrencyKindStr,sstr);
  8452. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8453. {
  8454. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8455. }
  8456. else
  8457. {
  8458. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8459. }
  8460. }
  8461. else
  8462. {
  8463. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8464. {
  8465. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8466. }
  8467. else
  8468. {
  8469. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8470. }
  8471. }
  8472. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8473. //*********************validFrom***************************/
  8474. loc = strstr(sstrtemp, "validFrom");
  8475. if(loc != NULL)
  8476. {
  8477. c = 0;
  8478. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8479. while (loc[3+strlen("validFrom")+c] != '\"')
  8480. {
  8481. sstr[c] = loc[3+strlen("validFrom")+c];
  8482. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8483. c++;
  8484. }
  8485. sstr[c] = '\0';
  8486. strcpy(validFromStr,sstr);
  8487. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8488. {
  8489. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8490. }
  8491. else
  8492. {
  8493. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8494. }
  8495. }
  8496. else
  8497. {
  8498. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8499. {
  8500. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8501. }
  8502. else
  8503. {
  8504. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8505. }
  8506. }
  8507. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8508. //*********************validTo***************************/
  8509. loc = strstr(sstrtemp, "validTo");
  8510. if(loc != NULL)
  8511. {
  8512. c = 0;
  8513. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8514. while (loc[3+strlen("validTo")+c] != '\"')
  8515. {
  8516. sstr[c] = loc[3+strlen("validTo")+c];
  8517. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8518. c++;
  8519. }
  8520. sstr[c] = '\0';
  8521. strcpy(validToStr,sstr);
  8522. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8523. {
  8524. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8525. }
  8526. else
  8527. {
  8528. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8529. }
  8530. }
  8531. else
  8532. {
  8533. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8534. {
  8535. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8536. }
  8537. else
  8538. {
  8539. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8540. }
  8541. }
  8542. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8543. //*********************duration***************************/
  8544. loc = strstr(sstrtemp, "duration");
  8545. if(loc != NULL)
  8546. {
  8547. c = 0;
  8548. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8549. while (loc[strlen("duration")+2+c] != ',')
  8550. {
  8551. sstr[c] = loc[strlen("duration")+2+c];
  8552. c++;
  8553. }
  8554. sstr[c] = '\0';
  8555. durationInt = atoi(sstr);
  8556. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8557. {
  8558. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8559. }
  8560. else
  8561. {
  8562. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8563. }
  8564. }
  8565. else
  8566. {
  8567. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8568. {
  8569. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8570. }
  8571. else
  8572. {
  8573. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8574. }
  8575. }
  8576. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8577. //*********************startSchedule***************************/
  8578. loc = strstr(sstrtemp, "startSchedule");
  8579. if(loc != NULL)
  8580. {
  8581. c = 0;
  8582. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8583. while (loc[3+strlen("startSchedule")+c] != '\"')
  8584. {
  8585. sstr[c] = loc[3+strlen("startSchedule")+c];
  8586. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8587. c++;
  8588. }
  8589. sstr[c] = '\0';
  8590. strcpy(startScheduleStr,sstr);
  8591. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8592. {
  8593. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8594. }
  8595. else
  8596. {
  8597. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8598. }
  8599. }
  8600. else
  8601. {
  8602. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8603. {
  8604. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8605. }
  8606. else
  8607. {
  8608. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8609. }
  8610. }
  8611. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8612. //*********************chargingRateUnit***************************/
  8613. loc = strstr(sstrtemp, "chargingRateUnit");
  8614. if(loc != NULL)
  8615. {
  8616. c = 0;
  8617. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8618. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8619. {
  8620. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8621. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8622. c++;
  8623. }
  8624. sstr[c] = '\0';
  8625. strcpy(chargingRateUnitStr,sstr);
  8626. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8627. {
  8628. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8629. }
  8630. else
  8631. {
  8632. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8633. }
  8634. }
  8635. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8636. //****************chargingSchedulePeriod count start*******************/
  8637. int what_len = strlen("startPeriod");
  8638. char tempChargingProfile[1600]={0};
  8639. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8640. char *where = tempChargingProfile;
  8641. if (what_len)
  8642. {
  8643. while ((where = strstr(where, "startPeriod"))) {
  8644. where += what_len;
  8645. chargingSchedulePeriodCount++;
  8646. }
  8647. }
  8648. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8649. {
  8650. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8651. goto end;
  8652. }
  8653. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8654. //where = payload;
  8655. int templength = 0;
  8656. //int searchstart = 0;
  8657. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8658. {
  8659. //****************startPeriod*******************/
  8660. c=0;
  8661. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8662. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8663. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8664. {
  8665. sstr[c] = loc[strlen("startPeriod")+2+c];
  8666. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8667. c++;
  8668. }
  8669. sstr[c] = '\0';
  8670. startPeriodInt[periodNums] = atoi(sstr);
  8671. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8672. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8673. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8674. {
  8675. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8676. }
  8677. else
  8678. {
  8679. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8680. }
  8681. templength = strlen("startPeriod")+2+c;
  8682. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8683. //****************limit*******************/
  8684. c=0;
  8685. loc = strstr(tempChargingProfile + templength, "limit");
  8686. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8687. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8688. {
  8689. sstr[c] = loc[strlen("limit")+2+c];
  8690. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8691. c++;
  8692. }
  8693. sstr[c] = '\0';
  8694. limitflaot[periodNums] = atof(sstr);
  8695. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8696. {
  8697. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8698. }
  8699. else
  8700. {
  8701. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8702. }
  8703. templength = templength + strlen("limit")+2+c;
  8704. //****************numberPhases*******************/
  8705. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8706. if(loc != NULL)
  8707. {
  8708. c=0;
  8709. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8710. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8711. {
  8712. sstr[c] = loc[strlen("numberPhases")+2+c];
  8713. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8714. c++;
  8715. }
  8716. sstr[c] = '\0';
  8717. numberPhasesInt[periodNums] = atoi(sstr);
  8718. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8719. {
  8720. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8721. }
  8722. else
  8723. {
  8724. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8725. }
  8726. templength = templength + strlen("numberPhases")+2+c;
  8727. }
  8728. //where = loc;
  8729. }
  8730. //****************chargingSchedulePeriod count end*******************/
  8731. //*********************minChargingRate***************************/
  8732. loc = strstr(sstrtemp, "minChargingRate");
  8733. if(loc != NULL)
  8734. {
  8735. c = 0;
  8736. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8737. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8738. {
  8739. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8740. c++;
  8741. }
  8742. sstr[c] = '\0';
  8743. minChargingRateFloat = atof(sstr);
  8744. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8745. {
  8746. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8747. }
  8748. else
  8749. {
  8750. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8751. }
  8752. }
  8753. else
  8754. {
  8755. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8756. {
  8757. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8758. }
  8759. else
  8760. {
  8761. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8762. }
  8763. }
  8764. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8765. {
  8766. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8767. if(connectorIdInt != 0)
  8768. {
  8769. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8770. goto end;
  8771. }
  8772. strcpy(filename, ChargePointMaxProfile_JSON );
  8773. fptr1 = fopen(filename, "r");
  8774. if (!fptr1)
  8775. {
  8776. //file not exist
  8777. DEBUG_INFO("Unable to open the input file!!\n");
  8778. fptr1 = fopen(filename, "w+");
  8779. }
  8780. else
  8781. {
  8782. //Check Charging Profile Count
  8783. while(fscanf(fptr1, "%s", word) != EOF)
  8784. {
  8785. //DEBUG_INFO("word=%s\n",word);
  8786. if(strstr(word, "chargingProfileId")!= NULL)
  8787. {
  8788. //DEBUG_INFO("test chargingProfileId \n");
  8789. n_chargingProfile = n_chargingProfile + 1;
  8790. //DEBUG_INFO("chargingProfileId Found\n");
  8791. }
  8792. }
  8793. }
  8794. fclose(fptr1);
  8795. }
  8796. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8797. {
  8798. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8799. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8800. {
  8801. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8802. goto end;
  8803. }
  8804. memset(filename, 0, ARRAY_SIZE(filename));
  8805. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8806. fptr1 = fopen(filename, "r");
  8807. if (!fptr1)
  8808. {
  8809. //file not exist
  8810. //DEBUG_INFO("Unable to open the input file!!\n");
  8811. fptr1 = fopen(filename, "w+");
  8812. }
  8813. else
  8814. {
  8815. //Check Charging Profile Count
  8816. while(fscanf(fptr1, "%s", word) != EOF)
  8817. {
  8818. //DEBUG_INFO("word=%s\n",word);
  8819. if(strstr(word, "chargingProfileId")!= NULL)
  8820. {
  8821. //DEBUG_INFO("test chargingProfileId \n");
  8822. n_chargingProfile = n_chargingProfile + 1;
  8823. //DEBUG_INFO("chargingProfileId Found\n");
  8824. }
  8825. }
  8826. }
  8827. fclose(fptr1);
  8828. }
  8829. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8830. {
  8831. //printf("set chargingProfile 1-4\n");
  8832. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8833. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8834. if(connectorIdInt == 0)
  8835. {
  8836. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8837. goto end;
  8838. }
  8839. int tempIndex = 0;
  8840. //check Transaction active
  8841. if(gunType[connectorIdInt -1] == 'J')
  8842. {
  8843. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8844. {
  8845. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8846. }
  8847. else
  8848. {
  8849. tempIndex = connectorIdInt -1;
  8850. }
  8851. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8852. {
  8853. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8854. {
  8855. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8856. {
  8857. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8858. {
  8859. meet = TRUE;
  8860. break;
  8861. }
  8862. }
  8863. }
  8864. }
  8865. }
  8866. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8867. {
  8868. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8869. {
  8870. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8871. }
  8872. else
  8873. {
  8874. tempIndex = connectorIdInt -1;
  8875. }
  8876. for (int index = 0; index < CCS_QUANTITY; index++)
  8877. {
  8878. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8879. {
  8880. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8881. {
  8882. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8883. {
  8884. meet = TRUE;
  8885. break;
  8886. }
  8887. }
  8888. }
  8889. }
  8890. }
  8891. else if(gunType[connectorIdInt -1] == 'G')
  8892. {
  8893. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8894. {
  8895. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8896. }
  8897. else
  8898. {
  8899. tempIndex = connectorIdInt -1;
  8900. }
  8901. for (int index = 0; index < GB_QUANTITY; index++)
  8902. {
  8903. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8904. {
  8905. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8906. {
  8907. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8908. {
  8909. meet = TRUE;
  8910. break;
  8911. }
  8912. }
  8913. }
  8914. }
  8915. }
  8916. else
  8917. {
  8918. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8919. {
  8920. tempIndex = 2;
  8921. }
  8922. else
  8923. {
  8924. tempIndex = (connectorIdInt -1);
  8925. }
  8926. for (int index = 0; index < AC_QUANTITY; index++)
  8927. {
  8928. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8929. {
  8930. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8931. {
  8932. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8933. {
  8934. meet = TRUE;
  8935. break;
  8936. }
  8937. }
  8938. }
  8939. }
  8940. }
  8941. //check Transaction active
  8942. if(meet == FALSE)
  8943. {
  8944. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8945. goto end;
  8946. }
  8947. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8948. {
  8949. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8950. goto end;
  8951. }
  8952. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8953. fptr1 = fopen(filename, "r");
  8954. if (!fptr1)
  8955. {
  8956. //file not exist
  8957. DEBUG_INFO("Unable to open the input file!!\n");
  8958. fptr1 = fopen(filename, "w+");
  8959. }
  8960. else
  8961. {
  8962. //Check Charging Profile Count
  8963. while(fscanf(fptr1, "%s", word) != EOF)
  8964. {
  8965. //DEBUG_INFO("word=%s\n",word);
  8966. if(strstr(word, "chargingProfileId")!= NULL)
  8967. {
  8968. //DEBUG_INFO("test chargingProfileId \n");
  8969. n_chargingProfile = n_chargingProfile + 1;
  8970. //DEBUG_INFO("chargingProfileId Found\n");
  8971. }
  8972. }
  8973. }
  8974. fclose(fptr1);
  8975. }
  8976. // Check ChargeProfileMaxStackLevel
  8977. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8978. {
  8979. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8980. goto end;
  8981. }
  8982. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8983. {
  8984. int i = 0;
  8985. char fnametemp[200]={0};
  8986. n_chargingProfile = 0;
  8987. //Check ChargePointMaxProfile.json exit
  8988. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8989. {
  8990. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8991. //Check Charging Profile Count
  8992. while(fscanf(fptr1, "%s", word) != EOF)
  8993. {
  8994. //DEBUG_INFO("word=%s\n",word);
  8995. if(strstr(word, "chargingProfileId")!= NULL)
  8996. {
  8997. //DEBUG_INFO("test chargingProfileId \n");
  8998. n_chargingProfile = n_chargingProfile + 1;
  8999. i = i + 1;
  9000. //DEBUG_INFO("chargingProfileId Found\n");
  9001. }
  9002. memset(word, 0, ARRAY_SIZE(word));
  9003. }
  9004. fclose(fptr1);
  9005. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9006. }
  9007. //Check TxDefaultProfile_0.json exit
  9008. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9009. {
  9010. i = 0;
  9011. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  9012. //Check Charging Profile Count
  9013. while(fscanf(fptr1, "%s", word) != EOF)
  9014. {
  9015. //DEBUG_INFO("word=%s\n",word);
  9016. if(strstr(word, "chargingProfileId")!= NULL)
  9017. {
  9018. //DEBUG_INFO("test chargingProfileId \n");
  9019. n_chargingProfile = n_chargingProfile + 1;
  9020. i = i + 1;
  9021. //DEBUG_INFO("chargingProfileId Found\n");
  9022. }
  9023. memset(word, 0, ARRAY_SIZE(word));
  9024. }
  9025. fclose(fptr1);
  9026. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9027. }
  9028. //Check TxDefaultProfile_%d.json
  9029. for(int j=1; j <= gunTotalNumber; j++)
  9030. {
  9031. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9032. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9033. if((access(fnametemp,F_OK))!=-1)
  9034. {
  9035. i = 0;
  9036. fptr1 = fopen(fnametemp, "r");
  9037. //Check Charging Profile Count
  9038. while(fscanf(fptr1, "%s", word) != EOF)
  9039. {
  9040. //DEBUG_INFO("word=%s\n",word);
  9041. if(strstr(word, "chargingProfileId")!= NULL)
  9042. {
  9043. //DEBUG_INFO("test chargingProfileId \n");
  9044. n_chargingProfile = n_chargingProfile + 1;
  9045. i = i + 1;
  9046. //DEBUG_INFO("chargingProfileId Found\n");
  9047. }
  9048. memset(word, 0, ARRAY_SIZE(word));
  9049. }
  9050. fclose(fptr1);
  9051. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9052. }
  9053. }
  9054. //Check TxProfile_%d.json
  9055. for(int j=1; j <= gunTotalNumber; j++)
  9056. {
  9057. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9058. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9059. if((access(fnametemp,F_OK))!=-1)
  9060. {
  9061. i = 0;
  9062. fptr1 = fopen(fnametemp, "r");
  9063. //Check Charging Profile Count
  9064. while(fscanf(fptr1, "%s", word) != EOF)
  9065. {
  9066. //DEBUG_INFO("word=%s\n",word);
  9067. if(strstr(word, "chargingProfileId")!= NULL)
  9068. {
  9069. //DEBUG_INFO("test chargingProfileId \n");
  9070. n_chargingProfile = n_chargingProfile + 1;
  9071. i = i + 1;
  9072. //DEBUG_INFO("chargingProfileId Found\n");
  9073. }
  9074. memset(word, 0, ARRAY_SIZE(word));
  9075. }
  9076. fclose(fptr1);
  9077. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9078. }
  9079. }
  9080. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9081. {
  9082. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9083. goto end;
  9084. }
  9085. }
  9086. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9087. //**********************************Write to File********************************************************/
  9088. FILE *infile;
  9089. FILE *outfile;
  9090. // open file for writing
  9091. infile = fopen (filename, "r");
  9092. outfile = fopen (tempfile, "w");
  9093. int d =0;
  9094. d = fgetc(infile);
  9095. //DEBUG_INFO("d:%d\n",d);
  9096. rewind(infile);
  9097. //*璉 瘚 辣蝏     1嚗   0 */
  9098. if(d == EOF)
  9099. {
  9100. //DEBUG_INFO("ChargingProfile content is NULL\n");
  9101. fprintf(outfile,"%s\n",payload);
  9102. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9103. fclose(infile);
  9104. fclose(outfile);
  9105. sprintf(rmFileCmd,"rm -f %s",filename);
  9106. system(rmFileCmd);
  9107. rename(tempfile, filename);
  9108. sleep(1);
  9109. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  9110. //system(rmFileCmd);
  9111. }
  9112. else
  9113. {
  9114. char buf[1000]={0};
  9115. int ChargingProfileAdded = FALSE;
  9116. while (fgets(buf, sizeof(buf), infile) != NULL)
  9117. {
  9118. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9119. //*************************tempconnectorIdInt*********************************/
  9120. loc = strstr(buf, "connectorId");
  9121. c = 0;
  9122. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9123. while (loc[strlen("connectorId")+2+c] != ',')
  9124. {
  9125. sstr[c] = loc[strlen("connectorId")+2+c];
  9126. c++;
  9127. }
  9128. sstr[c] = '\0';
  9129. tempconnectorIdInt = atoi(sstr);
  9130. //*************************tempchargingProfileIdInt*********************************/
  9131. loc = strstr(buf, "chargingProfileId");
  9132. c = 0;
  9133. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9134. while (loc[strlen("chargingProfileId")+2+c] != ',')
  9135. {
  9136. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  9137. c++;
  9138. }
  9139. sstr[c] = '\0';
  9140. tempchargingProfileIdInt = atoi(sstr);
  9141. //*************************tempstackLevelInt*********************************/
  9142. loc = strstr(buf, "stackLevel");
  9143. c = 0;
  9144. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9145. while (loc[strlen("stackLevel")+2+c] != ',')
  9146. {
  9147. sstr[c] = loc[strlen("stackLevel")+2+c];
  9148. c++;
  9149. }
  9150. sstr[c] = '\0';
  9151. tempstackLevelInt = atoi(sstr);
  9152. //*************************tempchargingProfilePurposeStr*********************************/
  9153. loc = strstr(payload, "chargingProfilePurpose");
  9154. c = 0;
  9155. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9156. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  9157. {
  9158. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  9159. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9160. c++;
  9161. }
  9162. sstr[c] = '\0';
  9163. strcpy(tempchargingProfilePurposeStr,sstr);
  9164. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9165. {
  9166. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9167. {
  9168. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9169. if(ChargingProfileAdded == FALSE)
  9170. {
  9171. fprintf(outfile,"%s\n",payload);
  9172. ChargingProfileAdded = TRUE;
  9173. }
  9174. }
  9175. else
  9176. {
  9177. if(tempstackLevelInt < stackLevelInt)
  9178. {
  9179. if(ChargingProfileAdded == FALSE)
  9180. {
  9181. fprintf(outfile,"%s\n",payload);
  9182. ChargingProfileAdded = TRUE;
  9183. fprintf(outfile,"%s\n",buf);
  9184. }
  9185. else
  9186. {
  9187. fprintf(outfile,"%s\n",buf);
  9188. }
  9189. }
  9190. else
  9191. {
  9192. if(ChargingProfileAdded == FALSE)
  9193. {
  9194. fprintf(outfile,"%s\n",buf);
  9195. fprintf(outfile,"%s\n",payload);
  9196. ChargingProfileAdded = TRUE;
  9197. }
  9198. else
  9199. {
  9200. fprintf(outfile,"%s\n",buf);
  9201. }
  9202. }
  9203. }
  9204. }
  9205. else
  9206. {
  9207. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9208. {
  9209. if(ChargingProfileAdded == FALSE)
  9210. {
  9211. fprintf(outfile,"%s\n",payload);
  9212. ChargingProfileAdded = TRUE;
  9213. fprintf(outfile,"%s\n",buf);
  9214. }
  9215. else
  9216. {
  9217. fprintf(outfile,"%s\n",buf);
  9218. }
  9219. }
  9220. else if(tempstackLevelInt < stackLevelInt)
  9221. {
  9222. if(ChargingProfileAdded == FALSE)
  9223. {
  9224. fprintf(outfile,"%s\n",payload);
  9225. ChargingProfileAdded = TRUE;
  9226. fprintf(outfile,"%s\n",buf);
  9227. }
  9228. else
  9229. {
  9230. fprintf(outfile,"%s\n",buf);
  9231. }
  9232. }
  9233. else
  9234. {
  9235. if(ChargingProfileAdded == FALSE)
  9236. {
  9237. fprintf(outfile,"%s\n",buf);
  9238. fprintf(outfile,"%s\n",payload);
  9239. ChargingProfileAdded = TRUE;
  9240. }
  9241. else
  9242. {
  9243. fprintf(outfile,"%s\n",buf);
  9244. }
  9245. }
  9246. }
  9247. } // end of while loop
  9248. fclose(infile);
  9249. fclose(outfile);
  9250. sprintf(rmFileCmd,"rm -f %s",filename);
  9251. system(rmFileCmd);
  9252. rename(tempfile, filename);
  9253. sleep(1);
  9254. result = TRUE;
  9255. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9256. }
  9257. end:
  9258. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9259. return result;
  9260. return result;
  9261. }
  9262. int handleTriggerMessageRequest(char *uuid, char *payload)
  9263. {
  9264. mtrace();
  9265. int result = FAIL;
  9266. int connectorIdIsNULL = FALSE;
  9267. int connectorIdInt =0;
  9268. char sstr[40]={0},sstrtemp[100]={ 0 };
  9269. char requestedMessagestr[40]={0};
  9270. char comfirmstr[20]={0};
  9271. int c = 0;
  9272. char *loc;
  9273. DEBUG_INFO("handleTriggerMessageRequest\n");
  9274. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9275. strcpy(sstrtemp, stringtrimspace(payload));
  9276. c = 0;
  9277. loc = strstr(sstrtemp, "requestedMessage");
  9278. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9279. {
  9280. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9281. c++;
  9282. }
  9283. sstr[c] = '\0';
  9284. strcpy(requestedMessagestr, sstr);
  9285. c = 0;
  9286. loc = strstr(sstrtemp, "connectorId");
  9287. if(loc == NULL)
  9288. {
  9289. connectorIdIsNULL = TRUE;
  9290. }
  9291. else
  9292. {
  9293. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9294. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9295. {
  9296. sstr[c] = loc[strlen("connectorId")+2+c];
  9297. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9298. c++;
  9299. }
  9300. sstr[c] = '\0';
  9301. connectorIdInt = atoi(sstr);
  9302. }
  9303. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  9304. {
  9305. //connectorIdInt = json_object_get_int(connectorId);
  9306. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9307. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9308. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9309. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9310. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9311. }
  9312. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9313. {
  9314. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9315. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9316. return TRUE;
  9317. }
  9318. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9319. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9320. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9321. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9322. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9323. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9324. {
  9325. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9326. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9327. return TRUE;
  9328. }
  9329. else
  9330. {
  9331. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9332. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9333. }
  9334. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9335. {
  9336. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9337. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9338. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9339. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9340. {
  9341. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9342. }
  9343. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9344. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9345. }
  9346. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9347. {
  9348. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9349. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9350. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9351. }
  9352. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9353. {
  9354. sendBootNotificationRequest();
  9355. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9356. }
  9357. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9358. {
  9359. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9360. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9361. }
  9362. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9363. {
  9364. if(connectorIdIsNULL == FALSE)
  9365. {
  9366. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9367. {
  9368. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9369. sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9370. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9371. }
  9372. }
  9373. else
  9374. {
  9375. for(int idx=0;idx< gunTotalNumber;idx++)
  9376. {
  9377. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  9378. sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9379. }
  9380. }
  9381. }
  9382. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9383. {
  9384. if(connectorIdIsNULL == FALSE)
  9385. {
  9386. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9387. {
  9388. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9389. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9390. }
  9391. }
  9392. else
  9393. {
  9394. for(int idx=0;idx< gunTotalNumber;idx++)
  9395. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9396. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9397. }
  9398. }
  9399. return result;
  9400. }
  9401. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9402. {
  9403. mtrace();
  9404. int result = FAIL;
  9405. char sstr[6]={0},sstrtemp[50]={ 0 };
  9406. int connectorIdInt =0;
  9407. char comfirmstr[20]={0};
  9408. int c = 0;
  9409. int tempIndex = 0;
  9410. char *loc;
  9411. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9412. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9413. strcpy(sstrtemp, stringtrimspace(payload));
  9414. c = 0;
  9415. loc = strstr(sstrtemp, "connectorId");
  9416. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9417. while (loc[strlen("connectorId")+2+c] != '}')
  9418. {
  9419. sstr[c] = loc[strlen("connectorId")+2+c];
  9420. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9421. c++;
  9422. }
  9423. sstr[c] = '\0';
  9424. connectorIdInt = atoi(sstr);
  9425. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  9426. if(gunTotalNumber == 0)
  9427. {
  9428. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9429. goto end;
  9430. }
  9431. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9432. {
  9433. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9434. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9435. goto end;
  9436. }
  9437. else
  9438. {
  9439. //check Transaction active
  9440. if(gunType[connectorIdInt-1] == 'J')
  9441. {
  9442. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9443. {
  9444. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9445. }
  9446. else
  9447. {
  9448. tempIndex = connectorIdInt -1;
  9449. }
  9450. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9451. {
  9452. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9453. {
  9454. //stop Transaction
  9455. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9456. }
  9457. }
  9458. }
  9459. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9460. {
  9461. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9462. {
  9463. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9464. }
  9465. else
  9466. {
  9467. tempIndex = connectorIdInt -1;
  9468. }
  9469. for (int index = 0; index < CCS_QUANTITY; index++)
  9470. {
  9471. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9472. {
  9473. //stop Transaction
  9474. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9475. }
  9476. }
  9477. }
  9478. else if(gunType[connectorIdInt-1] == 'G')
  9479. {
  9480. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9481. {
  9482. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9483. }
  9484. else
  9485. {
  9486. tempIndex = connectorIdInt -1;
  9487. }
  9488. for (int index = 0; index < GB_QUANTITY; index++)
  9489. {
  9490. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9491. {
  9492. //stop Transaction
  9493. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9494. }
  9495. }
  9496. }
  9497. else
  9498. {
  9499. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9500. {
  9501. tempIndex = 2;
  9502. }
  9503. else
  9504. {
  9505. tempIndex = connectorIdInt-1;
  9506. }
  9507. for (int index = 0; index < AC_QUANTITY; index++)
  9508. {
  9509. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9510. {
  9511. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9512. }
  9513. }
  9514. }
  9515. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9516. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9517. result = TRUE;
  9518. return result;
  9519. }
  9520. end:
  9521. //json_object_put(obj); --- remove temporally
  9522. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9523. return result;
  9524. }
  9525. static char UpdateFirmwarepayloadData[300]={0};
  9526. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9527. {
  9528. mtrace();
  9529. int result = FAIL;
  9530. pthread_t t;
  9531. sendUpdateFirmwareConfirmation(uuid);
  9532. memset(UpdateFirmwarepayloadData, 0, 300);
  9533. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9534. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9535. ////pthread_join(t, NULL); //
  9536. //pthread_detach(t);
  9537. //sendUpdateFirmwareConfirmation(uuid);
  9538. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9539. return result;
  9540. }
  9541. void *UpdateFirmwareProcess(void *data)
  9542. {
  9543. pthread_detach(pthread_self());
  9544. mtrace();
  9545. int retriesInt =0, retryIntervalInt=0;
  9546. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9547. int port=0;
  9548. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9549. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  9550. //char comfirmstr[20];
  9551. int isSuccess = 0;
  9552. char ftpbuf[200];
  9553. char temp[100];
  9554. char * pch;
  9555. int retriesISNULL=FALSE;
  9556. int retryInterval=FALSE;
  9557. int c = 0;
  9558. //int i = 0;
  9559. char *loc;
  9560. char sstr[300]={ 0 };
  9561. char str[300]={ 0 };
  9562. //char *str = (char*) data; // ? ?頛詨鞈 ?
  9563. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9564. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  9565. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  9566. //***************location **************/
  9567. loc = strstr(str, "location");
  9568. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9569. c = 0;
  9570. while (loc[3+strlen("location")+c] != '\"')
  9571. {
  9572. sstr[c] = loc[3+strlen("location")+c];
  9573. c++;
  9574. }
  9575. sstr[c] = '\0';
  9576. strcpy(locationstr, sstr);
  9577. //***************retries**************/
  9578. c = 0;
  9579. loc = strstr(str, "retries");
  9580. if(loc == NULL)
  9581. {
  9582. retriesISNULL=TRUE;
  9583. }
  9584. else
  9585. {
  9586. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9587. while (loc[strlen("retries")+2+c] != ',')
  9588. {
  9589. sstr[c] = loc[strlen("retries")+2+c];
  9590. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9591. c++;
  9592. }
  9593. sstr[c] = '\0';
  9594. }
  9595. if(retriesISNULL == FALSE)
  9596. {
  9597. retriesInt = atoi(sstr);
  9598. }
  9599. //***************retrieveDate **************/
  9600. loc = strstr(str, "retrieveDate");
  9601. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9602. c = 0;
  9603. while (loc[3+strlen("retrieveDate")+c] != '\"')
  9604. {
  9605. sstr[c] = loc[3+strlen("retrieveDate")+c];
  9606. c++;
  9607. }
  9608. sstr[c] = '\0';
  9609. strcpy(retrieveDatestr, sstr);
  9610. //***************retryInterval **************/
  9611. c = 0;
  9612. loc = strstr(str, "retryInterval");
  9613. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9614. if(loc == NULL)
  9615. {
  9616. retryInterval=TRUE;
  9617. }
  9618. else
  9619. {
  9620. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  9621. {
  9622. sstr[c] = loc[strlen("retryInterval")+2+c];
  9623. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  9624. c++;
  9625. }
  9626. sstr[c] = '\0';
  9627. }
  9628. if(retryInterval==FALSE)
  9629. {
  9630. retryIntervalInt = atoi(sstr);
  9631. }
  9632. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9633. memset(path, 0, ARRAY_SIZE(path));
  9634. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9635. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9636. if(strncmp(locationstr,"http", 4) == 0)
  9637. {
  9638. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  9639. protocol, host, path);
  9640. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9641. // protocol, user, password, host, path);
  9642. sprintf(ftppath,"/%s", path);
  9643. //DEBUG_INFO("protocol =%s\n",protocol);
  9644. //DEBUG_INFO("host =%s\n",host);
  9645. //DEBUG_INFO("path =%s\n",path);
  9646. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9647. int ftppathlen=strlen(ftppath);
  9648. int i=1;
  9649. char filenametemp[50];
  9650. while(i < ftppathlen)
  9651. {
  9652. int len=ftppathlen-i;
  9653. if(ftppath[len]== 47) // '/' ascll code: 47
  9654. {
  9655. DEBUG_INFO("compare '/' all right\n");
  9656. break;
  9657. }
  9658. i=i+1;
  9659. }
  9660. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9661. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9662. filenametemp[i+1] = 0;
  9663. do
  9664. {
  9665. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9666. sleep(retryIntervalInt);
  9667. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9668. if(!isSuccess)
  9669. {
  9670. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9671. }
  9672. else
  9673. {
  9674. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9675. }
  9676. }
  9677. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9678. {
  9679. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9680. memset(temp, 0, ARRAY_SIZE(temp));
  9681. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9682. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9683. int ftppathlen=strlen(ftpbuf);
  9684. int i=1;
  9685. char filenametemp[50];
  9686. while(i < ftppathlen)
  9687. {
  9688. int len=ftppathlen-i;
  9689. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9690. {
  9691. DEBUG_INFO(" compare '/' all right\n");
  9692. break;
  9693. }
  9694. i=i+1;
  9695. }
  9696. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9697. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9698. filenametemp[i+1] = 0;
  9699. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9700. pch=strchr(temp,'@');
  9701. if(pch==NULL)
  9702. {
  9703. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9704. protocol, host, &port, path);
  9705. strcpy(user,"anonymous");
  9706. strcpy(password,"");
  9707. }
  9708. else
  9709. {
  9710. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9711. protocol, user, password, host, &port, path);
  9712. }
  9713. sscanf(host,"%[^/]%s",host1, path1);
  9714. sprintf(ftppath,"%s", path1);
  9715. //DEBUG_INFO("protocol =%s\n",protocol);
  9716. //DEBUG_INFO("user =%s\n",user);
  9717. //DEBUG_INFO("password =%s\n",password);
  9718. //DEBUG_INFO("host1 =%s\n",host1);
  9719. //DEBUG_INFO("port =%d\n",port);
  9720. //DEBUG_INFO("path1 =%s\n",path1);
  9721. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9722. //ftpFile(host, user, password, port, ftppath, fname);
  9723. //download firmware pthred
  9724. if(port == 0)
  9725. {
  9726. port = 21;
  9727. }
  9728. do
  9729. {
  9730. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9731. sleep(retryIntervalInt);
  9732. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9733. if(!isSuccess)
  9734. {
  9735. //BulldogUtil.sleepMs(interval*1000);
  9736. DEBUG_INFO("Update firmware request and download file fail.\n");
  9737. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9738. }
  9739. else
  9740. {
  9741. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9742. }
  9743. }
  9744. else
  9745. {
  9746. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9747. }
  9748. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9749. pthread_exit(NULL);
  9750. }
  9751. //==========================================
  9752. // Handle server response routine
  9753. //==========================================
  9754. void handleAuthorizeResponse(char *payload, int gun_index)
  9755. {
  9756. mtrace();
  9757. char expiryDatestr[30]={0};
  9758. char parentIdTagstr[20]={0};
  9759. char statusstr[20]={0};
  9760. char expiryDatestrtemp[30]={0};
  9761. char parentIdTagstrtemp[20]={0};
  9762. char IdTagstrtemp[20]={0};
  9763. char statusstrtemp[20]={0};
  9764. int expiryDateISNULL=FALSE;
  9765. int parentIdTagISNULL=FALSE;
  9766. char sstr[160]={0};
  9767. char* filename = AuthorizationCache_JSON;
  9768. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9769. char *loc;
  9770. int resultRename=0;
  9771. int responseIdTagInfoAsZero= 0;
  9772. char rmFileCmd[50]={0};
  9773. DEBUG_INFO("handleAuthorizeResponse...\n");
  9774. json_object *Authorize;
  9775. Authorize = json_tokener_parse(payload);
  9776. if(!is_error(Authorize))
  9777. {
  9778. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9779. {
  9780. // Required data
  9781. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9782. // Optional data
  9783. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9784. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9785. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9786. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9787. }
  9788. }
  9789. json_object_put(Authorize);
  9790. if(expiryDateISNULL == FALSE)
  9791. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9792. if(parentIdTagISNULL == FALSE)
  9793. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9794. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9795. //Update idTag information to authorization cache if supproted
  9796. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9797. {
  9798. if((access(filename,F_OK))!=-1)
  9799. {
  9800. printf("AuthorizationCache exist.\n");
  9801. }
  9802. else
  9803. {
  9804. printf("AuthorizationCache not exist\n");
  9805. FILE *log = fopen(filename, "w+");
  9806. if(log == NULL)
  9807. {
  9808. printf("log is NULL\n");
  9809. goto out;
  9810. }
  9811. else
  9812. {
  9813. fclose(log);
  9814. }
  9815. }
  9816. FILE *infile;
  9817. FILE *outfile;
  9818. // open file for writing
  9819. infile = fopen (filename, "r");
  9820. outfile = fopen (tempfile, "w");
  9821. int c;
  9822. c = fgetc(infile);
  9823. //DEBUG_INFO("c:%d\n",c);
  9824. rewind(infile);
  9825. if(c == EOF)
  9826. {
  9827. DEBUG_INFO("Orignal File is NULL\n");
  9828. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9829. {
  9830. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9831. }
  9832. else
  9833. {
  9834. strcpy(expiryDatestrtemp, "");
  9835. }
  9836. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9837. {
  9838. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9839. }
  9840. else
  9841. {
  9842. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9843. }
  9844. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9845. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9846. fclose(infile);
  9847. fclose(outfile);
  9848. sprintf(rmFileCmd,"rm -f %s",filename);
  9849. system(rmFileCmd);
  9850. resultRename = rename(tempfile, filename);
  9851. if(resultRename == 0)
  9852. {
  9853. printf("File renamed successfully");
  9854. }
  9855. else
  9856. {
  9857. printf("Error: unable to rename the file");
  9858. }
  9859. }
  9860. else
  9861. {
  9862. char buf[160]={0};
  9863. while (fgets(buf, ARRAY_SIZE(buf), infile) != NULL)
  9864. {
  9865. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9866. memset(expiryDatestr, 0, ARRAY_SIZE(expiryDatestrtemp));
  9867. memset(parentIdTagstr,0, ARRAY_SIZE(parentIdTagstrtemp));
  9868. memset(statusstr, 0, ARRAY_SIZE(statusstrtemp));
  9869. memset(IdTagstrtemp, 0, ARRAY_SIZE(IdTagstrtemp));
  9870. memset(expiryDatestrtemp, 0, ARRAY_SIZE(expiryDatestrtemp));
  9871. memset(parentIdTagstrtemp, 0, ARRAY_SIZE(parentIdTagstrtemp));
  9872. memset(statusstrtemp, 0, ARRAY_SIZE(statusstrtemp));
  9873. //------------------IdTag-----------------------
  9874. loc = strstr(buf, "idTag");
  9875. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9876. c = 0;
  9877. while (loc[3+strlen("idTag")+c] != '\"')
  9878. {
  9879. sstr[c] = loc[3+strlen("idTag")+c];
  9880. c++;
  9881. }
  9882. sstr[c] = '\0';
  9883. strcpy(IdTagstrtemp,sstr);
  9884. //*********************expiryDate***************/
  9885. loc = strstr(buf, "expiryDate");
  9886. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9887. c = 0;
  9888. while (loc[3+strlen("expiryDate")+c] != '\"')
  9889. {
  9890. sstr[c] = loc[3+strlen("expiryDate")+c];
  9891. c++;
  9892. }
  9893. sstr[c] = '\0';
  9894. strcpy(expiryDatestr,sstr);
  9895. //*********************parentIdTag***************/
  9896. loc = strstr(buf, "parentIdTag");
  9897. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9898. c = 0;
  9899. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9900. {
  9901. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9902. c++;
  9903. }
  9904. sstr[c] = '\0';
  9905. strcpy(parentIdTagstr,sstr);
  9906. //*********************status***************/
  9907. loc = strstr(buf, "status");
  9908. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9909. c = 0;
  9910. while (loc[3+strlen("status")+c] != '\"')
  9911. {
  9912. sstr[c] = loc[3+strlen("status")+c];
  9913. c++;
  9914. }
  9915. sstr[c] = '\0';
  9916. strcpy(statusstr,sstr);
  9917. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9918. {
  9919. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9920. responseIdTagInfoAsZero = 1;
  9921. }
  9922. else
  9923. {
  9924. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9925. }
  9926. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9927. {
  9928. //modify item
  9929. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9930. {
  9931. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9932. }
  9933. else
  9934. {
  9935. strcpy(expiryDatestrtemp, "");
  9936. }
  9937. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9938. {
  9939. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9940. }
  9941. else
  9942. {
  9943. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9944. }
  9945. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9946. }
  9947. else
  9948. {
  9949. //wrie original item
  9950. strcpy(expiryDatestrtemp, expiryDatestr);
  9951. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9952. strcpy(statusstrtemp, statusstr);
  9953. }
  9954. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9955. }
  9956. fclose(infile);
  9957. fclose(outfile);
  9958. sprintf(rmFileCmd,"rm -f %s",filename);
  9959. system(rmFileCmd);
  9960. resultRename = rename(tempfile, filename);
  9961. if(resultRename == 0)
  9962. {
  9963. DEBUG_INFO("File renamed successfully");
  9964. }
  9965. else
  9966. {
  9967. DEBUG_INFO("Error: unable to rename the file");
  9968. }
  9969. }
  9970. }
  9971. out:
  9972. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9973. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9974. authorizeRetryTimes = 0;
  9975. }
  9976. char * strtrimc( char * s )
  9977. {
  9978. char * p1 = s;
  9979. char * p2 = s;
  9980. while(*p1 != '\0')
  9981. {
  9982. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9983. {
  9984. if(*p1 != ',')
  9985. {
  9986. p1 ++;
  9987. }
  9988. else
  9989. {
  9990. break;
  9991. }
  9992. }
  9993. if(*p1 != ',')
  9994. {
  9995. * p2 ++ = *p1 ++;
  9996. //printf("p2=%s\n",p2);
  9997. }
  9998. else
  9999. {
  10000. break;
  10001. }
  10002. }
  10003. *p2 = '\0';
  10004. return (s);
  10005. }
  10006. void handleBootNotificationResponse(char *payload, int gun_index)
  10007. {
  10008. mtrace();
  10009. char statusStr[12]={0};
  10010. char currentTimeStr[30]={0};
  10011. int intervalInt = 0;
  10012. struct tm tp;
  10013. char buf[28]={0};
  10014. char timebuf[50]={0};
  10015. DEBUG_INFO("handleBootNotificationResponse...\n");
  10016. json_object *BootNotification;
  10017. BootNotification = json_tokener_parse(payload);
  10018. if(!is_error(BootNotification))
  10019. {
  10020. // Required data
  10021. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  10022. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  10023. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  10024. }
  10025. json_object_put(BootNotification);
  10026. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10027. BootNotificationInterval = intervalInt;
  10028. HeartBeatWaitTime = intervalInt;
  10029. //write back to ShmOCPP16Data->BootNotification
  10030. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  10031. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10032. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  10033. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  10034. {
  10035. server_sign = TRUE;
  10036. server_pending =FALSE;
  10037. }
  10038. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  10039. {
  10040. server_pending = TRUE;
  10041. }
  10042. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10043. tp.tm_isdst = -1;
  10044. //time_t utc = mktime(&tp);
  10045. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10046. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  10047. sprintf(timebuf,"date -s '%s'",buf);
  10048. system(timebuf);
  10049. srand(time(NULL));
  10050. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  10051. //==============================================
  10052. // RTC sync
  10053. //==============================================
  10054. system("/sbin/hwclock -w --systohc");
  10055. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  10056. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  10057. }
  10058. void handleDataTransferResponse(char *payload, int gun_index)
  10059. {
  10060. char sstr[160]={0};//sstr[200]={ 0 };
  10061. int c = 0;
  10062. char *loc;
  10063. DEBUG_INFO("handleDataTransferResponse ...\n");
  10064. loc = strstr(payload, "status");
  10065. printf("loc=%s\n",loc);
  10066. c = 0;
  10067. while (loc[3+strlen("status")+c] != '\"')
  10068. {
  10069. sstr[c] = loc[3+strlen("status")+c];
  10070. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10071. c++;
  10072. }
  10073. sstr[c] = '\0';
  10074. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  10075. }
  10076. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  10077. {
  10078. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  10079. //struct json_object *obj;
  10080. // obj = json_tokener_parse(payload);
  10081. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  10082. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  10083. //No fields are defined.
  10084. }
  10085. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  10086. {
  10087. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  10088. //struct json_object *obj;
  10089. // obj = json_tokener_parse(payload);
  10090. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  10091. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  10092. //No fields are defined.
  10093. }
  10094. void handleHeartbeatResponse(char *payload, int gun_index)
  10095. {
  10096. mtrace();
  10097. struct tm tp;
  10098. char buf[28]={0};
  10099. char timebuf[50]={0};
  10100. DEBUG_INFO("handleHeartbeatResponse...\n");
  10101. json_object *Heartbeat;
  10102. Heartbeat = json_tokener_parse(payload);
  10103. if(!is_error(Heartbeat))
  10104. {
  10105. // Required data
  10106. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  10107. }
  10108. json_object_put(BootNotification);
  10109. if(FirstHeartBeat == 0)
  10110. {
  10111. FirstHeartBeat = 1;
  10112. DEBUG_INFO("FirstHeartBeat \n");
  10113. }
  10114. HeartBeatWithNOResponse = 0;
  10115. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10116. tp.tm_isdst = -1;
  10117. //time_t utc = mktime(&tp);
  10118. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10119. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  10120. sprintf(timebuf,"date -s '%s'",buf);
  10121. system(timebuf);
  10122. //==============================================
  10123. // RTC sync
  10124. //==============================================
  10125. system("/sbin/hwclock -w --systohc");
  10126. //===============================================
  10127. //Print Out HeartBeat log
  10128. //===============================================
  10129. {
  10130. double diff_t;
  10131. struct tm tp,tp1;
  10132. // BootNotification Receive Time
  10133. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10134. tp.tm_isdst = -1;
  10135. time_t BootNotificationReceiveTime = mktime(&tp);
  10136. //HeartBeat Receive Time
  10137. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  10138. tp1.tm_isdst = -1;
  10139. time_t HeartBeatReceiveTime = mktime(&tp1);
  10140. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  10141. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  10142. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  10143. {
  10144. HeartBeatCountPerHour = (int)diff_t / 3600;
  10145. DEBUG_INFO("handleHeartbeatResponse ...\n");
  10146. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  10147. }
  10148. }
  10149. }
  10150. void handleMeterValuesResponse(char *payload, int gun_index)
  10151. {
  10152. mtrace();
  10153. DEBUG_INFO("handleMeterValuesResponse...\n");
  10154. }
  10155. void handleStartTransactionResponse(char *payload, int gun_index)
  10156. {
  10157. mtrace();
  10158. //int transactionIdInt = 0;
  10159. FILE *outfile;
  10160. char data[100]={0};
  10161. DEBUG_INFO("handleStartTransactionResponse...\n");
  10162. json_object *StartTransaction;
  10163. StartTransaction = json_tokener_parse(payload);
  10164. if(!is_error(StartTransaction))
  10165. {
  10166. // Required data
  10167. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  10168. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  10169. // Optional data
  10170. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  10171. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  10172. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10173. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  10174. }
  10175. json_object_put(StartTransaction);
  10176. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10177. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10178. //-----------Start : write to the Queue TransactionId file -----------------//
  10179. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10180. {}
  10181. else
  10182. {
  10183. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10184. if(log == NULL)
  10185. {
  10186. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10187. return ;
  10188. }
  10189. else
  10190. {
  10191. fclose(log);
  10192. }
  10193. }
  10194. // open file for writing
  10195. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10196. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10197. {
  10198. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10199. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10200. fputs(data, outfile);
  10201. fclose (outfile);
  10202. }
  10203. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10204. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10205. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10206. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10207. }
  10208. void handleStatusNotificationResponse(char *payload, int gun_index)
  10209. {
  10210. mtrace();
  10211. DEBUG_INFO("handleStatusNotificationResponse...\n");
  10212. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10213. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10214. }
  10215. void handleStopTransactionnResponse(char *payload, int gun_index)
  10216. {
  10217. mtrace();
  10218. DEBUG_INFO("handleStopTransactionnResponse...\n");
  10219. json_object *StopTransaction;
  10220. StopTransaction = json_tokener_parse(payload);
  10221. if(!is_error(StopTransaction))
  10222. {
  10223. // Optional data
  10224. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  10225. {
  10226. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  10227. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  10228. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  10229. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10230. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  10231. }
  10232. }
  10233. json_object_put(StopTransaction);
  10234. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10235. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10236. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10237. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10238. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10239. }
  10240. //==========================================
  10241. // Handle Error routine
  10242. //==========================================
  10243. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10244. {
  10245. mtrace();
  10246. #ifdef SystemLogMessage
  10247. DEBUG_INFO("errorCode: %s\n", errorCode);
  10248. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10249. DEBUG_INFO("errorDetails: %s\n", payload);
  10250. #endif
  10251. }
  10252. //===============================================
  10253. // Common routine
  10254. //===============================================
  10255. int initialConfigurationTable(void)
  10256. {
  10257. //clock_t start_t, end_t, total_t;
  10258. FILE *fp;
  10259. FILE *outfile;
  10260. char str[200]={0};
  10261. char sstr[100]={0};
  10262. int c = 0;
  10263. char *loc;
  10264. DEBUG_INFO("initialConfigurationTable...\n");
  10265. //start_t = clock();
  10266. //printf("Starting of the program, start_t = %ld\n", start_t);
  10267. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10268. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10269. {
  10270. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10271. if(outfile == NULL)
  10272. {
  10273. DEBUG_INFO("Error opening file\n");
  10274. return FALSE;
  10275. }
  10276. /*Core Profile*/
  10277. //AllowOfflineTxForUnknownId
  10278. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10281. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10282. //AuthorizationCacheEnabled
  10283. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10284. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10286. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10287. //AuthorizeRemoteTxRequests
  10288. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10291. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10292. //BlinkRepeat
  10293. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10297. //ClockAlignedDataInterval
  10298. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10301. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10302. //ConnectionTimeOut
  10303. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10307. //GetConfigurationMaxKeys
  10308. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10311. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10312. // HeartbeatInterval
  10313. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10316. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10317. // LightIntensity
  10318. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10321. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10322. // LocalAuthorizeOffline
  10323. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10326. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10327. // LocalPreAuthorize
  10328. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10331. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10332. // MaxEnergyOnInvalidId
  10333. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10336. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10337. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10338. // MeterValuesAlignedData
  10339. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10341. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10343. else
  10344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10346. // MeterValuesAlignedDataMaxLength
  10347. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10349. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10351. else
  10352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10353. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10354. // MeterValuesSampledData
  10355. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10357. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10359. else
  10360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10361. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10362. // MeterValuesSampledDataMaxLength
  10363. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10365. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10367. else
  10368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10370. // MeterValueSampleInterval
  10371. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10375. // MinimumStatusDuration
  10376. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10379. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10380. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10381. // NumberOfConnectors
  10382. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10384. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10385. {
  10386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10387. }
  10388. else
  10389. {
  10390. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10391. }
  10392. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10393. // ResetRetries
  10394. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10397. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10398. // ConnectorPhaseRotation
  10399. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10402. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10403. // ConnectorPhaseRotationMaxLength
  10404. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10408. // StopTransactionOnEVSideDisconnect
  10409. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10412. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10413. // StopTransactionOnInvalidId
  10414. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10417. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10418. // StopTxnAlignedData
  10419. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10422. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10423. // StopTxnAlignedDataMaxLength
  10424. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10427. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10428. // StopTxnSampledData
  10429. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10431. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10432. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10433. else
  10434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10435. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10436. // StopTxnSampledDataMaxLength
  10437. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10438. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10439. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10440. {
  10441. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10442. }
  10443. else
  10444. {
  10445. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10446. }
  10447. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10448. // SupportedFeatureProfiles
  10449. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10452. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10453. // SupportedFeatureProfilesMaxLength
  10454. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10456. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10457. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10458. // TransactionMessageAttempts
  10459. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10460. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10461. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10462. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10463. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10464. // TransactionMessageRetryInterval
  10465. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10466. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10467. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10468. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10469. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10470. // UnlockConnectorOnEVSideDisconnect
  10471. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10474. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10475. // WebSocketPingInterval
  10476. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10480. // QueueOffLineStartTransactionMessage
  10481. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10484. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10485. //* Local Auth List Management Profile*/
  10486. #if 0
  10487. //For OCTT Test Case
  10488. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10491. #endif
  10492. #if 1
  10493. //LocalAuthListEnabled
  10494. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10495. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10497. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10498. #endif
  10499. //LocalAuthListMaxLength
  10500. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10503. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10504. //SendLocalListMaxLength
  10505. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10506. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10508. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10509. //ReserveConnectorZeroSupported
  10510. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10513. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10514. //* Smart Charging Profile */
  10515. //ChargeProfileMaxStackLevel
  10516. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10519. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10520. // ChargingScheduleAllowedChargingRateUnit
  10521. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10523. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10524. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10525. // ChargingScheduleMaxPeriods
  10526. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10529. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10530. // ConnectorSwitch3to1PhaseSupported
  10531. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10534. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10535. // MaxChargingProfilesInstalled
  10536. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10538. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10539. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10540. fclose(outfile);
  10541. }
  10542. else
  10543. {
  10544. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10545. char keystr[60]={0};
  10546. char readonlystr[10]={0};
  10547. char valuestr[100]={0};
  10548. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10549. if(fp == NULL) {
  10550. DEBUG_INFO("Error opening file");
  10551. return FALSE;
  10552. }
  10553. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10554. {
  10555. //DEBUG_INFO("Get Configuration \n");
  10556. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10557. //*************************key*********************************/
  10558. loc = strstr(str, "key");
  10559. c = 0;
  10560. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10561. while (loc[strlen("key")+3+c] != '\"')
  10562. {
  10563. sstr[c] = loc[strlen("key")+3+c];
  10564. c++;
  10565. }
  10566. sstr[c] = '\0';
  10567. strcpy(keystr,sstr);
  10568. //*************************readonly*********************************/
  10569. loc = strstr(str, "readonly");
  10570. c = 0;
  10571. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10572. while (loc[strlen("readonly")+2+c] != ',')
  10573. {
  10574. sstr[c] = loc[strlen("readonly")+2+c];
  10575. c++;
  10576. }
  10577. sstr[c] = '\0';
  10578. strcpy(readonlystr,sstr);
  10579. //*************************value*********************************/
  10580. loc = strstr(str, "value");
  10581. c = 0;
  10582. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10583. while (loc[strlen("value")+3+c] != '\"')
  10584. {
  10585. sstr[c] = loc[strlen("value")+3+c];
  10586. c++;
  10587. }
  10588. sstr[c] = '\0';
  10589. strcpy(valuestr,sstr);
  10590. // DEBUG_INFO("keystr=%s\n",keystr);
  10591. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10592. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10593. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10594. {
  10595. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10596. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10597. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10598. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10599. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10600. }
  10601. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10602. {
  10603. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10604. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10605. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10606. }
  10607. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10608. {
  10609. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10610. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10611. }
  10612. if(strcmp(keystr, "BlinkRepeat") == 0)
  10613. {
  10614. //Charger.BlinkRepeat = Integer.parseInt(value);
  10615. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10616. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10617. }
  10618. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10619. {
  10620. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10621. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10622. }
  10623. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10624. {
  10625. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10626. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10627. }
  10628. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10629. {
  10630. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10631. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10632. }
  10633. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10634. {
  10635. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10636. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10637. HeartBeatWaitTime = atoi(valuestr);
  10638. }
  10639. if(strcmp(keystr, "LightIntensity") == 0)
  10640. {
  10641. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10642. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10643. }
  10644. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10645. {
  10646. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10647. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10648. }
  10649. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10650. {
  10651. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10652. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10653. }
  10654. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10655. {
  10656. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10657. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10658. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10659. }
  10660. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10661. {
  10662. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10663. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10664. }
  10665. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10666. {
  10667. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10668. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10669. }
  10670. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10671. {
  10672. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10673. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10674. }
  10675. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10676. {
  10677. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10678. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10679. }
  10680. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10681. {
  10682. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10683. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10684. }
  10685. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10686. {
  10687. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10688. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10689. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10690. }
  10691. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10692. {
  10693. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10694. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10695. }
  10696. if(strcmp(keystr, "ResetRetries") == 0)
  10697. {
  10698. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10699. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10700. }
  10701. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10702. {
  10703. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10704. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10705. }
  10706. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10707. {
  10708. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10709. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10710. }
  10711. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10712. {
  10713. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10714. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10715. }
  10716. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10717. {
  10718. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10719. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10720. }
  10721. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10722. {
  10723. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10724. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10725. }
  10726. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10727. {
  10728. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10729. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10730. }
  10731. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10732. {
  10733. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10734. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10735. }
  10736. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10737. {
  10738. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10739. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10740. }
  10741. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10742. {
  10743. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10744. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10745. }
  10746. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10747. {
  10748. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10749. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10750. }
  10751. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10752. {
  10753. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10754. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10755. TransactionMessageAttemptsValue = atoi(valuestr);
  10756. }
  10757. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10758. {
  10759. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10760. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10761. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10762. }
  10763. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10764. {
  10765. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10766. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10767. }
  10768. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10769. {
  10770. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10771. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10772. }
  10773. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10774. {
  10775. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10776. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10777. }
  10778. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10779. {
  10780. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10781. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10782. }
  10783. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10784. {
  10785. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10786. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10787. }
  10788. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10789. {
  10790. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10791. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10792. }
  10793. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10794. {
  10795. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10796. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10797. }
  10798. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10799. {
  10800. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10801. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10802. }
  10803. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10804. {
  10805. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10806. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10807. }
  10808. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10809. {
  10810. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10811. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10812. }
  10813. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10814. {
  10815. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10816. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10817. }
  10818. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10819. {
  10820. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10821. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10822. }
  10823. }
  10824. fclose(fp);
  10825. }
  10826. return 0;
  10827. }
  10828. void StoreConfigurationTable(void)
  10829. {
  10830. FILE *outfile;
  10831. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10832. if(outfile == NULL)
  10833. {
  10834. DEBUG_INFO("Error opening file");
  10835. return ;
  10836. }
  10837. /*Core Profile*/
  10838. //AllowOfflineTxForUnknownId
  10839. /*
  10840. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10841. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10844. */
  10845. //DEBUG_INFO("data=%s\n",data);
  10846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10847. //AuthorizationCacheEnabled
  10848. /*
  10849. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10852. */
  10853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10854. //AuthorizeRemoteTxRequests
  10855. /*
  10856. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10859. */
  10860. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10861. //BlinkRepeat
  10862. /*
  10863. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10866. */
  10867. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10868. //ClockAlignedDataInterval
  10869. /*
  10870. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10873. */
  10874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10875. //ConnectionTimeOut
  10876. /*
  10877. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10880. */
  10881. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10882. //GetConfigurationMaxKeys
  10883. /*
  10884. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10885. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10887. */
  10888. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10889. // HeartbeatInterval
  10890. /*
  10891. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10894. */
  10895. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10896. // LightIntensity
  10897. /*
  10898. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10901. */
  10902. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10903. // LocalAuthorizeOffline
  10904. /*
  10905. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10908. */
  10909. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10910. // LocalPreAuthorize
  10911. /*
  10912. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10915. */
  10916. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10917. // MaxEnergyOnInvalidId
  10918. /*
  10919. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10922. */
  10923. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10924. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10925. // MeterValuesAlignedData
  10926. /*
  10927. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10928. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10930. */
  10931. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10932. // MeterValuesAlignedDataMaxLength
  10933. /*
  10934. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10937. */
  10938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10939. // MeterValuesSampledData
  10940. /*
  10941. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10944. */
  10945. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10946. // MeterValuesSampledDataMaxLength
  10947. /*
  10948. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10949. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10951. */
  10952. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10953. // MeterValueSampleInterval
  10954. /*
  10955. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10958. */
  10959. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10960. // MinimumStatusDuration
  10961. /*
  10962. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10965. */
  10966. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10967. // NumberOfConnectors
  10968. /*
  10969. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10970. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10971. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10972. {
  10973. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10974. }
  10975. else
  10976. {
  10977. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10978. }
  10979. */
  10980. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10981. // ResetRetries
  10982. /*
  10983. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10986. */
  10987. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10988. // ConnectorPhaseRotation
  10989. /*
  10990. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10993. */
  10994. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10995. // ConnectorPhaseRotationMaxLength
  10996. /*
  10997. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11000. */
  11001. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11002. // StopTransactionOnEVSideDisconnect
  11003. /*
  11004. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11007. */
  11008. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11009. // StopTransactionOnInvalidId
  11010. /*
  11011. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  11012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11014. */
  11015. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11016. // StopTxnAlignedData
  11017. /*
  11018. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  11019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11021. */
  11022. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11023. // StopTxnAlignedDataMaxLength
  11024. /*
  11025. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11028. */
  11029. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11030. // StopTxnSampledData
  11031. /*
  11032. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  11035. */
  11036. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11037. // StopTxnSampledDataMaxLength
  11038. /*
  11039. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  11042. */
  11043. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11044. // SupportedFeatureProfiles
  11045. /*
  11046. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11049. */
  11050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11051. // SupportedFeatureProfilesMaxLength
  11052. /*
  11053. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11056. */
  11057. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11058. // TransactionMessageAttempts
  11059. /*
  11060. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11063. */
  11064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11065. // TransactionMessageRetryInterval
  11066. /*
  11067. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11070. */
  11071. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11072. // UnlockConnectorOnEVSideDisconnect
  11073. /*
  11074. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11077. */
  11078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11079. // WebSocketPingInterval
  11080. /*
  11081. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11084. */
  11085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11086. // QueueOffLineStartTransactionMessage
  11087. /*
  11088. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  11089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11091. */
  11092. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11093. //* Local Auth List Management Profile*/
  11094. //LocalAuthListEnabled
  11095. /*
  11096. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11099. */
  11100. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11101. //LocalAuthListMaxLength
  11102. /*
  11103. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11106. */
  11107. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11108. //SendLocalListMaxLength
  11109. /*
  11110. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  11113. */
  11114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11115. //ReserveConnectorZeroSupported
  11116. /*
  11117. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11120. */
  11121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11122. //* Smart Charging Profile */
  11123. //ChargeProfileMaxStackLevel
  11124. /*
  11125. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11128. */
  11129. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11130. // ChargingScheduleAllowedChargingRateUnit
  11131. /*
  11132. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11135. */
  11136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11137. // ChargingScheduleMaxPeriods
  11138. /*
  11139. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11142. */
  11143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11144. // ConnectorSwitch3to1PhaseSupported
  11145. /*
  11146. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11149. */
  11150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11151. // MaxChargingProfilesInstalled
  11152. /*
  11153. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  11156. */
  11157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11158. fclose(outfile);
  11159. }
  11160. void getKeyValue(char *keyReq)
  11161. {
  11162. int isEmpty = FALSE;
  11163. int isKnowKey = FALSE;
  11164. DEBUG_INFO("keyReq = %s\n", keyReq);
  11165. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11166. isEmpty = TRUE;
  11167. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11168. {
  11169. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11171. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11172. {
  11173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11174. }
  11175. else
  11176. {
  11177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11178. }
  11179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11180. isKnowKey = TRUE;
  11181. }
  11182. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11183. {
  11184. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11186. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11187. {
  11188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11189. }
  11190. else
  11191. {
  11192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11193. }
  11194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11195. isKnowKey = TRUE;
  11196. }
  11197. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11198. {
  11199. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11201. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11202. {
  11203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11204. }
  11205. else
  11206. {
  11207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11208. }
  11209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11210. isKnowKey = TRUE;
  11211. }
  11212. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11213. {
  11214. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11216. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11217. {
  11218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11219. }
  11220. else
  11221. {
  11222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11223. }
  11224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11225. isKnowKey = TRUE;
  11226. }
  11227. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11228. {
  11229. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11231. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11232. {
  11233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11234. }
  11235. else
  11236. {
  11237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11238. }
  11239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11240. isKnowKey = TRUE;
  11241. }
  11242. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11243. {
  11244. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11246. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11247. {
  11248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11249. }
  11250. else
  11251. {
  11252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11253. }
  11254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11255. isKnowKey = TRUE;
  11256. }
  11257. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11258. {
  11259. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11261. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11262. {
  11263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11264. }
  11265. else
  11266. {
  11267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11268. }
  11269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11270. isKnowKey = TRUE;
  11271. }
  11272. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11273. {
  11274. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11276. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11277. {
  11278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11279. }
  11280. else
  11281. {
  11282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11283. }
  11284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11285. isKnowKey = TRUE;
  11286. }
  11287. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11288. {
  11289. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11291. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11292. {
  11293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11294. }
  11295. else
  11296. {
  11297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11298. }
  11299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11300. isKnowKey = TRUE;
  11301. }
  11302. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11303. {
  11304. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11306. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11307. {
  11308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11309. }
  11310. else
  11311. {
  11312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11313. }
  11314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11315. isKnowKey = TRUE;
  11316. }
  11317. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11318. {
  11319. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11321. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11322. {
  11323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11324. }
  11325. else
  11326. {
  11327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11328. }
  11329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11330. isKnowKey = TRUE;
  11331. }
  11332. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11333. {
  11334. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11336. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11337. {
  11338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11339. }
  11340. else
  11341. {
  11342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11343. }
  11344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11345. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11346. isKnowKey = TRUE;
  11347. }
  11348. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11349. {
  11350. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11352. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11353. {
  11354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11355. }
  11356. else
  11357. {
  11358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11359. }
  11360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11361. isKnowKey = TRUE;
  11362. }
  11363. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11364. {
  11365. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11367. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11368. {
  11369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11370. }
  11371. else
  11372. {
  11373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11374. }
  11375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11376. isKnowKey = TRUE;
  11377. }
  11378. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11379. {
  11380. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11382. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11383. {
  11384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11385. }
  11386. else
  11387. {
  11388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11389. }
  11390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11391. isKnowKey = TRUE;
  11392. }
  11393. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11394. {
  11395. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11397. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11398. {
  11399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11400. }
  11401. else
  11402. {
  11403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11404. }
  11405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11406. isKnowKey = TRUE;
  11407. }
  11408. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11409. {
  11410. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11412. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11413. {
  11414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11415. }
  11416. else
  11417. {
  11418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11419. }
  11420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11421. isKnowKey = TRUE;
  11422. }
  11423. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11424. {
  11425. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11427. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11428. {
  11429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11430. }
  11431. else
  11432. {
  11433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11434. }
  11435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11436. isKnowKey = TRUE;
  11437. }
  11438. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11439. {
  11440. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11442. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11443. {
  11444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11445. }
  11446. else
  11447. {
  11448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11449. }
  11450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11451. isKnowKey = TRUE;
  11452. }
  11453. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11454. {
  11455. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11457. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11458. {
  11459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11460. }
  11461. else
  11462. {
  11463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11464. }
  11465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11466. isKnowKey = TRUE;
  11467. }
  11468. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11469. {
  11470. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11472. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11473. {
  11474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11475. }
  11476. else
  11477. {
  11478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11479. }
  11480. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11481. isKnowKey = TRUE;
  11482. }
  11483. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11484. {
  11485. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11487. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11488. {
  11489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11490. }
  11491. else
  11492. {
  11493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11494. }
  11495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11496. isKnowKey = TRUE;
  11497. }
  11498. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11499. {
  11500. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11502. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11503. {
  11504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11505. }
  11506. else
  11507. {
  11508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11509. }
  11510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11511. isKnowKey = TRUE;
  11512. }
  11513. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11514. {
  11515. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11517. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11518. {
  11519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11520. }
  11521. else
  11522. {
  11523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11524. }
  11525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11526. isKnowKey = TRUE;
  11527. }
  11528. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11529. {
  11530. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11532. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11533. {
  11534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11535. }
  11536. else
  11537. {
  11538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11539. }
  11540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11541. isKnowKey = TRUE;
  11542. }
  11543. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11544. {
  11545. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11547. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11548. {
  11549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11550. }
  11551. else
  11552. {
  11553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11554. }
  11555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11556. isKnowKey = TRUE;
  11557. }
  11558. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11559. {
  11560. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11562. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11563. {
  11564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11565. }
  11566. else
  11567. {
  11568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11569. }
  11570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11571. isKnowKey = TRUE;
  11572. }
  11573. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11574. {
  11575. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11577. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11578. {
  11579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11580. }
  11581. else
  11582. {
  11583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11584. }
  11585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11586. isKnowKey = TRUE;
  11587. }
  11588. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11589. {
  11590. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11592. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11593. {
  11594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11595. }
  11596. else
  11597. {
  11598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11599. }
  11600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11601. isKnowKey = TRUE;
  11602. }
  11603. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11604. {
  11605. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11607. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11608. {
  11609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11610. }
  11611. else
  11612. {
  11613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11614. }
  11615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11616. isKnowKey = TRUE;
  11617. }
  11618. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11619. {
  11620. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11622. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11623. {
  11624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11625. }
  11626. else
  11627. {
  11628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11629. }
  11630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11631. isKnowKey = TRUE;
  11632. }
  11633. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11634. {
  11635. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11637. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11638. {
  11639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11640. }
  11641. else
  11642. {
  11643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11644. }
  11645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11646. isKnowKey = TRUE;
  11647. }
  11648. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11649. {
  11650. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11652. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11653. {
  11654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11655. }
  11656. else
  11657. {
  11658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11659. }
  11660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11661. isKnowKey = TRUE;
  11662. }
  11663. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11664. {
  11665. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11667. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11668. {
  11669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11670. }
  11671. else
  11672. {
  11673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11674. }
  11675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11676. isKnowKey = TRUE;
  11677. }
  11678. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11679. {
  11680. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11681. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11682. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11683. {
  11684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11685. }
  11686. else
  11687. {
  11688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11689. }
  11690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11691. isKnowKey = TRUE;
  11692. }
  11693. #if 1
  11694. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11695. {
  11696. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11698. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11699. {
  11700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11701. }
  11702. else
  11703. {
  11704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11705. }
  11706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11707. isKnowKey = TRUE;
  11708. }
  11709. #endif
  11710. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11711. {
  11712. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11714. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11715. {
  11716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11717. }
  11718. else
  11719. {
  11720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11721. }
  11722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11723. isKnowKey = TRUE;
  11724. }
  11725. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11726. {
  11727. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11729. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11730. {
  11731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11732. }
  11733. else
  11734. {
  11735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11736. }
  11737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11738. isKnowKey = TRUE;
  11739. }
  11740. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11741. {
  11742. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11744. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11745. {
  11746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11747. }
  11748. else
  11749. {
  11750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11751. }
  11752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11753. isKnowKey = TRUE;
  11754. }
  11755. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11756. {
  11757. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11759. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11760. {
  11761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11762. }
  11763. else
  11764. {
  11765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11766. }
  11767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11768. isKnowKey = TRUE;
  11769. }
  11770. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11771. {
  11772. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11774. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11775. {
  11776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11777. }
  11778. else
  11779. {
  11780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11781. }
  11782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11783. isKnowKey = TRUE;
  11784. }
  11785. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11786. {
  11787. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11789. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11790. {
  11791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11792. }
  11793. else
  11794. {
  11795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11796. }
  11797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11798. isKnowKey = TRUE;
  11799. }
  11800. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11801. {
  11802. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11804. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11805. {
  11806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11807. }
  11808. else
  11809. {
  11810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11811. }
  11812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11813. isKnowKey = TRUE;
  11814. }
  11815. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11816. {
  11817. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11819. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11820. {
  11821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11822. }
  11823. else
  11824. {
  11825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11826. }
  11827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11828. isKnowKey = TRUE;
  11829. }
  11830. //=========================================================
  11831. if(!isEmpty && !isKnowKey)
  11832. {
  11833. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11834. strcpy(unknownkey[UnknownKeynum], keyReq);
  11835. UnknownKeynum = UnknownKeynum + 1;
  11836. }
  11837. }
  11838. void processUnkownKey(void)
  11839. {
  11840. DEBUG_INFO("processUnkownKey...\n");
  11841. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11842. for(int index=0; index < UnknownKeynum; index++)
  11843. {
  11844. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11845. {
  11846. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11847. }
  11848. }
  11849. }
  11850. int setKeyValue(char *key, char *value)
  11851. {
  11852. int isSuccess = NotSupported;
  11853. int check_ascii=0;
  11854. char str[10]={0};
  11855. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11856. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11857. {
  11858. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11859. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11860. {
  11861. strcpy(str, (const char*)value);
  11862. for(int i = 0; str[i]; i++){
  11863. str[i] = tolower(str[i]);
  11864. }
  11865. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11866. isSuccess = ConfigurationStatus_Accepted;
  11867. }
  11868. else
  11869. {
  11870. isSuccess = ConfigurationStatus_Rejected;
  11871. }
  11872. }
  11873. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11874. {
  11875. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11876. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11877. {
  11878. strcpy(str, (const char*)value);
  11879. for(int i = 0; str[i]; i++){
  11880. str[i] = tolower(str[i]);
  11881. }
  11882. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11883. isSuccess = ConfigurationStatus_Accepted;
  11884. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11885. }
  11886. else
  11887. {
  11888. isSuccess = ConfigurationStatus_Rejected;
  11889. }
  11890. }
  11891. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11892. {
  11893. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11894. {
  11895. strcpy(str, (const char*)value);
  11896. for(int i = 0; str[i]; i++)
  11897. {
  11898. str[i] = tolower(str[i]);
  11899. }
  11900. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11901. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].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, "BlinkRepeat") == 0)
  11910. {
  11911. //Charger.BlinkRepeat = Integer.parseInt(value);
  11912. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11913. {
  11914. check_ascii = value[0];
  11915. if( (check_ascii < 48) || (check_ascii > 57) )
  11916. {
  11917. isSuccess = ConfigurationStatus_Rejected;
  11918. }
  11919. else
  11920. {
  11921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11922. isSuccess = ConfigurationStatus_Accepted;
  11923. }
  11924. }
  11925. else
  11926. {
  11927. isSuccess = ConfigurationStatus_Rejected;
  11928. }
  11929. }
  11930. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11931. {
  11932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11933. {
  11934. check_ascii = value[0];
  11935. if( (check_ascii < 48) || (check_ascii > 57) )
  11936. {
  11937. isSuccess = ConfigurationStatus_Rejected;
  11938. }
  11939. else
  11940. {
  11941. if((atoi(value) == 0) || (atoi(value) >= 10))
  11942. {
  11943. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11944. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11945. isSuccess = ConfigurationStatus_Accepted;
  11946. }
  11947. else
  11948. isSuccess = ConfigurationStatus_Rejected;
  11949. }
  11950. }
  11951. else
  11952. {
  11953. isSuccess = ConfigurationStatus_Rejected;
  11954. }
  11955. }
  11956. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11957. {
  11958. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11959. {
  11960. check_ascii = value[0];
  11961. if( (check_ascii < 48) || (check_ascii > 57) )
  11962. {
  11963. isSuccess = ConfigurationStatus_Rejected;
  11964. }
  11965. else
  11966. {
  11967. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11969. isSuccess = ConfigurationStatus_Accepted;
  11970. }
  11971. }
  11972. else
  11973. {
  11974. isSuccess = ConfigurationStatus_Rejected;
  11975. }
  11976. }
  11977. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11978. {
  11979. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11980. {
  11981. check_ascii = value[0];
  11982. if( (check_ascii < 48) || (check_ascii > 57) )
  11983. {
  11984. isSuccess = ConfigurationStatus_Rejected;
  11985. }
  11986. else
  11987. {
  11988. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11989. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11990. isSuccess = ConfigurationStatus_Accepted;
  11991. }
  11992. }
  11993. else
  11994. {
  11995. isSuccess = ConfigurationStatus_Rejected;
  11996. }
  11997. }
  11998. if(strcmp(key, "HeartbeatInterval") == 0)
  11999. {
  12000. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12001. {
  12002. check_ascii = value[0];
  12003. if( (check_ascii < 48) || (check_ascii > 57) )
  12004. {
  12005. isSuccess = ConfigurationStatus_Rejected;
  12006. }
  12007. else
  12008. {
  12009. if((atoi(value) == 0) || (atoi(value) >= 10))
  12010. {
  12011. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  12013. HeartBeatWaitTime = atoi(value);
  12014. isSuccess = ConfigurationStatus_Accepted;
  12015. }
  12016. else
  12017. {
  12018. isSuccess = ConfigurationStatus_Rejected;
  12019. }
  12020. }
  12021. }
  12022. else
  12023. {
  12024. isSuccess = ConfigurationStatus_Rejected;
  12025. }
  12026. }
  12027. if(strcmp(key, "LightIntensity") == 0)
  12028. {
  12029. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12030. {
  12031. check_ascii = value[0];
  12032. if( (check_ascii < 48) || (check_ascii > 57) )
  12033. {
  12034. isSuccess = ConfigurationStatus_Rejected;
  12035. }
  12036. else
  12037. {
  12038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  12039. isSuccess = ConfigurationStatus_Accepted;
  12040. }
  12041. }
  12042. else
  12043. {
  12044. isSuccess = ConfigurationStatus_Rejected;
  12045. }
  12046. }
  12047. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  12048. {
  12049. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12050. {
  12051. strcpy(str, (const char*)value);
  12052. for(int i = 0; str[i]; i++)
  12053. {
  12054. str[i] = tolower(str[i]);
  12055. }
  12056. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12057. isSuccess = ConfigurationStatus_Accepted;
  12058. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12059. }
  12060. else
  12061. {
  12062. isSuccess = ConfigurationStatus_Rejected;
  12063. }
  12064. }
  12065. if(strcmp(key, "LocalPreAuthorize") == 0)
  12066. {
  12067. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12068. {
  12069. strcpy(str, (const char*)value);
  12070. for(int i = 0; str[i]; i++)
  12071. {
  12072. str[i] = tolower(str[i]);
  12073. }
  12074. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12075. isSuccess = ConfigurationStatus_Accepted;
  12076. }
  12077. else
  12078. {
  12079. isSuccess = ConfigurationStatus_Rejected;
  12080. }
  12081. }
  12082. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  12083. {
  12084. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12085. {
  12086. check_ascii = value[0];
  12087. if( (check_ascii < 48) || (check_ascii > 57) )
  12088. {
  12089. isSuccess = ConfigurationStatus_Rejected;
  12090. }
  12091. else
  12092. {
  12093. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  12094. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  12095. isSuccess = ConfigurationStatus_Accepted;
  12096. }
  12097. }
  12098. else
  12099. {
  12100. isSuccess = ConfigurationStatus_Rejected;
  12101. }
  12102. }
  12103. if(strcmp(key, "MeterValuesAlignedData") == 0)
  12104. {
  12105. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12106. {
  12107. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  12108. isSuccess = ConfigurationStatus_Accepted;
  12109. }
  12110. else
  12111. {
  12112. isSuccess = ConfigurationStatus_Rejected;
  12113. }
  12114. }
  12115. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  12116. {
  12117. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12118. {
  12119. check_ascii = value[0];
  12120. if( (check_ascii < 48) || (check_ascii > 57) )
  12121. {
  12122. isSuccess = ConfigurationStatus_Rejected;
  12123. }
  12124. else
  12125. {
  12126. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12127. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  12128. isSuccess = ConfigurationStatus_Accepted;
  12129. }
  12130. }
  12131. else
  12132. {
  12133. isSuccess = ConfigurationStatus_Rejected;
  12134. }
  12135. }
  12136. if(strcmp(key, "MeterValuesSampledData") == 0 )
  12137. {
  12138. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12139. {
  12140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  12141. isSuccess = ConfigurationStatus_Accepted;
  12142. }
  12143. else
  12144. {
  12145. isSuccess = ConfigurationStatus_Rejected;
  12146. }
  12147. }
  12148. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  12149. {
  12150. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12151. {
  12152. check_ascii = value[0];
  12153. if( (check_ascii < 48) || (check_ascii > 57) )
  12154. {
  12155. isSuccess = ConfigurationStatus_Rejected;
  12156. }
  12157. else
  12158. {
  12159. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12160. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12161. isSuccess = ConfigurationStatus_Accepted;
  12162. }
  12163. }
  12164. else
  12165. {
  12166. isSuccess = ConfigurationStatus_Rejected;
  12167. }
  12168. }
  12169. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12170. {
  12171. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12172. {
  12173. check_ascii = value[0];
  12174. if( (check_ascii < 48) || (check_ascii > 57) )
  12175. {
  12176. isSuccess = ConfigurationStatus_Rejected;
  12177. }
  12178. else
  12179. {
  12180. if((atoi(value) == 0) || (atoi(value) >= 10))
  12181. {
  12182. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12183. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12184. isSuccess = ConfigurationStatus_Accepted;
  12185. }
  12186. else
  12187. {
  12188. isSuccess = ConfigurationStatus_Rejected;
  12189. }
  12190. }
  12191. }
  12192. else
  12193. {
  12194. isSuccess = ConfigurationStatus_Rejected;
  12195. }
  12196. }
  12197. if(strcmp(key, "MinimumStatusDuration") == 0)
  12198. {
  12199. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12200. {
  12201. check_ascii = value[0];
  12202. if( (check_ascii < 48) || (check_ascii > 57) )
  12203. {
  12204. isSuccess = ConfigurationStatus_Rejected;
  12205. }
  12206. else
  12207. {
  12208. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12209. {
  12210. isSuccess = ConfigurationStatus_Rejected;
  12211. }
  12212. else
  12213. {
  12214. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12215. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12216. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12217. isSuccess = ConfigurationStatus_Accepted;
  12218. }
  12219. }
  12220. }
  12221. else
  12222. {
  12223. isSuccess = ConfigurationStatus_Rejected;
  12224. }
  12225. }
  12226. if(strcmp(key, "NumberOfConnectors") == 0)
  12227. {
  12228. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12229. {
  12230. check_ascii = value[0];
  12231. if( (check_ascii < 48) || (check_ascii > 57) )
  12232. {
  12233. isSuccess = ConfigurationStatus_Rejected;
  12234. }
  12235. else
  12236. {
  12237. //Charger.ResetRetries = Integer.parseInt(value);
  12238. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12239. isSuccess = ConfigurationStatus_Accepted;
  12240. }
  12241. }
  12242. else
  12243. {
  12244. isSuccess = ConfigurationStatus_Rejected;
  12245. }
  12246. }
  12247. if(strcmp(key, "ResetRetries") == 0)
  12248. {
  12249. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12250. {
  12251. check_ascii = value[0];
  12252. if( (check_ascii < 48) || (check_ascii > 57) )
  12253. {
  12254. isSuccess = ConfigurationStatus_Rejected;
  12255. }
  12256. else
  12257. {
  12258. //Charger.ResetRetries = Integer.parseInt(value);
  12259. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12260. isSuccess = ConfigurationStatus_Accepted;
  12261. }
  12262. }
  12263. else
  12264. {
  12265. isSuccess = ConfigurationStatus_Rejected;
  12266. }
  12267. }
  12268. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12269. {
  12270. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12271. {
  12272. strcpy(str, (const char*)value);
  12273. for(int i = 0; str[i]; i++)
  12274. {
  12275. str[i] = tolower(str[i]);
  12276. }
  12277. if(strcmp(str, "notapplicable")== 0)
  12278. {
  12279. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12280. isSuccess = ConfigurationStatus_Accepted;
  12281. }
  12282. else if(strcmp(str, "unknown")== 0)
  12283. {
  12284. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12285. isSuccess = ConfigurationStatus_Accepted;
  12286. }
  12287. else if(strcmp(str, "rst")== 0)
  12288. {
  12289. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12290. isSuccess = ConfigurationStatus_Accepted;
  12291. }
  12292. else if(strcmp(str, "rts")== 0)
  12293. {
  12294. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12295. isSuccess = ConfigurationStatus_Accepted;
  12296. }
  12297. else if(strcmp(str, "srt")== 0)
  12298. {
  12299. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12300. isSuccess = ConfigurationStatus_Accepted;
  12301. }
  12302. else if(strcmp(str, "str")== 0)
  12303. {
  12304. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12305. isSuccess = ConfigurationStatus_Accepted;
  12306. }
  12307. else if(strcmp(str, "trs")== 0)
  12308. {
  12309. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12310. isSuccess = ConfigurationStatus_Accepted;
  12311. }
  12312. else if(strcmp(str, "tsr")== 0)
  12313. {
  12314. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12315. isSuccess = ConfigurationStatus_Accepted;
  12316. }
  12317. else
  12318. {
  12319. isSuccess = ConfigurationStatus_Rejected;
  12320. }
  12321. }
  12322. else
  12323. {
  12324. isSuccess = ConfigurationStatus_Rejected;
  12325. }
  12326. }
  12327. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12328. {
  12329. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12330. {
  12331. check_ascii = value[0];
  12332. if( (check_ascii < 48) || (check_ascii > 57) )
  12333. {
  12334. isSuccess = ConfigurationStatus_Rejected;
  12335. }
  12336. else
  12337. {
  12338. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12339. isSuccess = ConfigurationStatus_Accepted;
  12340. }
  12341. }
  12342. else
  12343. {
  12344. isSuccess = ConfigurationStatus_Rejected;
  12345. }
  12346. }
  12347. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12348. {
  12349. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12350. {
  12351. strcpy(str, (const char*)value);
  12352. for(int i = 0; str[i]; i++)
  12353. {
  12354. str[i] = tolower(str[i]);
  12355. }
  12356. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12357. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12358. isSuccess = ConfigurationStatus_Accepted;
  12359. }
  12360. else
  12361. {
  12362. isSuccess = ConfigurationStatus_Rejected;
  12363. }
  12364. }
  12365. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12366. {
  12367. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12368. {
  12369. strcpy(str, (const char*)value);
  12370. for(int i = 0; str[i]; i++)
  12371. {
  12372. str[i] = tolower(str[i]);
  12373. }
  12374. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12375. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12376. isSuccess = ConfigurationStatus_Accepted;
  12377. }
  12378. else
  12379. {
  12380. isSuccess = ConfigurationStatus_Rejected;
  12381. }
  12382. }
  12383. if(strcmp(key, "StopTxnAlignedData") == 0)
  12384. {
  12385. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12386. {
  12387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12388. isSuccess = ConfigurationStatus_Accepted;
  12389. }
  12390. else
  12391. {
  12392. isSuccess = ConfigurationStatus_Rejected;
  12393. }
  12394. }
  12395. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12396. {
  12397. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12398. {
  12399. check_ascii = value[0];
  12400. if( (check_ascii < 48) || (check_ascii > 57) )
  12401. {
  12402. isSuccess = ConfigurationStatus_Rejected;
  12403. }
  12404. else
  12405. {
  12406. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12407. isSuccess = ConfigurationStatus_Accepted;
  12408. }
  12409. }
  12410. else
  12411. {
  12412. isSuccess = ConfigurationStatus_Rejected;
  12413. }
  12414. }
  12415. if(strcmp(key, "StopTxnSampledData") == 0)
  12416. {
  12417. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12418. {
  12419. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12420. isSuccess = ConfigurationStatus_Accepted;
  12421. }
  12422. else
  12423. {
  12424. isSuccess = ConfigurationStatus_Rejected;
  12425. }
  12426. }
  12427. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12428. {
  12429. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12430. {
  12431. check_ascii = value[0];
  12432. if( (check_ascii < 48) || (check_ascii > 57) )
  12433. {
  12434. isSuccess = ConfigurationStatus_Rejected;
  12435. }
  12436. else
  12437. {
  12438. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12439. isSuccess = ConfigurationStatus_Accepted;
  12440. }
  12441. }
  12442. else
  12443. {
  12444. isSuccess = ConfigurationStatus_Rejected;
  12445. }
  12446. }
  12447. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12448. {
  12449. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12450. {
  12451. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12452. isSuccess = ConfigurationStatus_Accepted;
  12453. }
  12454. else
  12455. {
  12456. isSuccess = ConfigurationStatus_Rejected;
  12457. }
  12458. }
  12459. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12460. {
  12461. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12462. {
  12463. check_ascii = value[0];
  12464. if( (check_ascii < 48) || (check_ascii > 57) )
  12465. {
  12466. isSuccess = ConfigurationStatus_Rejected;
  12467. }
  12468. else
  12469. {
  12470. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12471. isSuccess = ConfigurationStatus_Accepted;
  12472. }
  12473. }
  12474. else
  12475. {
  12476. isSuccess = ConfigurationStatus_Rejected;
  12477. }
  12478. }
  12479. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12480. {
  12481. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12482. {
  12483. check_ascii = value[0];
  12484. if( (check_ascii < 48) || (check_ascii > 57) )
  12485. {
  12486. isSuccess = ConfigurationStatus_Rejected;
  12487. }
  12488. else
  12489. {
  12490. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12491. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12492. TransactionMessageAttemptsValue = atoi(value);
  12493. isSuccess = ConfigurationStatus_Accepted;
  12494. }
  12495. }
  12496. else
  12497. {
  12498. isSuccess = ConfigurationStatus_Rejected;
  12499. }
  12500. }
  12501. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12502. {
  12503. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12504. {
  12505. check_ascii = value[0];
  12506. if( (check_ascii < 48) || (check_ascii > 57) )
  12507. {
  12508. isSuccess = ConfigurationStatus_Rejected;
  12509. }
  12510. else
  12511. {
  12512. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12513. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12514. TransactionMessageRetryIntervalValue = atoi(value);
  12515. isSuccess = ConfigurationStatus_Accepted;
  12516. }
  12517. }
  12518. else
  12519. {
  12520. isSuccess = ConfigurationStatus_Rejected;
  12521. }
  12522. }
  12523. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12524. {
  12525. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12526. {
  12527. strcpy(str, (const char*)value);
  12528. for(int i = 0; str[i]; i++)
  12529. {
  12530. str[i] = tolower(str[i]);
  12531. }
  12532. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12533. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12534. isSuccess = ConfigurationStatus_Accepted;
  12535. }
  12536. else
  12537. {
  12538. isSuccess = ConfigurationStatus_Rejected;
  12539. }
  12540. }
  12541. if(strcmp(key, "WebSocketPingInterval") == 0)
  12542. {
  12543. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12544. {
  12545. check_ascii = value[0];
  12546. if( (check_ascii < 48) || (check_ascii > 57) )
  12547. {
  12548. isSuccess = ConfigurationStatus_Rejected;
  12549. }
  12550. else
  12551. {
  12552. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12553. isSuccess = ConfigurationStatus_Accepted;
  12554. }
  12555. }
  12556. else
  12557. {
  12558. isSuccess = ConfigurationStatus_Rejected;
  12559. }
  12560. }
  12561. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12562. {
  12563. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12564. {
  12565. strcpy(str, (const char*)value);
  12566. for(int i = 0; str[i]; i++)
  12567. {
  12568. str[i] = tolower(str[i]);
  12569. }
  12570. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12571. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12572. isSuccess = ConfigurationStatus_Accepted;
  12573. }
  12574. else
  12575. {
  12576. isSuccess = ConfigurationStatus_Rejected;
  12577. }
  12578. }
  12579. #if 0
  12580. //For OCPP Test Case
  12581. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12582. {
  12583. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12584. {
  12585. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12586. isSuccess = ConfigurationStatus_Accepted;
  12587. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12588. }
  12589. else
  12590. {
  12591. isSuccess = ConfigurationStatus_Rejected;
  12592. }
  12593. }
  12594. #endif
  12595. #if 1
  12596. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12597. {
  12598. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12599. {
  12600. strcpy(str, (const char*)value);
  12601. for(int i = 0; str[i]; i++)
  12602. {
  12603. str[i] = tolower(str[i]);
  12604. }
  12605. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12606. isSuccess = ConfigurationStatus_Accepted;
  12607. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12608. }
  12609. else
  12610. {
  12611. isSuccess = ConfigurationStatus_Rejected;
  12612. }
  12613. }
  12614. #endif
  12615. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12616. {
  12617. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12618. {
  12619. check_ascii = value[0];
  12620. if( (check_ascii < 48) || (check_ascii > 57) )
  12621. {
  12622. isSuccess = ConfigurationStatus_Rejected;
  12623. }
  12624. else
  12625. {
  12626. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12627. isSuccess = ConfigurationStatus_Accepted;
  12628. }
  12629. }
  12630. else
  12631. {
  12632. isSuccess = ConfigurationStatus_Rejected;
  12633. }
  12634. }
  12635. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12636. {
  12637. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12638. {
  12639. check_ascii = value[0];
  12640. if( (check_ascii < 48) || (check_ascii > 57) )
  12641. {
  12642. isSuccess = ConfigurationStatus_Rejected;
  12643. }
  12644. else
  12645. {
  12646. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12647. isSuccess = ConfigurationStatus_Accepted;
  12648. }
  12649. }
  12650. else
  12651. {
  12652. isSuccess = ConfigurationStatus_Rejected;
  12653. }
  12654. }
  12655. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12656. {
  12657. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12658. {
  12659. strcpy(str, (const char*)value);
  12660. for(int i = 0; str[i]; i++)
  12661. {
  12662. str[i] = tolower(str[i]);
  12663. }
  12664. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12665. isSuccess = ConfigurationStatus_Accepted;
  12666. }
  12667. else
  12668. {
  12669. isSuccess = ConfigurationStatus_Rejected;
  12670. }
  12671. }
  12672. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12673. {
  12674. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12675. {
  12676. check_ascii = value[0];
  12677. if( (check_ascii < 48) || (check_ascii > 57) )
  12678. {
  12679. isSuccess = ConfigurationStatus_Rejected;
  12680. }
  12681. else
  12682. {
  12683. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12684. isSuccess = ConfigurationStatus_Accepted;
  12685. }
  12686. }
  12687. else
  12688. {
  12689. isSuccess = ConfigurationStatus_Rejected;
  12690. }
  12691. }
  12692. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12693. {
  12694. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12695. {
  12696. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12697. isSuccess = ConfigurationStatus_Accepted;
  12698. }
  12699. else
  12700. {
  12701. isSuccess = ConfigurationStatus_Rejected;
  12702. }
  12703. }
  12704. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12705. {
  12706. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12707. {
  12708. check_ascii = value[0];
  12709. if( (check_ascii < 48) || (check_ascii > 57) )
  12710. {
  12711. isSuccess = ConfigurationStatus_Rejected;
  12712. }
  12713. else
  12714. {
  12715. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12716. isSuccess = ConfigurationStatus_Accepted;
  12717. }
  12718. }
  12719. else
  12720. {
  12721. isSuccess = ConfigurationStatus_Rejected;
  12722. }
  12723. }
  12724. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12725. {
  12726. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12727. {
  12728. strcpy(str, (const char*)value);
  12729. for(int i = 0; str[i]; i++)
  12730. {
  12731. str[i] = tolower(str[i]);
  12732. }
  12733. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12734. isSuccess = ConfigurationStatus_Accepted;
  12735. }
  12736. else
  12737. {
  12738. isSuccess = ConfigurationStatus_Rejected;
  12739. }
  12740. }
  12741. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12742. {
  12743. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12744. {
  12745. check_ascii = value[0];
  12746. if( (check_ascii < 48) || (check_ascii > 57) )
  12747. {
  12748. isSuccess = ConfigurationStatus_Rejected;
  12749. }
  12750. else
  12751. {
  12752. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12753. isSuccess = ConfigurationStatus_Accepted;
  12754. }
  12755. }
  12756. else
  12757. {
  12758. isSuccess = ConfigurationStatus_Rejected;
  12759. }
  12760. }
  12761. return isSuccess;
  12762. }
  12763. int TransactionMessageAttemptsGet(void)
  12764. {
  12765. return TransactionMessageAttemptsValue;
  12766. }
  12767. int FirstHeartBeatResponse(void)
  12768. {
  12769. return FirstHeartBeat;
  12770. }
  12771. int TransactionMessageRetryIntervalGet(void)
  12772. {
  12773. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12774. }
  12775. int ReadHttpStatus(int sock)
  12776. {
  12777. //char c;
  12778. char buff[1024]="",*ptr=buff+1;
  12779. int bytes_received, status;
  12780. DEBUG_INFO("Begin Response ..\n");
  12781. while((bytes_received = recv(sock, ptr, 1, 0))){
  12782. if(bytes_received==-1){
  12783. perror("ReadHttpStatus");
  12784. exit(1);
  12785. }
  12786. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12787. ptr++;
  12788. }
  12789. *ptr=0;
  12790. ptr=buff+1;
  12791. sscanf(ptr,"%*s %d ", &status);
  12792. DEBUG_INFO("%s\n",ptr);
  12793. DEBUG_INFO("status=%d\n",status);
  12794. DEBUG_INFO("End Response ..\n");
  12795. return (bytes_received>0)?status:0;
  12796. }
  12797. //the only filed that it parsed is 'Content-Length'
  12798. int ParseHeader(int sock)
  12799. {
  12800. //char c;
  12801. char buff[1024]="",*ptr=buff+4;
  12802. int bytes_received;
  12803. DEBUG_INFO("Begin HEADER ..\n");
  12804. while((bytes_received = recv(sock, ptr, 1, 0))){
  12805. if(bytes_received==-1){
  12806. perror("Parse Header");
  12807. exit(1);
  12808. }
  12809. if(
  12810. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12811. (ptr[-1]=='\r') && (*ptr=='\n' )
  12812. ) break;
  12813. ptr++;
  12814. }
  12815. *ptr=0;
  12816. ptr=buff+4;
  12817. //printf("%s",ptr);
  12818. if(bytes_received){
  12819. ptr=strstr(ptr,"Content-Length:");
  12820. if(ptr){
  12821. sscanf(ptr,"%*s %d",&bytes_received);
  12822. }else
  12823. bytes_received=-1; //unknown size
  12824. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12825. }
  12826. DEBUG_INFO("End HEADER ..\n");
  12827. return bytes_received ;
  12828. }
  12829. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12830. {
  12831. char rmFileCmd[100]={0};
  12832. char FilePath[100]={0};
  12833. char ftpbuf[200];
  12834. int systemresult;
  12835. //DEBUG_INFO("filename=%s\n",filename);
  12836. //DEBUG_INFO("url=%s\n",url);
  12837. sprintf(FilePath,"/mnt/%s",filename);
  12838. if((access(FilePath,F_OK))!=-1)
  12839. {
  12840. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12841. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12842. system(rmFileCmd);
  12843. }
  12844. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12845. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12846. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12847. systemresult = system(ftpbuf);
  12848. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12849. if(systemresult != 0)
  12850. {
  12851. DEBUG_INFO("http DownLoad error!\n");
  12852. return FALSE;
  12853. }
  12854. return TRUE;
  12855. }
  12856. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12857. {
  12858. char rmFileCmd[100]={0};
  12859. char FilePath[100]={0};
  12860. char ftpbuf[200];
  12861. int systemresult;
  12862. //char temp[100];
  12863. sprintf(FilePath,"/mnt/%s",filename);
  12864. if((access(FilePath,F_OK))!=-1)
  12865. {
  12866. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12867. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12868. system(rmFileCmd);
  12869. }
  12870. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12871. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12872. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12873. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12874. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12875. systemresult = system(ftpbuf);
  12876. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12877. if(systemresult != 0)
  12878. {
  12879. printf("wget error!\n");
  12880. return FALSE;
  12881. }
  12882. return TRUE;
  12883. }
  12884. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12885. {
  12886. char rmFileCmd[100]={0};
  12887. char FilePath[100]={0};
  12888. char ftpbuf[200];
  12889. int systemresult;
  12890. //DEBUG_INFO("filename=%s\n",filename);
  12891. //DEBUG_INFO("url=%s\n",url);
  12892. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12893. if((access(FilePath,F_OK))!=-1)
  12894. {
  12895. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12896. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12897. system(rmFileCmd);
  12898. }
  12899. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12900. if(fp == NULL)
  12901. {
  12902. DEBUG_INFO("log is NULL\n");
  12903. return FALSE;
  12904. }
  12905. else
  12906. {
  12907. fprintf(fp, "%s\n", url);
  12908. fprintf(fp, "%s\n", filename);
  12909. fclose(fp);
  12910. }
  12911. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12912. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12913. systemresult = system(ftpbuf);
  12914. DEBUG_INFO("systemresult = %d\n",systemresult);
  12915. if(systemresult != 0)
  12916. {
  12917. DEBUG_INFO("http upload error!\n");
  12918. return FALSE;
  12919. }
  12920. return TRUE;
  12921. }
  12922. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12923. {
  12924. struct hostent* server;
  12925. char *IPbuffer;
  12926. char ftpbuf[200];
  12927. int systemresult;
  12928. // To retrieve host information
  12929. server = gethostbyname(location);
  12930. // To convert an Internet network
  12931. // address into ASCII string
  12932. IPbuffer = inet_ntoa(*((struct in_addr*)
  12933. server->h_addr_list[0]));
  12934. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12935. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12936. /* format : ftpput -u username -p passwd IP target source*/
  12937. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12938. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12939. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12940. systemresult = system(ftpbuf);
  12941. DEBUG_INFO("systemresult=%d\n",systemresult);
  12942. if(systemresult != 0)
  12943. {
  12944. DEBUG_INFO("ftpput error!\n");
  12945. return FALSE;
  12946. }
  12947. return TRUE;
  12948. }
  12949. /**
  12950. * Place the contents of the specified file into a memory buffer
  12951. *
  12952. * @param[in] filename The path and name of the file to read
  12953. * @param[out] filebuffer A pointer to the contents in memory
  12954. * @return status 0 success, 1 on failure
  12955. */
  12956. int get_file_contents(const char* filename, char** outbuffer) {
  12957. FILE* file = NULL;
  12958. long filesize;
  12959. const int blocksize = 1;
  12960. size_t readsize;
  12961. char* filebuffer;
  12962. // Open the file
  12963. file = fopen(filename, "r");
  12964. if (NULL == file)
  12965. {
  12966. printf("'%s' not opened\n", filename);
  12967. exit(EXIT_FAILURE);
  12968. }
  12969. // Determine the file size
  12970. fseek(file, 0, SEEK_END);
  12971. filesize = ftell(file);
  12972. rewind (file);
  12973. // Allocate memory for the file contents
  12974. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12975. *outbuffer = filebuffer;
  12976. if (filebuffer == NULL)
  12977. {
  12978. fputs ("malloc out-of-memory", stderr);
  12979. exit(EXIT_FAILURE);
  12980. }
  12981. // Read in the file
  12982. readsize = fread(filebuffer, blocksize, filesize, file);
  12983. if (readsize != filesize)
  12984. {
  12985. fputs ("didn't read file completely",stderr);
  12986. exit(EXIT_FAILURE);
  12987. }
  12988. // Clean exit
  12989. fclose(file);
  12990. return EXIT_SUCCESS;
  12991. }
  12992. static int selectSqlCount = 0;
  12993. static int callback(void *data, int argc, char **argv, char **azColName){
  12994. int i;
  12995. //printf("%s: ", (const char*)data);
  12996. selectSqlCount = argc;
  12997. for(i = 0; i<argc; i++){
  12998. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12999. }
  13000. //printf("\n");
  13001. return 0;
  13002. }
  13003. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  13004. //int i;
  13005. //printf("%s:\n", (const char*)data);
  13006. localversion = argv[5] ? atoi(argv[5]) : 0;
  13007. //printf("localversion=%d\n", localversion);
  13008. return 0;
  13009. }
  13010. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  13011. //int i;
  13012. //printf("%s:\n", (const char*)data);
  13013. //idTag
  13014. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  13015. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  13016. //parentIdTag
  13017. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  13018. //expir_date
  13019. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  13020. //status
  13021. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  13022. //version
  13023. idTagQuery.listVersionInt = atoi(argv[5]);
  13024. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  13025. return 0;
  13026. }
  13027. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  13028. {
  13029. // localversion = argv[5] ? atoi(argv[5]) : 0;
  13030. // printf("localversion=%d\n", localversion);
  13031. return 0;
  13032. }
  13033. //=========================================
  13034. // Sqlite3 related function
  13035. //=========================================
  13036. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  13037. {
  13038. for (int i = 0; i < n_columns; i++)
  13039. {
  13040. DEBUG_INFO("%s/t", col_values[i]);
  13041. }
  13042. DEBUG_INFO("/n");
  13043. return 0;
  13044. }
  13045. void OCPP_getListVerion()
  13046. {
  13047. int rc = 0;
  13048. // const char* data = "Callback function called";
  13049. char sql[100];
  13050. char zErrMsg[100];
  13051. memset(sql, 0, 100);
  13052. memset(zErrMsg, 0, 100);
  13053. strcpy(sql, "select * from ocpp_auth_local order by idx");
  13054. /* Execute SQL statement */
  13055. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  13056. if( rc != SQLITE_OK )
  13057. {
  13058. DEBUG_INFO("SQL error: %s", zErrMsg);
  13059. }
  13060. }
  13061. void OCPP_getIdTag(char idTag[])
  13062. {
  13063. int rc = 0;
  13064. // const char* data = "Callback function called";
  13065. char sql[100];
  13066. char zErrMsg[100];
  13067. memset(sql, 0, 100);
  13068. memset(zErrMsg, 0, 100);
  13069. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  13070. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13071. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  13072. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13073. /* Execute SQL statement */
  13074. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13075. if( rc != SQLITE_OK )
  13076. {
  13077. DEBUG_INFO("SQL error: %s", zErrMsg);
  13078. }
  13079. //return ver;
  13080. }
  13081. void OCPP_get_TableAuthlocalAllData(void)
  13082. {
  13083. int rc = 0;
  13084. char sql[100];
  13085. char zErrMsg[100];
  13086. memset(sql, 0, 100);
  13087. memset(zErrMsg, 0, 100);
  13088. sprintf(sql,"select * from ocpp_auth_local ");
  13089. /* Execute SQL statement */
  13090. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  13091. if( rc != SQLITE_OK )
  13092. {
  13093. DEBUG_INFO("SQL error: %s", zErrMsg);
  13094. }
  13095. //return ver;
  13096. }
  13097. int OCPP_cleanLocalList()
  13098. {
  13099. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  13100. char *errMsg = 0;
  13101. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13102. if (SQLITE_OK != rc)
  13103. {
  13104. DEBUG_INFO("%s\n",errMsg);
  13105. return FALSE;
  13106. }
  13107. return TRUE;
  13108. }
  13109. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13110. {
  13111. int isSuccess = FALSE;
  13112. int ret = 0;
  13113. //const char* data = "Callback function called";
  13114. char sql[300];
  13115. char zErrMsg[200];
  13116. memset(sql, 0, 300);
  13117. memset(zErrMsg, 0, 200);
  13118. 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);
  13119. //* Execute SQL statement */
  13120. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13121. if( ret != SQLITE_OK )
  13122. {
  13123. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13124. return isSuccess;
  13125. }
  13126. memset(sql, 0, 300);
  13127. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13128. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13129. if( ret != SQLITE_OK )
  13130. {
  13131. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13132. return isSuccess;
  13133. }
  13134. isSuccess = TRUE;
  13135. return isSuccess;
  13136. }
  13137. void OCPP_deleteIdTag(char idTag[])
  13138. {
  13139. //int ver = 0;
  13140. //int isSuccess = FALSE;
  13141. int rc = 0;
  13142. char sql[100];
  13143. char zErrMsg[100];
  13144. memset(sql, 0, 100);
  13145. memset(zErrMsg, 0, 100);
  13146. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13147. //* Execute SQL statement */
  13148. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13149. if( rc != SQLITE_OK )
  13150. {
  13151. DEBUG_INFO("SQL error: %s", zErrMsg);
  13152. }
  13153. }
  13154. int GetOcppServerURL()
  13155. {
  13156. int result = FALSE;
  13157. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  13158. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  13159. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  13160. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13161. {
  13162. #if 1
  13163. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13164. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13165. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13166. #endif
  13167. result = TRUE;
  13168. goto End;
  13169. }
  13170. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13171. {
  13172. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13173. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13174. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13175. result = TRUE;
  13176. goto End;
  13177. }
  13178. else
  13179. {
  13180. strcpy(OcppHost,"");
  13181. }
  13182. End:
  13183. return result;
  13184. }
  13185. int GetOcppPath()
  13186. {
  13187. int result = FALSE;
  13188. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13189. {
  13190. if(OcppTempPath == NULL)
  13191. {
  13192. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13193. }
  13194. else
  13195. {
  13196. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13197. }
  13198. result = TRUE;
  13199. goto End;
  13200. }
  13201. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13202. {
  13203. if(OcppTempPath == NULL)
  13204. {
  13205. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13206. }
  13207. else
  13208. {
  13209. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13210. }
  13211. result = TRUE;
  13212. goto End;
  13213. }
  13214. else
  13215. {
  13216. strcpy(OcppPath,"");
  13217. }
  13218. End:
  13219. return result;
  13220. }
  13221. int GetOcppPort()
  13222. {
  13223. return OcppPort;
  13224. }
  13225. int GetOcppConnStatus(void)
  13226. {
  13227. return ShmOCPP16Data->OcppConnStatus;
  13228. }
  13229. void SetOcppConnStatus(uint8_t status)
  13230. {
  13231. ShmOCPP16Data->OcppConnStatus = status;
  13232. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13233. }
  13234. int GetHeartBeatWithNOResponse(void)
  13235. {
  13236. return HeartBeatWithNOResponse;
  13237. }
  13238. void SetHeartBeatWithNOResponse(void)
  13239. {
  13240. HeartBeatWithNOResponse = 0;
  13241. }
  13242. void GetStartTransactionIdTag(int gun_index)
  13243. {
  13244. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13245. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13246. }
  13247. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13248. {
  13249. char ch;
  13250. FILE *fptr1;
  13251. int temptransactionId;
  13252. char str[100]={0};
  13253. temptransactionId = 0;
  13254. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  13255. {
  13256. DEBUG_INFO("IdTag is empty.\n");
  13257. return temptransactionId;
  13258. }
  13259. /*------ Read the file ----------------*/
  13260. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13261. if (!fptr1)
  13262. {
  13263. DEBUG_INFO("QueueTransactionId file open error.\n");
  13264. //printf(" File not found or unable to open the input file!!\n");
  13265. return temptransactionId;
  13266. }
  13267. ch=fgetc(fptr1);
  13268. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13269. rewind(fptr1);
  13270. if(ch!=EOF)
  13271. {
  13272. // printf("%c",ch);
  13273. while (fgets(str, 100, fptr1) != NULL)
  13274. {
  13275. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13276. if(str[0]=='\0')
  13277. {
  13278. break;
  13279. }
  13280. char *revbuf[8] = {0}; //存放分割後的子字串
  13281. int num = 0;//分割後子字串的個數
  13282. DEBUG_INFO("str: %s\n", str);
  13283. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13284. DEBUG_INFO("revbuf[0]: %s\n", revbuf[0]);
  13285. DEBUG_INFO("revbuf[1]: %s\n", revbuf[1]);
  13286. DEBUG_INFO("revbuf[2]: %s\n", revbuf[2]);
  13287. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13288. {
  13289. if(isStopTransaction)
  13290. {
  13291. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13292. {
  13293. temptransactionId = atoi(revbuf[2]);
  13294. break;
  13295. }
  13296. }
  13297. else
  13298. {
  13299. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13300. {
  13301. temptransactionId = atoi(revbuf[2]);
  13302. break;
  13303. }
  13304. }
  13305. }
  13306. }
  13307. }
  13308. else
  13309. DEBUG_INFO("EOF\n");
  13310. fclose(fptr1);
  13311. /*------- End of reading ---------------*/
  13312. return temptransactionId;
  13313. }
  13314. void SetTransactionIdZero(int transactionId)
  13315. {
  13316. char ch;
  13317. FILE *fptr1, *fptr2;
  13318. int temptransactionId = 0;
  13319. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13320. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13321. if (!fptr1)
  13322. {
  13323. //printf(" File not found or unable to open the input file!!\n");
  13324. return ;
  13325. }
  13326. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13327. if (!fptr2)
  13328. {
  13329. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13330. fclose(fptr1);
  13331. return ;
  13332. }
  13333. ch=fgetc(fptr1);
  13334. rewind(fptr1);
  13335. if(ch!=EOF)
  13336. {
  13337. // copy all contents to the temporary file except the specific line
  13338. while (fgets(str, 100, fptr1) != NULL)
  13339. {
  13340. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13341. if(str[0]=='\0')
  13342. {
  13343. break;
  13344. }
  13345. char *revbuf[8] = {0};
  13346. int num = 0;
  13347. strcpy(strtemp, str);
  13348. splitstring(str,",",revbuf,&num);
  13349. if(revbuf[2][0] != '\0')
  13350. {
  13351. temptransactionId = atoi(revbuf[2]);
  13352. if(transactionId != temptransactionId)
  13353. {
  13354. fprintf(fptr2, "%s\n", strtemp);
  13355. }
  13356. }
  13357. }
  13358. }
  13359. fclose(fptr1);
  13360. fclose(fptr2);
  13361. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13362. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13363. /*------ Read the file ----------------*/
  13364. }
  13365. int InternetDisconnect(void)
  13366. {
  13367. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13368. }
  13369. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13370. void storeTempStopTransaction(int gun_index)
  13371. {
  13372. char guid[37]={0};
  13373. int tempIndex = 0;
  13374. DEBUG_INFO("storeTempStopTransaction...\n");
  13375. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13376. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13377. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13378. if(gunType[gun_index] == 'J')
  13379. {
  13380. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13381. {
  13382. tempIndex = ((gun_index==2) ? 1: 0);
  13383. }
  13384. else
  13385. {
  13386. tempIndex = gun_index;
  13387. }
  13388. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13389. {
  13390. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13391. {
  13392. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13393. }
  13394. }// END OF CHAdeMO_QUANTITY
  13395. }
  13396. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13397. {
  13398. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13399. {
  13400. tempIndex = ((gun_index==2) ? 1: 0);
  13401. }
  13402. else
  13403. {
  13404. tempIndex = gun_index;
  13405. }
  13406. for (int index = 0; index < CCS_QUANTITY; index++)
  13407. {
  13408. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13409. {
  13410. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13411. }
  13412. }// END OF CCS_QUANTITY
  13413. }
  13414. else if(gunType[gun_index] == 'G')
  13415. {
  13416. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13417. {
  13418. tempIndex = ((gun_index==2) ? 1: 0);
  13419. }
  13420. else
  13421. {
  13422. tempIndex = gun_index;
  13423. }
  13424. for (int index = 0; index < GB_QUANTITY; index++)
  13425. {
  13426. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13427. {
  13428. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13429. }
  13430. }// END OF GB_QUANTITY
  13431. }
  13432. else
  13433. {
  13434. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13435. {
  13436. tempIndex = 2;
  13437. }
  13438. else
  13439. {
  13440. tempIndex = gun_index;
  13441. }
  13442. for (int index = 0; index < AC_QUANTITY; index++)
  13443. {
  13444. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13445. {
  13446. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13447. }
  13448. }// END OF AC_QUANTITY
  13449. }
  13450. //Stop Transaction Time
  13451. struct timeval tmnow;
  13452. struct tm *tm;
  13453. char buf[28];//, usec_buf[6];
  13454. gettimeofday(&tmnow, NULL);
  13455. time_t t;
  13456. t = time(NULL);
  13457. /*UTC time and date*/
  13458. tm = gmtime(&t);
  13459. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13461. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13462. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13463. random_uuid(guid);
  13464. /***********************************transactionData******************************************************/
  13465. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13466. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13467. //=================================
  13468. //1. Transaction_Begin
  13469. //=================================
  13470. //============================== Energy.Active.Import.Interval ===========================================
  13471. //idx_sample=0;
  13472. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  13473. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13474. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13475. 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*/]);
  13476. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13477. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13478. {
  13479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13480. }
  13481. else
  13482. {
  13483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13484. }
  13485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13487. //=================================
  13488. //2. Transaction_End
  13489. //=================================
  13490. //2.1====================================== Current.Import L1 ==============================================
  13491. //idx_sample=1;
  13492. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13493. if(gunType[gun_index] == 'J')
  13494. {
  13495. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13496. {
  13497. tempIndex = ((gun_index==2) ? 1: 0);
  13498. }
  13499. else
  13500. {
  13501. tempIndex = gun_index;
  13502. }
  13503. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13504. {
  13505. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13506. {
  13507. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13508. }
  13509. }// End of for CHAdeMO_QUANTITY
  13510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13511. }
  13512. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13513. {
  13514. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13515. {
  13516. tempIndex = ((gun_index==2) ? 1: 0);
  13517. }
  13518. else
  13519. {
  13520. tempIndex = gun_index;
  13521. }
  13522. for (int index = 0; index < CCS_QUANTITY; index++)
  13523. {
  13524. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13525. {
  13526. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13527. }
  13528. }// End of for CCS_QUANTITY
  13529. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13530. }
  13531. else if(gunType[gun_index] == 'G')
  13532. {
  13533. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13534. {
  13535. tempIndex = ((gun_index==2) ? 1: 0);
  13536. }
  13537. else
  13538. {
  13539. tempIndex = gun_index;
  13540. }
  13541. for (int index = 0; index < GB_QUANTITY; index++)
  13542. {
  13543. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13544. {
  13545. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13546. }
  13547. }// End of for GB_QUANTITY
  13548. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13549. }
  13550. else
  13551. {
  13552. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13553. {
  13554. tempIndex = 2;
  13555. }
  13556. else
  13557. {
  13558. tempIndex = gun_index;
  13559. }
  13560. for (int index = 0; index < AC_QUANTITY; index++)
  13561. {
  13562. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13563. {
  13564. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13565. }
  13566. }// End of for AC_QUANTITY
  13567. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13568. }
  13569. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13570. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13571. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13572. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13573. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13574. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13575. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13576. //idx_sample=2;
  13577. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13578. if(gunType[gun_index] == 'J')
  13579. {
  13580. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13581. {
  13582. tempIndex = ((gun_index==2) ? 1: 0);
  13583. }
  13584. else
  13585. {
  13586. tempIndex = gun_index;
  13587. }
  13588. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13589. {
  13590. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13591. {
  13592. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13593. }
  13594. }// END OF CHAdeMO_QUANTITY
  13595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13596. }
  13597. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13598. {
  13599. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13600. {
  13601. tempIndex = ((gun_index==2) ? 1: 0);
  13602. }
  13603. else
  13604. {
  13605. tempIndex = gun_index;
  13606. }
  13607. for (int index = 0; index < CCS_QUANTITY; index++)
  13608. {
  13609. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13610. {
  13611. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13612. }
  13613. }// END OF CCS_QUANTITY
  13614. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13615. }
  13616. else if(gunType[gun_index] == 'G')
  13617. {
  13618. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13619. {
  13620. tempIndex = ((gun_index==2) ? 1: 0);
  13621. }
  13622. else
  13623. {
  13624. tempIndex = gun_index;
  13625. }
  13626. for (int index = 0; index < GB_QUANTITY; index++)
  13627. {
  13628. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13629. {
  13630. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13631. }
  13632. }// END OF GB_QUANTITY
  13633. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13634. }
  13635. else
  13636. {
  13637. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13638. {
  13639. tempIndex = 2;
  13640. }
  13641. else
  13642. {
  13643. tempIndex = gun_index;
  13644. }
  13645. for (int index = 0; index < AC_QUANTITY; index++)
  13646. {
  13647. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13648. {
  13649. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13650. }
  13651. }// END OF AC_QUANTITY
  13652. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13653. }
  13654. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13655. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13656. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13657. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13658. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13659. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13660. //2.3====================================== Power.Active.Import =========================================
  13661. //idx_sample=3;
  13662. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13663. if(gunType[gun_index] == 'J')
  13664. {
  13665. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13666. {
  13667. tempIndex = ((gun_index==2) ? 1: 0);
  13668. }
  13669. else
  13670. {
  13671. tempIndex = gun_index;
  13672. }
  13673. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13674. {
  13675. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13676. {
  13677. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13678. }
  13679. } // End for CHAdeMO_QUANTITY
  13680. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13681. }
  13682. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13683. {
  13684. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13685. {
  13686. tempIndex = ((gun_index==2) ? 1: 0);
  13687. }
  13688. else
  13689. {
  13690. tempIndex = gun_index;
  13691. }
  13692. for (int index = 0; index < CCS_QUANTITY; index++)
  13693. {
  13694. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13695. {
  13696. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13697. }
  13698. } // END for CCS_QUANTITY
  13699. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13700. }
  13701. else if(gunType[gun_index] == 'G')
  13702. {
  13703. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13704. {
  13705. tempIndex = ((gun_index==2) ? 1: 0);
  13706. }
  13707. else
  13708. {
  13709. tempIndex = gun_index;
  13710. }
  13711. for (int index = 0; index < GB_QUANTITY; index++)
  13712. {
  13713. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13714. {
  13715. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13716. }
  13717. }// END for GB_QUANTITY
  13718. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13719. }
  13720. else
  13721. {
  13722. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13723. {
  13724. tempIndex = 2;
  13725. }
  13726. else
  13727. {
  13728. tempIndex = gun_index;
  13729. }
  13730. for (int index = 0; index < AC_QUANTITY; index++)
  13731. {
  13732. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13733. {
  13734. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13735. }
  13736. } // END for AC_QUANTITY
  13737. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13738. }
  13739. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13740. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13741. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13742. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13743. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13744. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13745. //2.4====================================== Voltage L1 ====================================================
  13746. //idx_sample=4;
  13747. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13748. if(gunType[gun_index] == 'J')
  13749. {
  13750. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13751. {
  13752. tempIndex = ((gun_index==2) ? 1: 0);
  13753. }
  13754. else
  13755. {
  13756. tempIndex = gun_index;
  13757. }
  13758. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13759. {
  13760. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13761. {
  13762. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13763. }
  13764. } // END OF FOR CHAdeMO_QUANTITY
  13765. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13766. }
  13767. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13768. {
  13769. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13770. {
  13771. tempIndex = ((gun_index==2) ? 1: 0);
  13772. }
  13773. else
  13774. {
  13775. tempIndex = gun_index;
  13776. }
  13777. for (int index = 0; index < CCS_QUANTITY; index++)
  13778. {
  13779. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13780. {
  13781. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13782. }
  13783. } // END OF FOR CCS_QUANTITY
  13784. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13785. }
  13786. else if(gunType[gun_index] == 'G')
  13787. {
  13788. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13789. {
  13790. tempIndex = ((gun_index==2) ? 1: 0);
  13791. }
  13792. else
  13793. {
  13794. tempIndex = gun_index;
  13795. }
  13796. for (int index = 0; index < GB_QUANTITY; index++)
  13797. {
  13798. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13799. {
  13800. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13801. }
  13802. } // END OF FOR GB_QUANTITY
  13803. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13804. }
  13805. else
  13806. {
  13807. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13808. {
  13809. tempIndex = 2;
  13810. }
  13811. else
  13812. {
  13813. tempIndex = gun_index;
  13814. }
  13815. for (int index = 0; index < AC_QUANTITY; index++)
  13816. {
  13817. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13818. {
  13819. 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
  13820. }
  13821. } // END OF FOR AC_QUANTITY
  13822. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13823. }
  13824. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13825. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13826. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13827. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13828. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13829. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13830. //2.5============================================== SoC =========================================================
  13831. //idx_sample=5;
  13832. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13833. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13834. {
  13835. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13836. {
  13837. tempIndex = ((gun_index==2) ? 1: 0);
  13838. }
  13839. else
  13840. {
  13841. tempIndex = gun_index;
  13842. }
  13843. if(gunType[gun_index] == 'J')
  13844. {
  13845. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13846. {
  13847. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13848. {
  13849. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13850. }
  13851. }
  13852. }
  13853. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13854. {
  13855. for (int index = 0; index < CCS_QUANTITY; index++)
  13856. {
  13857. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13858. {
  13859. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13860. }
  13861. }
  13862. }
  13863. else if(gunType[gun_index] == 'G')
  13864. {
  13865. for (int index = 0; index < GB_QUANTITY; index++)
  13866. {
  13867. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13868. {
  13869. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13870. }
  13871. }
  13872. }
  13873. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13874. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13875. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13876. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13877. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  13878. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13879. } // END FOR DC CASE
  13880. //2.6====================================== Current.Import L2 ==============================================
  13881. // idx_sample=6;
  13882. // AC 3 phase L2 current
  13883. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13884. {
  13885. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13886. {
  13887. tempIndex = 2;
  13888. }
  13889. else
  13890. {
  13891. tempIndex = gun_index;
  13892. }
  13893. for (int index = 0; index < AC_QUANTITY; index++)
  13894. {
  13895. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13896. {
  13897. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  13898. }
  13899. }// End of for AC_QUANTITY
  13900. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  13901. }
  13902. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13903. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  13904. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  13905. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  13906. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13907. //2.7====================================== Current.Import L3 ==============================================
  13908. // idx_sample=7;
  13909. // AC 3 phase L3 current
  13910. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13911. {
  13912. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13913. {
  13914. tempIndex = 2;
  13915. }
  13916. else
  13917. {
  13918. tempIndex = gun_index;
  13919. }
  13920. for (int index = 0; index < AC_QUANTITY; index++)
  13921. {
  13922. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13923. {
  13924. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  13925. }
  13926. }// End of for AC_QUANTITY
  13927. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  13928. }
  13929. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13930. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  13931. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  13932. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  13933. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13934. //2.9====================================== Voltage L2 ====================================================
  13935. //idx_sample=8;
  13936. // AC 3 phase L2 volatge
  13937. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13938. {
  13939. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13940. {
  13941. tempIndex = 2;
  13942. }
  13943. else
  13944. {
  13945. tempIndex = gun_index;
  13946. }
  13947. for (int index = 0; index < AC_QUANTITY; index++)
  13948. {
  13949. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13950. {
  13951. 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
  13952. }
  13953. } // END OF FOR AC_QUANTITY
  13954. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  13955. }
  13956. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13957. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  13958. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  13959. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  13960. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13961. //2.10====================================== Voltage L3 ====================================================
  13962. //idx_sample=9;
  13963. // AC 3 phase L3 volatge
  13964. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13965. {
  13966. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13967. {
  13968. tempIndex = 2;
  13969. }
  13970. else
  13971. {
  13972. tempIndex = gun_index;
  13973. }
  13974. for (int index = 0; index < AC_QUANTITY; index++)
  13975. {
  13976. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13977. {
  13978. 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
  13979. }
  13980. } // END OF FOR AC_QUANTITY
  13981. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  13982. }
  13983. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  13985. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  13986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  13987. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13988. //======================================== Message create ==============================================
  13989. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13990. {
  13991. 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\"}]}]}]"
  13992. ,gun_index+1
  13993. ,MESSAGE_TYPE_CALL
  13994. ,guid
  13995. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13996. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13997. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13998. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13999. ,"PowerLoss"
  14000. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  14001. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  14002. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  14003. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  14004. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  14005. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  14006. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  14007. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  14008. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  14009. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  14010. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  14011. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  14012. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  14013. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  14014. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  14015. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  14016. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  14017. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  14018. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  14019. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  14020. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  14021. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  14022. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  14023. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  14024. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  14025. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  14026. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  14027. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  14028. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  14029. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  14030. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  14031. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  14032. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  14033. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  14034. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  14035. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  14036. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  14037. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  14038. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  14039. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  14040. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  14041. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  14042. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  14043. );
  14044. }
  14045. else
  14046. {
  14047. if(((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W')))
  14048. {
  14049. 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\"}]}]}]"
  14050. ,gun_index+1
  14051. ,MESSAGE_TYPE_CALL
  14052. ,guid
  14053. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  14054. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  14055. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  14056. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  14057. ,"PowerLoss"
  14058. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  14059. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  14060. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  14061. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  14062. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  14063. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  14064. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  14065. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  14066. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  14067. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  14068. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  14069. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  14070. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  14071. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  14072. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  14073. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  14074. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  14075. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  14076. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  14077. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  14078. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  14079. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  14080. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  14081. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  14082. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  14083. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  14084. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  14085. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  14086. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  14087. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  14088. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  14089. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  14090. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  14091. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  14092. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  14093. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  14094. );
  14095. }
  14096. else
  14097. {
  14098. 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\"}]}]}]"
  14099. ,gun_index+1
  14100. ,MESSAGE_TYPE_CALL
  14101. ,guid
  14102. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  14103. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  14104. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  14105. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  14106. ,"PowerLoss"
  14107. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  14108. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  14109. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  14110. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  14111. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  14112. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  14113. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  14114. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  14115. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  14116. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  14117. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  14118. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  14119. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  14120. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  14121. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  14122. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  14123. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  14124. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  14125. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  14126. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  14127. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  14128. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  14129. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  14130. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  14131. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  14132. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  14133. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  14134. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  14135. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  14136. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  14137. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  14138. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  14139. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  14140. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  14141. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  14142. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  14143. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  14144. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  14145. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  14146. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  14147. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  14148. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  14149. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  14150. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  14151. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  14152. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  14153. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  14154. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  14155. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  14156. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  14157. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  14158. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  14159. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  14160. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  14161. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  14162. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  14163. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  14164. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  14165. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  14166. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  14167. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  14168. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  14169. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  14170. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  14171. );
  14172. }
  14173. }
  14174. // Check File "TempStopTransaction" Exist
  14175. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  14176. {
  14177. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14178. fclose(fopen("/Storage/OCPP/TempStopTransaction", "w"));
  14179. }
  14180. else
  14181. {
  14182. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  14183. FILE *log = fopen("/Storage/OCPP/TempStopTransaction", "w+");
  14184. if(log == NULL)
  14185. {
  14186. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  14187. return ;
  14188. }
  14189. else
  14190. {
  14191. fclose(log);
  14192. }
  14193. }
  14194. //Add TempStopTransaction | Update TempStopTransaction
  14195. // open file for writing
  14196. FILE *outfile;
  14197. outfile = fopen ("/Storage/OCPP/TempStopTransaction", "a");
  14198. //DEBUG_INFO("data = %s\n", queuedata);
  14199. fputs(queuedata, outfile);
  14200. fputs("\n", outfile);
  14201. fclose (outfile);
  14202. }
  14203. void checkTempStopTransaction(int gun_index)
  14204. {
  14205. FILE *fptr1;
  14206. char ch;
  14207. char str[QUEUE_MESSAGE_LENGTH]={0};
  14208. char guid[37]={0};
  14209. char tempdata[65]={0};
  14210. char connectorStr[2]={0};
  14211. fptr1 = fopen("/Storage/OCPP/TempStopTransaction", "r");
  14212. //TempStopTransaction格式: 槍號,StopTransaction封包
  14213. if (!fptr1)
  14214. {
  14215. //printf(" File not found or unable to open the input file!!\n");
  14216. return ;
  14217. }
  14218. ch=fgetc(fptr1);
  14219. //printf(" Now the content of the file %s is : \n",fname);
  14220. rewind(fptr1);
  14221. if(ch!=EOF)
  14222. {
  14223. // copy all contents to the temporary file except the specific line
  14224. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14225. {
  14226. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14227. if(str[0]=='\0')
  14228. {
  14229. break;
  14230. }
  14231. //TempStopTransaction格式: 槍號,StopTransaction封包
  14232. strncpy(connectorStr, str, 1);
  14233. if(atoi(connectorStr) != (gun_index+1))
  14234. {
  14235. DEBUG_INFO("atoi(connectorStr) = %d\n", atoi(connectorStr));
  14236. return ;
  14237. }
  14238. //random_uuid(guid);
  14239. strncpy(guid, str+6, 36); //copy guid
  14240. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14241. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14242. {
  14243. DEBUG_INFO("StopTransaction mapitem pass\n");
  14244. }
  14245. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14246. memset(str,0,ARRAY_SIZE(str));
  14247. }
  14248. }
  14249. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14250. fclose(fptr1);
  14251. remove("/Storage/OCPP/TempStopTransaction"); // remove the original file
  14252. }
  14253. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14254. {
  14255. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14256. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14257. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14258. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14259. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14260. }
  14261. int GetWebSocketPingInterval(void)
  14262. {
  14263. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14264. }
  14265. int GetServerSign(void)
  14266. {
  14267. return server_sign;
  14268. }
  14269. void SetServerSign(int value)
  14270. {
  14271. server_sign = value;
  14272. }
  14273. int GetBootNotificationInterval(void)
  14274. {
  14275. return BootNotificationInterval;
  14276. }
  14277. int GetInternetConn(void)
  14278. {
  14279. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14280. }
  14281. void InitialSystemValue(void)
  14282. {
  14283. int connectorIndex = 0;
  14284. //int valueASCII = 0;
  14285. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14286. gunTotalNumber=0;
  14287. SystemInitial = 0;
  14288. localversion=0;
  14289. BootNotificationInterval = 0;
  14290. authorizeRetryTimes = 0;
  14291. GunStatusInterval = 10;
  14292. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14293. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14294. //Hear Beat
  14295. HeartBeatWithNOResponse = 0;
  14296. HeartBeatCountPerHour = 0;
  14297. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14298. FirstHeartBeat = 0;
  14299. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14300. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14301. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14302. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14303. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14304. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14305. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14306. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14307. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14308. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14309. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14310. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14311. memset(gunType, 0, ARRAY_SIZE(gunType));
  14312. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14313. {
  14314. //check connector / socket type (index: 8, 9, 10)
  14315. for(int index=7; index <10 ; index++)
  14316. {
  14317. if(index != 8)
  14318. {
  14319. // DC Connector
  14320. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  14321. {
  14322. SystemInitial = SystemInitial + 1;
  14323. gunTotalNumber = gunTotalNumber + 1;
  14324. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14325. connectorIndex = connectorIndex + 1;
  14326. }
  14327. }
  14328. else
  14329. {
  14330. // AC Connector
  14331. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14332. {
  14333. SystemInitial = SystemInitial + 1;
  14334. gunTotalNumber = gunTotalNumber + 1;
  14335. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14336. connectorIndex = connectorIndex + 1;
  14337. }
  14338. }
  14339. }
  14340. //DEBUG_INFO("DC ...\n");
  14341. }
  14342. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14343. {
  14344. //check connector / socket type (index: 8, 9, 10)
  14345. for(int index=7; index <10 ; index++)
  14346. {
  14347. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14348. {
  14349. SystemInitial = SystemInitial + 1;
  14350. gunTotalNumber = gunTotalNumber + 1;
  14351. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14352. connectorIndex = connectorIndex + 1;
  14353. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14354. }
  14355. }
  14356. }
  14357. //Status && ConnectorPlugIn Setting
  14358. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14359. {
  14360. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14361. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14362. }
  14363. for (int index = 0; index < CCS_QUANTITY; index++)
  14364. {
  14365. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14366. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14367. }
  14368. for (int index = 0; index < GB_QUANTITY; index++)
  14369. {
  14370. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14371. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14372. }
  14373. for (int index = 0; index < AC_QUANTITY; index++)
  14374. {
  14375. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14376. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14377. }
  14378. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14379. {
  14380. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14381. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14382. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14383. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14384. }
  14385. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14386. clientTime.Heartbeat=time((time_t*)NULL);
  14387. sleep(1);
  14388. }
  14389. void LWS_Send(char * str)
  14390. {
  14391. //=====================================================
  14392. // Check InternetConn 0: disconnected, 1: connected
  14393. //====================================================
  14394. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14395. {
  14396. DEBUG_INFO("offline now !!!\n");
  14397. return;
  14398. }
  14399. pthread_mutex_lock(&lock_send);
  14400. memset(SendBuffer, 0, SendBufLen);
  14401. sprintf((char *)SendBuffer, "%s", str);
  14402. pthread_mutex_unlock(&lock_send);
  14403. lws_callback_on_writable(wsi_client);
  14404. //lws_service(context, 0);
  14405. //sleep(1);
  14406. }