MessageHandler.c 677 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. #define TxDefaultProfile_1_JSON "/Storage/OCPP/TxDefaultProfile_1.json"
  8. #define TxDefaultProfile_2_JSON "/Storage/OCPP/TxDefaultProfile_2.json"
  9. //TxProfile
  10. #define TxProfile_1_JSON "/Storage/OCPP/TxProfile_1.json"
  11. #define TxProfile_2_JSON "/Storage/OCPP/TxProfile_2.json"
  12. #define ChargingProfile_0_JSON "/Storage/OCPP/chargingprofile_0.json"
  13. #define ChargingProfile_1_JSON "/Storage/OCPP/chargingprofile_1.json"
  14. #define ChargingProfile_2_JSON "/Storage/OCPP/chargingprofile_2.json"
  15. #define AuthorizationCache_JSON "/Storage/OCPP/AuthorizationCache.json"
  16. #define LocalAuthorizationList_JSON "/Storage/OCPP/LocalAuthorizationList.json"
  17. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  18. struct StatusCodeData *ShmStatusCodeData;
  19. struct PsuData *ShmPsuData ;
  20. struct OCPP16Data *ShmOCPP16Data;
  21. //ConfigurationMaxKeys
  22. #define GetConfigurationMaxKeysNUM 44
  23. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  24. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  25. //=================================
  26. // StatusNotification cycle
  27. //=================================
  28. static int server_cycle_Status = 120;
  29. //===============================
  30. // Configuration: unknownkey
  31. //===============================
  32. static char unknownkey[10][20] = {0};
  33. static int UnknownKeynum = 0;
  34. //===============================
  35. // Gun Total Numbers
  36. //===============================
  37. static int gunTotalNumber = 0;
  38. static uint8_t gunType[4] = {0};
  39. //===============================
  40. // Local List Version
  41. //===============================
  42. static int localversion=0;
  43. static char idTagAuthorization[32] = {0};
  44. //===============================
  45. // OCPP sign variable
  46. //===============================
  47. static int server_sign = FALSE;
  48. int server_pending = FALSE;
  49. static int BootNotificationInterval = 0;
  50. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  51. //===============================
  52. // OCPP auth variable
  53. //===============================
  54. static int authorizeRetryTimes = 0; //number of Retry times
  55. //===============================
  56. // OCPP other variables
  57. //===============================
  58. static int HeartBeatWaitTime = 10;
  59. static int FirstHeartBeat = 0;
  60. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  61. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  62. static char CurrentChargingProfileScheduleStr[30] = {0};
  63. //========================================
  64. // OCPP status/previous related variables
  65. //========================================
  66. static int GunStatusInterval = 10;
  67. static uint8_t statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  68. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  69. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  70. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  71. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  72. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  73. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  74. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  75. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  76. static int TransactionMessageAttemptsValue = 0;
  77. static int TransactionMessageRetryIntervalValue = 0;
  78. static int TempMeterValueInterval = 0;
  79. static struct OCPPAuthLocalElemet
  80. {
  81. int listVersionInt;
  82. char idTagstr[20];
  83. char parentIdTag[20];
  84. char expiryDate[30];
  85. char idTagstatus[16];
  86. }idTagQuery;
  87. //=============================================
  88. // OCPP HeartBeat Response Not Receive Counts
  89. //============================================
  90. static int HeartBeatWithNOResponse = 0;
  91. static int HeartBeatCountPerHour = 0;
  92. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  93. extern int GetTransactionQueueNum(void);
  94. extern struct Charger_Info Charger;
  95. extern sqlite3 *db;
  96. int TransactionMessageAttemptsGet(void);
  97. int TransactionMessageRetryIntervalGet(void);
  98. int GetOcppConnStatus(void);
  99. void SetOcppConnStatus(uint8_t status);
  100. int setKeyValue(char *key, char *value);
  101. void OCPP_get_TableAuthlocalAllData(void);
  102. void processUnkownKey(void);
  103. struct StructOCPPMeterValue
  104. {
  105. unsigned char TimeStamp[28];
  106. struct StructSampledValue SampledValue[10];
  107. };
  108. struct ClientTime
  109. {
  110. unsigned int Heartbeat;
  111. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  112. unsigned int StartTransaction;
  113. unsigned int StopTransaction;
  114. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  115. }clientTime;
  116. typedef union
  117. {
  118. //Operations Initiated by Central System
  119. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  120. struct
  121. {
  122. //CsMsgValue[0]
  123. unsigned char StatusNotificationReq:1; //bit 0,
  124. unsigned char StatusNotificationConf:1; //bit 1,
  125. unsigned char TriggerMeterValue:1; //bit 2,
  126. unsigned char :5; //bit 5~7
  127. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  128. }CpinitiateMsg;
  129. CpinitiateMsg cpinitateMsg;
  130. //GetConfiguration Array
  131. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  132. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  133. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  134. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  135. #if 0
  136. static char *ChargePointErrorCodeStr[] = {
  137. MACROSTR(ConnectorLockFailure),
  138. MACROSTR(EVCommunicationError),
  139. MACROSTR(GroundFailure),
  140. MACROSTR(HighTemperature),
  141. MACROSTR(InternalError),
  142. MACROSTR(LocalListConflict),
  143. MACROSTR(NoError),
  144. MACROSTR(OtherError),
  145. MACROSTR(OverCurrentFailure),
  146. MACROSTR(OverVoltage),
  147. MACROSTR(PowerMeterFailure),
  148. MACROSTR(PowerSwitchFailure),
  149. MACROSTR(ReaderFailure),
  150. MACROSTR(ResetFailure),
  151. MACROSTR(UnderVoltage),
  152. MACROSTR(WeakSignal)
  153. };
  154. #endif
  155. static char * ChargePointStatusStr[] = {
  156. MACROSTR(Available),
  157. MACROSTR(Preparing),
  158. MACROSTR(Charging),
  159. MACROSTR(SuspendedEVSE),
  160. MACROSTR(SuspendedEV),
  161. MACROSTR(Finishing),
  162. MACROSTR(Reserved),
  163. MACROSTR(Unavailable),
  164. MACROSTR(Faulted)
  165. };
  166. static char *RegistrationStatusStr[] = {
  167. MACROSTR(Accepted),
  168. MACROSTR(Pending),
  169. MACROSTR(Rejected)
  170. };
  171. static char *AvailabilityTypeStr[] = {
  172. MACROSTR(Inoperative),
  173. MACROSTR(Operative)
  174. };
  175. static char *AvailabilityStatusStr[] = {
  176. MACROSTR(Accepted),
  177. MACROSTR(Rejected),
  178. MACROSTR(Scheduled)
  179. };
  180. static char *ConfigurationStatusStr[] = {
  181. MACROSTR(Accepted),
  182. MACROSTR(Rejected),
  183. MACROSTR(RebootRequired),
  184. MACROSTR(NotSupported)
  185. };
  186. static char *ClearCacheStatusStr[] = {
  187. MACROSTR(Accepted),
  188. MACROSTR(Rejected)
  189. };
  190. static char *ChargingProfilePurposeTypeStr[] = {
  191. MACROSTR(ChargePointMaxProfile),
  192. MACROSTR(TxDefaultProfile),
  193. MACROSTR(TxProfile)
  194. };
  195. static char *ChargingProfileStatusStr[] = {
  196. MACROSTR(Accepted),
  197. MACROSTR(Rejected),
  198. MACROSTR(NotSupported)
  199. };
  200. static char *ClearChargingProfileStatusStr[] = {
  201. MACROSTR(Accepted),
  202. MACROSTR(Unknown)
  203. };
  204. static char *GetCompositeScheduleStatusStr[] = {
  205. MACROSTR(Accepted),
  206. MACROSTR(Rejected)
  207. };
  208. static char *UpdateTypeStr[] = {
  209. MACROSTR(Differential),
  210. MACROSTR(Full)
  211. };
  212. static char *UpdateStatusStr[] = {
  213. MACROSTR(Accepted),
  214. MACROSTR(Failed),
  215. MACROSTR(NotSupported),
  216. MACROSTR(VersionMismatch)
  217. };
  218. static char *RemoteStartStopStatusStr[] = {
  219. MACROSTR(Accepted),
  220. MACROSTR(Rejected)
  221. };
  222. static char *ReservationStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Faulted),
  225. MACROSTR(Occupied),
  226. MACROSTR(Rejected),
  227. MACROSTR(Unavailable)
  228. };
  229. static char *ResetTypeStr[] = {
  230. MACROSTR(Hard),
  231. MACROSTR(Soft)
  232. };
  233. static char *ResetStatusStr[] = {
  234. MACROSTR(Accepted),
  235. MACROSTR(Rejected)
  236. };
  237. static char * DiagnosticsStatusStr[] = {
  238. MACROSTR(Idle),
  239. MACROSTR(Uploaded),
  240. MACROSTR(UploadFailed),
  241. MACROSTR(Uploading)
  242. };
  243. static char * FirmwareStatusStr[] = {
  244. MACROSTR(Downloaded),
  245. MACROSTR(DownloadFailed),
  246. MACROSTR(Downloading),
  247. MACROSTR(Idle),
  248. MACROSTR(InstallationFailed),
  249. MACROSTR(Installing),
  250. MACROSTR(Installed)
  251. };
  252. static char * MessageTriggerStr[] = {
  253. MACROSTR(BootNotification),
  254. MACROSTR(DiagnosticsStatusNotification),
  255. MACROSTR(FirmwareStatusNotification),
  256. MACROSTR(Heartbeat),
  257. MACROSTR(MeterValues),
  258. MACROSTR(StatusNotification)
  259. };
  260. static char * TriggerMessageStatusStr[] = {
  261. MACROSTR(Accepted),
  262. MACROSTR(Rejected),
  263. MACROSTR(NotImplemented)
  264. };
  265. static char * UnlockStatusStr[] = {
  266. MACROSTR(Unlocked),
  267. MACROSTR(UnlockFailed),
  268. MACROSTR(NotSupported)
  269. };
  270. #if 0
  271. static char * StopTransactionReasonStr[] = {
  272. MACROSTR(EmergencyStop),
  273. MACROSTR(EVDisconnected),
  274. MACROSTR(HardReset),
  275. MACROSTR(Local),
  276. MACROSTR(Other),
  277. MACROSTR(PowerLoss),
  278. MACROSTR(Reboot),
  279. MACROSTR(Remote),
  280. MACROSTR(SoftReset),
  281. MACROSTR(UnlockCommand),
  282. MACROSTR(DeAuthorized)
  283. };
  284. #endif
  285. static char * CancelReservationStatusStr[] = {
  286. MACROSTR(Accepted),
  287. MACROSTR(Rejected)
  288. };
  289. static char * ReadingContextStr[] = {
  290. MACROSTR(Interruption.Begin),
  291. MACROSTR(Interruption.End),
  292. MACROSTR(Other),
  293. MACROSTR(Sample.Clock),
  294. MACROSTR(Sample.Periodic),
  295. MACROSTR(Transaction.Begin),
  296. MACROSTR(Transaction.End),
  297. MACROSTR(Trigger)
  298. };
  299. static char * ValueFormatStr[] = {
  300. MACROSTR(Raw),
  301. MACROSTR(SignedData)
  302. };
  303. static char * MeasurandStr[] = {
  304. MACROSTR(Current.Export),
  305. MACROSTR(Current.Import),
  306. MACROSTR(Current.Offered),
  307. MACROSTR(Energy.Active.Export.Register),
  308. MACROSTR(Energy.Active.Import.Register),
  309. MACROSTR(Energy.Reactive.Export.Register),
  310. MACROSTR(Energy.Reactive.Import.Register),
  311. MACROSTR(Energy.Active.Export.Interval),
  312. MACROSTR(Energy.Active.Import.Interval),
  313. MACROSTR(Energy.Reactive.Export.Interval),
  314. MACROSTR(Energy.Reactive.Import.Interval),
  315. MACROSTR(Frequency),
  316. MACROSTR(Power.Active.Export),
  317. MACROSTR(Power.Active.Import),
  318. MACROSTR(Power.Factor),
  319. MACROSTR(Power.Offered),
  320. MACROSTR(Power.Reactive.ExportMACROSTR),
  321. MACROSTR(Power.Reactive.Import),
  322. MACROSTR(RPM),
  323. MACROSTR(SoC),
  324. MACROSTR(Temperature),
  325. MACROSTR(Voltage)
  326. };
  327. static char * LocationStr[] = {
  328. MACROSTR(Body),
  329. MACROSTR(Cable),
  330. MACROSTR(EV),
  331. MACROSTR(Inlet),
  332. MACROSTR(Outlet)
  333. };
  334. static char * PhaseStr[] = {
  335. MACROSTR(L1),
  336. MACROSTR(L2),
  337. MACROSTR(L3),
  338. MACROSTR(N),
  339. MACROSTR(L1-N),
  340. MACROSTR(L2-N),
  341. MACROSTR(L3-N),
  342. MACROSTR(L1-L2),
  343. MACROSTR(L2-L3),
  344. MACROSTR(L3-L1)
  345. };
  346. static char * UnitOfMeasureStr[] = {
  347. MACROSTR(Wh),
  348. MACROSTR(kWh),
  349. MACROSTR(varh),
  350. MACROSTR(kvarh),
  351. MACROSTR(W),
  352. MACROSTR(kW),
  353. MACROSTR(VA),
  354. MACROSTR(kVA),
  355. MACROSTR(var),
  356. MACROSTR(kvar),
  357. MACROSTR(A),
  358. MACROSTR(V),
  359. MACROSTR(Celsius),
  360. MACROSTR(Fahrenheit),
  361. MACROSTR(K),
  362. MACROSTR(Percent)
  363. };
  364. //==========================================
  365. // Check time passed since today
  366. //==========================================
  367. long long DiffTimebWithNow(struct timeb ST)
  368. {
  369. //return milli-second
  370. struct timeb ET;
  371. long long StartTime,StopTime;
  372. ftime(&ET);
  373. StartTime=(long long)ST.time;
  374. StopTime=(long long)ET.time;
  375. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  376. }
  377. int getTimePassSinceToday()
  378. {
  379. int result = -1;
  380. time_t t;
  381. struct tm *tmStartToday;
  382. struct timeb tbStartToday;
  383. t=time(NULL);
  384. tmStartToday=localtime(&t);
  385. tmStartToday->tm_hour = 0;
  386. tmStartToday->tm_min = 0;
  387. tmStartToday->tm_sec = 0;
  388. tbStartToday.time = mktime(tmStartToday);
  389. tbStartToday.millitm = 0;
  390. result = DiffTimebWithNow(tbStartToday)/1000;
  391. return result;
  392. }
  393. //==========================================
  394. // GetCompositeSchedule logic related function
  395. //==========================================
  396. int DiffTimebSec(struct timeb ST, struct timeb ET)
  397. {
  398. //return milli-second
  399. unsigned int StartTime,StopTime;
  400. StartTime=(unsigned int)ST.time;
  401. StopTime=(unsigned int)ET.time;
  402. return (StopTime-StartTime);
  403. }
  404. int DiffTimebWithNowSec(struct timeb ST)
  405. {
  406. //return milli-second
  407. struct timeb ET;
  408. unsigned int StartTime,StopTime;
  409. ftime(&ET);
  410. StartTime=(unsigned int)ST.time;
  411. StopTime=(unsigned int)ET.time;
  412. return (StopTime-StartTime);
  413. }
  414. int getStartStop(uint8_t *start, uint8_t *stop)
  415. {
  416. int result = -1;
  417. struct tm tmStart;
  418. struct timeb tbStart;
  419. struct tm tmStop;
  420. struct timeb tbStop;
  421. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  422. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  423. {
  424. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  425. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  426. tmStart.tm_year -= 1900;
  427. tmStart.tm_mon -= 1;
  428. tbStart.time = mktime(&tmStart);
  429. tbStart.millitm = 0;
  430. tmStop.tm_year -= 1900;
  431. tmStop.tm_mon -= 1;
  432. tbStop.time = mktime(&tmStop);
  433. tbStop.millitm = 0;
  434. result = DiffTimebSec(tbStart, tbStop);
  435. //DEBUG_INFO("getStartStop(): %d\n", result);
  436. }
  437. else
  438. {
  439. DEBUG_WARN("Start or stop date parsing error.\r\n");
  440. }
  441. return result;
  442. }
  443. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  444. {
  445. int result = -1;
  446. struct tm tmStart;
  447. struct timeb tbStart;
  448. struct tm tmStop;
  449. struct timeb tbStop;
  450. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  451. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  452. {
  453. tmStart.tm_year -= 1900;
  454. tmStart.tm_mon -= 1;
  455. tbStart.time = mktime(&tmStart);
  456. tbStart.millitm = 0;
  457. tmStop.tm_year -= 1900;
  458. tmStop.tm_mon -= 1;
  459. tbStop.time = mktime(&tmStop);
  460. tbStop.millitm = 0;
  461. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  462. }
  463. return result;
  464. }
  465. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  466. {
  467. FILE *fp;
  468. char profileFileName[128];
  469. char *line = NULL;
  470. size_t len = 0;
  471. time_t CurrentTime;
  472. struct tm *tmComposite;
  473. struct StructChargingProfile maxProfile;
  474. struct StructChargingProfile defaultTxProfile;
  475. struct StructChargingProfile txProfile;
  476. struct StructChargingSchedulePeriod tmpPeriod;
  477. uint8_t limitMax=0;
  478. uint8_t limitDef=0;
  479. uint8_t limitTx=0;
  480. int compositePeriodIdx = 0;
  481. CurrentTime = time(NULL);
  482. tmComposite=localtime(&CurrentTime);
  483. sprintf((char*)compositeProfile->ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  484. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  485. compositeProfile->ChargingSchedule.Duration = durationReq;
  486. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  487. {
  488. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  489. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  490. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  491. }
  492. compositeProfile->ChargingProfileId = 0;
  493. compositeProfile->StackLevel = 99 ;
  494. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  495. maxProfile.ChargingProfileId = -1;
  496. defaultTxProfile.ChargingProfileId = -1;
  497. txProfile.ChargingProfileId = -1;
  498. maxProfile.ChargingSchedule.Duration = -1;
  499. defaultTxProfile.ChargingSchedule.Duration = -1;
  500. txProfile.ChargingSchedule.Duration = -1;
  501. system("yes|rm /tmp/*.json");
  502. system("cp /Storage/OCPP/*.json /tmp");
  503. /*
  504. * Search valid charging profile
  505. */
  506. //DEBUG_INFO("====================================\n");
  507. // Search tx profile
  508. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  509. if((access(profileFileName, F_OK))!=-1)
  510. {
  511. fp = fopen(profileFileName, "r");
  512. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  513. {
  514. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  515. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  516. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  517. }
  518. txProfile.ChargingProfileId = -1;
  519. txProfile.StackLevel = -1;
  520. while(getline(&line, &len, fp) != -1)
  521. {
  522. json_object *obj = NULL;
  523. obj = json_tokener_parse(line);
  524. if(is_error(obj))
  525. {
  526. DEBUG_ERROR("Parse txProfile from file error.\n");
  527. }
  528. else
  529. {
  530. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  531. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  532. )
  533. {
  534. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  535. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  536. )
  537. {
  538. struct tm tmFrom, tmTo;
  539. struct timeb tbFrom, tbTo;
  540. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  541. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  542. {
  543. tmFrom.tm_year -= 1900;
  544. tmFrom.tm_mon -= 1;
  545. tbFrom.time = mktime(&tmFrom);
  546. tmTo.tm_year -= 1900;
  547. tmTo.tm_mon -= 1;
  548. tbTo.time = mktime(&tmTo);
  549. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  550. {
  551. if(txProfile.ChargingProfileId == -1)
  552. DEBUG_INFO("TxProfile found.\n");
  553. else
  554. DEBUG_INFO("TxProfile updated.\n");
  555. // Required item
  556. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  557. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  558. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  559. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  560. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  561. {
  562. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  563. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  564. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  565. 3:
  566. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  567. }
  568. // Optional item
  569. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  570. {
  571. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  572. }
  573. else
  574. {
  575. sprintf((char*)txProfile.ValidFrom, " ");
  576. }
  577. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  578. {
  579. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  580. }
  581. else
  582. {
  583. sprintf((char*)txProfile.ValidTo, " ");
  584. }
  585. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  586. {
  587. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  588. }
  589. else
  590. {
  591. sprintf((char*)txProfile.RecurrencyKind, " ");
  592. }
  593. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  594. {
  595. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  596. }
  597. else
  598. {
  599. txProfile.TransactionId = -1;
  600. }
  601. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  602. {
  603. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  604. }
  605. else
  606. {
  607. txProfile.ChargingSchedule.Duration = 86400;
  608. }
  609. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  610. {
  611. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  612. }
  613. else
  614. {
  615. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  616. }
  617. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  618. {
  619. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  620. }
  621. else
  622. {
  623. txProfile.ChargingSchedule.MinChargingRate = -1;
  624. }
  625. }
  626. }
  627. }
  628. else
  629. {
  630. if(txProfile.ChargingProfileId == -1)
  631. DEBUG_INFO("TxProfile found.\n");
  632. else
  633. DEBUG_INFO("TxProfile updated.\n");
  634. // Required item
  635. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  636. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  637. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  638. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  639. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  640. {
  641. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  642. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  643. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  644. 3:
  645. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  646. }
  647. // Optional item
  648. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  649. {
  650. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  651. }
  652. else
  653. {
  654. sprintf((char*)txProfile.ValidFrom, " ");
  655. }
  656. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  657. {
  658. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  659. }
  660. else
  661. {
  662. sprintf((char*)txProfile.ValidTo, " ");
  663. }
  664. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  665. {
  666. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  667. }
  668. else
  669. {
  670. sprintf((char*)txProfile.RecurrencyKind, " ");
  671. }
  672. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  673. {
  674. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  675. }
  676. else
  677. {
  678. txProfile.TransactionId = -1;
  679. }
  680. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  681. {
  682. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  683. }
  684. else
  685. {
  686. txProfile.ChargingSchedule.Duration = 86400;
  687. }
  688. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  689. {
  690. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  691. }
  692. else
  693. {
  694. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  695. }
  696. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  697. {
  698. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  699. }
  700. else
  701. {
  702. txProfile.ChargingSchedule.MinChargingRate = -1;
  703. }
  704. }
  705. }
  706. }
  707. json_object_put(obj);
  708. }
  709. fclose(fp);
  710. /*
  711. if(txProfile.ChargingProfileId != -1)
  712. {
  713. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  714. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  715. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  716. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  717. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  718. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  719. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  720. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  721. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  722. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  723. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  724. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  725. {
  726. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  727. {
  728. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  729. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  730. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  731. }
  732. }
  733. }
  734. else
  735. DEBUG_INFO("TxProfile not found.\n");*/
  736. }
  737. // Search default tx profile
  738. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  739. if((access(profileFileName, F_OK))==-1)
  740. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  741. if((access(profileFileName, F_OK))!=-1)
  742. {
  743. fp = fopen(profileFileName, "r");
  744. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  745. {
  746. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  747. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  748. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  749. }
  750. defaultTxProfile.ChargingProfileId = -1;
  751. defaultTxProfile.StackLevel = -1;
  752. while(getline(&line, &len, fp) != -1)
  753. {
  754. json_object *obj = NULL;
  755. obj = json_tokener_parse(line);
  756. if(is_error(obj))
  757. {
  758. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  759. }
  760. else
  761. {
  762. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  763. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  764. )
  765. {
  766. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  767. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  768. )
  769. {
  770. struct tm tmFrom, tmTo;
  771. struct timeb tbFrom, tbTo;
  772. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  773. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  774. {
  775. tmFrom.tm_year -= 1900;
  776. tmFrom.tm_mon -= 1;
  777. tbFrom.time = mktime(&tmFrom);
  778. tmTo.tm_year -= 1900;
  779. tmTo.tm_mon -= 1;
  780. tbTo.time = mktime(&tmTo);
  781. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  782. {
  783. if(defaultTxProfile.ChargingProfileId == -1)
  784. DEBUG_INFO("TxDefaultProfile found.\n");
  785. else
  786. DEBUG_INFO("TxDefaultProfile updated.\n");
  787. // Required item
  788. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  789. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  790. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  791. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  792. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  793. {
  794. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  795. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  796. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  797. 3:
  798. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  799. }
  800. // Optional item
  801. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  802. {
  803. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  804. }
  805. else
  806. {
  807. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  808. }
  809. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  810. {
  811. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  812. }
  813. else
  814. {
  815. sprintf((char*)defaultTxProfile.ValidTo, " ");
  816. }
  817. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  818. {
  819. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  820. }
  821. else
  822. {
  823. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  824. }
  825. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  826. {
  827. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  828. }
  829. else
  830. {
  831. defaultTxProfile.TransactionId = -1;
  832. }
  833. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  834. {
  835. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  836. }
  837. else
  838. {
  839. defaultTxProfile.ChargingSchedule.Duration = 86400;
  840. }
  841. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  842. {
  843. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  844. }
  845. else
  846. {
  847. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  848. }
  849. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  850. {
  851. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  852. }
  853. else
  854. {
  855. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  856. }
  857. }
  858. }
  859. }
  860. else
  861. {
  862. if(defaultTxProfile.ChargingProfileId == -1)
  863. DEBUG_INFO("TxDefaultProfile found.\n");
  864. else
  865. DEBUG_INFO("TxDefaultProfile updated.\n");
  866. // Required item
  867. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  868. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  869. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  870. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  871. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  872. {
  873. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  874. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  875. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  876. 3:
  877. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  878. }
  879. // Optional item
  880. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  881. {
  882. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  883. }
  884. else
  885. {
  886. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  887. }
  888. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  889. {
  890. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  891. }
  892. else
  893. {
  894. sprintf((char*)defaultTxProfile.ValidTo, " ");
  895. }
  896. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  897. {
  898. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  899. }
  900. else
  901. {
  902. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  903. }
  904. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  905. {
  906. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  907. }
  908. else
  909. {
  910. defaultTxProfile.TransactionId = -1;
  911. }
  912. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  913. {
  914. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  915. }
  916. else
  917. {
  918. defaultTxProfile.ChargingSchedule.Duration = 86400;
  919. }
  920. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  921. {
  922. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  923. }
  924. else
  925. {
  926. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  927. }
  928. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  929. {
  930. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  931. }
  932. else
  933. {
  934. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  935. }
  936. }
  937. }
  938. }
  939. json_object_put(obj);
  940. }
  941. fclose(fp);
  942. /*
  943. if(defaultTxProfile.ChargingProfileId != -1)
  944. {
  945. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  946. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  947. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  948. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  949. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  950. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  951. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  952. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  953. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  954. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  955. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  956. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  957. {
  958. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  959. {
  960. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  961. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  962. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  963. }
  964. }
  965. }
  966. else
  967. DEBUG_INFO("TxDefaultProfile not found.\n");
  968. DEBUG_INFO("------------------------------------\n");*/
  969. }
  970. // Search max profile
  971. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  972. if((access(profileFileName, F_OK))!=-1)
  973. {
  974. fp = fopen(profileFileName, "r");
  975. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  976. {
  977. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  978. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  979. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  980. }
  981. maxProfile.ChargingProfileId = -1;
  982. maxProfile.StackLevel = -1;
  983. while(getline(&line, &len, fp) != -1)
  984. {
  985. json_object *obj = NULL;
  986. obj = json_tokener_parse(line);
  987. if(is_error(obj))
  988. {
  989. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  990. }
  991. else
  992. {
  993. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  994. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  995. )
  996. {
  997. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  998. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  999. )
  1000. {
  1001. struct tm tmFrom, tmTo;
  1002. struct timeb tbFrom, tbTo;
  1003. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1004. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1005. {
  1006. tmFrom.tm_year -= 1900;
  1007. tmFrom.tm_mon -= 1;
  1008. tbFrom.time = mktime(&tmFrom);
  1009. tmTo.tm_year -= 1900;
  1010. tmTo.tm_mon -= 1;
  1011. tbTo.time = mktime(&tmTo);
  1012. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1013. {
  1014. if(maxProfile.ChargingProfileId == -1)
  1015. DEBUG_INFO("MaxProfile found.\n");
  1016. else
  1017. DEBUG_INFO("MaxProfile updated.\n");
  1018. // Required item
  1019. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1020. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1021. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1022. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1023. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1024. {
  1025. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1026. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1027. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1028. 3:
  1029. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1030. }
  1031. // Optional item
  1032. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1033. {
  1034. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1035. }
  1036. else
  1037. {
  1038. sprintf((char*)maxProfile.ValidFrom, " ");
  1039. }
  1040. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1041. {
  1042. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1043. }
  1044. else
  1045. {
  1046. sprintf((char*)maxProfile.ValidTo, " ");
  1047. }
  1048. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1049. {
  1050. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1051. }
  1052. else
  1053. {
  1054. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1055. }
  1056. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1057. {
  1058. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1059. }
  1060. else
  1061. {
  1062. maxProfile.TransactionId = -1;
  1063. }
  1064. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1065. {
  1066. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1067. }
  1068. else
  1069. {
  1070. maxProfile.ChargingSchedule.Duration = 86400;
  1071. }
  1072. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1073. {
  1074. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1075. }
  1076. else
  1077. {
  1078. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1079. }
  1080. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1081. {
  1082. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1083. }
  1084. else
  1085. {
  1086. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1087. }
  1088. }
  1089. }
  1090. }
  1091. else
  1092. {
  1093. if(maxProfile.ChargingProfileId == -1)
  1094. DEBUG_INFO("MaxProfile found.\n");
  1095. else
  1096. DEBUG_INFO("MaxProfile updated.\n");
  1097. // Required item
  1098. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1099. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1100. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1101. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1102. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1103. {
  1104. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1105. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1106. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1107. 3:
  1108. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1109. }
  1110. // Optional item
  1111. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1112. {
  1113. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1114. }
  1115. else
  1116. {
  1117. sprintf((char*)maxProfile.ValidFrom, " ");
  1118. }
  1119. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1120. {
  1121. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1122. }
  1123. else
  1124. {
  1125. sprintf((char*)maxProfile.ValidTo, " ");
  1126. }
  1127. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1128. {
  1129. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1130. }
  1131. else
  1132. {
  1133. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1134. }
  1135. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1136. {
  1137. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1138. }
  1139. else
  1140. {
  1141. maxProfile.TransactionId = -1;
  1142. }
  1143. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1144. {
  1145. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1146. }
  1147. else
  1148. {
  1149. maxProfile.ChargingSchedule.Duration = 86400;
  1150. }
  1151. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1152. {
  1153. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1154. }
  1155. else
  1156. {
  1157. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1158. }
  1159. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1160. {
  1161. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1162. }
  1163. else
  1164. {
  1165. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1166. }
  1167. }
  1168. }
  1169. }
  1170. json_object_put(obj);
  1171. }
  1172. fclose(fp);
  1173. /*
  1174. if(maxProfile.ChargingProfileId !=-1)
  1175. {
  1176. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1177. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1178. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1179. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1180. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1181. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1182. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1183. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1184. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1185. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1186. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1187. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1188. {
  1189. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1190. {
  1191. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1192. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1193. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1194. }
  1195. }
  1196. }
  1197. else
  1198. DEBUG_INFO("MaxProfile not found.\n");
  1199. DEBUG_INFO("------------------------------------\n");*/
  1200. }
  1201. /*
  1202. * Align found profile start schedule & periods
  1203. */
  1204. //DEBUG_INFO("====================================\n");
  1205. /*
  1206. // For local test usage, force modify found profile start schedule info
  1207. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-10);
  1208. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-5);
  1209. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-3);
  1210. */
  1211. if(txProfile.ChargingProfileId != -1)
  1212. {
  1213. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1214. {
  1215. if(txProfile.ChargingSchedule.Duration != -1)
  1216. {
  1217. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1218. 0:
  1219. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1220. }
  1221. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1222. {
  1223. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1224. {
  1225. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1226. 0:
  1227. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1228. if(idxPeriod > 0)
  1229. {
  1230. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1231. {
  1232. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1233. }
  1234. }
  1235. }
  1236. }
  1237. }
  1238. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1239. {
  1240. if(txProfile.ChargingSchedule.Duration != -1)
  1241. {
  1242. txProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1243. 0:
  1244. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1245. }
  1246. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1247. {
  1248. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1249. {
  1250. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1251. 0:
  1252. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1253. if(idxPeriod > 0)
  1254. {
  1255. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1256. {
  1257. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1258. }
  1259. }
  1260. }
  1261. }
  1262. }
  1263. else
  1264. {
  1265. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1266. {
  1267. if(txProfile.ChargingSchedule.Duration != -1)
  1268. {
  1269. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1270. 0:
  1271. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1272. }
  1273. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1274. {
  1275. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1276. {
  1277. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1278. 0:
  1279. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1280. if(idxPeriod > 0)
  1281. {
  1282. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1283. {
  1284. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1285. }
  1286. }
  1287. }
  1288. }
  1289. }
  1290. else
  1291. {
  1292. if(txProfile.ChargingSchedule.Duration != -1)
  1293. {
  1294. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1295. 0:
  1296. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1297. }
  1298. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1299. {
  1300. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1301. {
  1302. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1303. 0:
  1304. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1305. if(idxPeriod > 0)
  1306. {
  1307. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1308. {
  1309. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1310. }
  1311. }
  1312. }
  1313. }
  1314. }
  1315. }
  1316. /*
  1317. DEBUG_INFO("txProfile after align.\n");
  1318. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1319. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1320. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1321. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1322. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1323. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1324. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1325. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1326. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1327. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1328. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1329. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1330. {
  1331. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1332. {
  1333. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1334. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1335. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1336. }
  1337. }*/
  1338. }
  1339. if(defaultTxProfile.ChargingProfileId != -1)
  1340. {
  1341. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1342. {
  1343. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1344. {
  1345. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1346. 0:
  1347. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1348. }
  1349. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1350. {
  1351. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1352. {
  1353. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1354. 0:
  1355. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1356. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1357. {
  1358. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1359. }
  1360. if(idxPeriod > 0)
  1361. {
  1362. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1363. {
  1364. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1365. }
  1366. }
  1367. }
  1368. }
  1369. }
  1370. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1371. {
  1372. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1373. {
  1374. defaultTxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1375. 0:
  1376. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1377. }
  1378. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1379. {
  1380. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1381. {
  1382. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1383. 0:
  1384. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1385. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1386. {
  1387. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1388. }
  1389. if(idxPeriod > 0)
  1390. {
  1391. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1392. {
  1393. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1394. }
  1395. }
  1396. }
  1397. }
  1398. }
  1399. else
  1400. {
  1401. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1402. {
  1403. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1404. {
  1405. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1406. 0:
  1407. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1408. }
  1409. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1410. {
  1411. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1412. {
  1413. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1414. 0:
  1415. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1416. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1417. {
  1418. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1419. }
  1420. if(idxPeriod > 0)
  1421. {
  1422. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1423. {
  1424. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1425. }
  1426. }
  1427. }
  1428. }
  1429. }
  1430. else
  1431. {
  1432. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1433. {
  1434. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1435. 0:
  1436. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1437. }
  1438. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1439. {
  1440. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1441. {
  1442. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1443. 0:
  1444. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1445. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1446. {
  1447. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1448. }
  1449. if(idxPeriod > 0)
  1450. {
  1451. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1452. {
  1453. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1454. }
  1455. }
  1456. }
  1457. }
  1458. }
  1459. }
  1460. /*
  1461. DEBUG_INFO("defaultTxProfile after align.\n");
  1462. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1463. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1464. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1465. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1466. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1467. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1468. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1469. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1470. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1471. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1472. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1473. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1474. {
  1475. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1476. {
  1477. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1478. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1479. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1480. }
  1481. }
  1482. DEBUG_INFO("------------------------------------\n");*/
  1483. }
  1484. if(maxProfile.ChargingProfileId != -1)
  1485. {
  1486. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1487. {
  1488. if(maxProfile.ChargingSchedule.Duration != -1)
  1489. {
  1490. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1491. 0:
  1492. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1493. }
  1494. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1495. {
  1496. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1497. {
  1498. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1499. 0:
  1500. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1501. if(idxPeriod > 0)
  1502. {
  1503. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1504. {
  1505. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1506. }
  1507. }
  1508. }
  1509. }
  1510. }
  1511. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1512. {
  1513. if(maxProfile.ChargingSchedule.Duration != -1)
  1514. {
  1515. maxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1516. 0:
  1517. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1518. }
  1519. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1520. {
  1521. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1522. {
  1523. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1524. 0:
  1525. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1526. if(idxPeriod > 0)
  1527. {
  1528. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1529. {
  1530. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1531. }
  1532. }
  1533. }
  1534. }
  1535. }
  1536. else
  1537. {
  1538. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1539. {
  1540. if(maxProfile.ChargingSchedule.Duration != -1)
  1541. {
  1542. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1543. 0:
  1544. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1545. }
  1546. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1547. {
  1548. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1549. {
  1550. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1551. 0:
  1552. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1553. if(idxPeriod > 0)
  1554. {
  1555. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1556. {
  1557. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1558. }
  1559. }
  1560. }
  1561. }
  1562. }
  1563. else
  1564. {
  1565. if(maxProfile.ChargingSchedule.Duration != -1)
  1566. {
  1567. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1568. 0:
  1569. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1570. }
  1571. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1572. {
  1573. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1574. {
  1575. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1576. 0:
  1577. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1578. if(idxPeriod > 0)
  1579. {
  1580. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1581. {
  1582. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1583. }
  1584. }
  1585. }
  1586. }
  1587. }
  1588. }
  1589. /*
  1590. DEBUG_INFO("MaxProfile after align.\n");
  1591. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1592. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1593. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1594. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1595. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1596. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1597. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1598. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1599. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1600. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1601. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1602. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1603. {
  1604. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1605. {
  1606. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1607. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1608. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1609. }
  1610. }
  1611. DEBUG_INFO("------------------------------------\n");*/
  1612. }
  1613. /*
  1614. * Merge to conposite schedule
  1615. */
  1616. //DEBUG_INFO("====================================\n");
  1617. // Find each profile period quantity
  1618. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1619. {
  1620. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1621. limitMax = idx+1;
  1622. }
  1623. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1624. {
  1625. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1626. limitDef = idx+1;
  1627. }
  1628. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1629. {
  1630. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1631. limitTx = idx+1;
  1632. }
  1633. // TxProfile found, composite schedule based on it
  1634. if(txProfile.ChargingProfileId != -1)
  1635. {
  1636. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1637. {
  1638. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1639. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  1640. (txProfile.ChargingSchedule.Duration > 0))
  1641. {
  1642. if(maxProfile.ChargingProfileId != -1)
  1643. {
  1644. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1645. {
  1646. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  1647. {
  1648. if((maxProfile.ChargingSchedule.Duration > 0))
  1649. {
  1650. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1651. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1652. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1653. }
  1654. else
  1655. {
  1656. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1657. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1658. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  1659. }
  1660. }
  1661. if(idxMaxPeriod == (limitMax-1))
  1662. {
  1663. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1664. {
  1665. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1666. {
  1667. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1668. compositePeriodIdx++;
  1669. }
  1670. else
  1671. {
  1672. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1673. }
  1674. }
  1675. }
  1676. }
  1677. }
  1678. else
  1679. {
  1680. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1681. {
  1682. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1683. compositePeriodIdx++;
  1684. }
  1685. else
  1686. {
  1687. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1688. }
  1689. }
  1690. }
  1691. if(idxTxPeriod == (limitTx-1))
  1692. {
  1693. if(defaultTxProfile.ChargingProfileId != -1)
  1694. {
  1695. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1696. {
  1697. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  1698. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1699. (defaultTxProfile.ChargingSchedule.Duration>0))
  1700. {
  1701. if(maxProfile.ChargingProfileId != -1)
  1702. {
  1703. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1704. {
  1705. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1706. {
  1707. if((maxProfile.ChargingSchedule.Duration > 0))
  1708. {
  1709. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1710. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1711. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1712. }
  1713. else
  1714. {
  1715. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1716. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1717. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1718. }
  1719. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1720. {
  1721. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1722. {
  1723. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1724. compositePeriodIdx++;
  1725. }
  1726. else
  1727. {
  1728. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1729. }
  1730. }
  1731. break;
  1732. }
  1733. }
  1734. }
  1735. else
  1736. {
  1737. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1738. {
  1739. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1740. compositePeriodIdx++;
  1741. }
  1742. else
  1743. {
  1744. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1745. }
  1746. }
  1747. }
  1748. }
  1749. }
  1750. }
  1751. }
  1752. }
  1753. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1754. else if(defaultTxProfile.ChargingProfileId != -1)
  1755. {
  1756. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1757. {
  1758. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1759. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1760. (defaultTxProfile.ChargingSchedule.Duration > 0))
  1761. {
  1762. if(maxProfile.ChargingProfileId != -1)
  1763. {
  1764. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1765. {
  1766. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1767. {
  1768. if((maxProfile.ChargingSchedule.Duration > 0))
  1769. {
  1770. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1771. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1772. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1773. }
  1774. else
  1775. {
  1776. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1777. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1778. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1779. }
  1780. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1781. {
  1782. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1783. {
  1784. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1785. compositePeriodIdx++;
  1786. }
  1787. else
  1788. {
  1789. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1790. }
  1791. }
  1792. break;
  1793. }
  1794. }
  1795. }
  1796. else
  1797. {
  1798. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1799. {
  1800. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1801. compositePeriodIdx++;
  1802. }
  1803. else
  1804. {
  1805. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1806. }
  1807. }
  1808. }
  1809. }
  1810. }
  1811. // Fill other period by MaxProfile
  1812. if(maxProfile.ChargingProfileId != -1)
  1813. {
  1814. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1815. {
  1816. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1817. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1818. (maxProfile.ChargingSchedule.Duration > 0))
  1819. {
  1820. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  1821. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1822. {
  1823. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  1824. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  1825. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1826. }
  1827. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1828. {
  1829. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  1830. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  1831. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1832. }
  1833. if(tmpPeriod.Limit != -1)
  1834. {
  1835. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1836. {
  1837. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1838. {
  1839. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1840. compositePeriodIdx++;
  1841. }
  1842. else
  1843. {
  1844. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1845. }
  1846. }
  1847. }
  1848. }
  1849. }
  1850. }
  1851. DEBUG_INFO("Composite schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1852. DEBUG_INFO("Composite schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1853. DEBUG_INFO("Composite rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1854. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1855. {
  1856. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1857. {
  1858. compositeProfile->ChargingProfileId = 1;
  1859. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1860. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1861. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1862. }
  1863. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1864. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1865. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1866. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1867. }
  1868. if(line)
  1869. free(line);
  1870. }
  1871. //==========================================
  1872. // Init all share memory
  1873. //==========================================
  1874. int InitShareMemory()
  1875. {
  1876. int result = PASS;
  1877. int MeterSMId;
  1878. //creat ShmSysConfigAndInfo
  1879. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1880. {
  1881. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1882. result = FAIL;
  1883. }
  1884. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1885. {
  1886. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  1887. result = FAIL;
  1888. }
  1889. else
  1890. {}
  1891. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1892. {
  1893. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1894. result = FAIL;
  1895. }
  1896. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1897. {
  1898. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1899. result = FAIL;
  1900. }
  1901. else
  1902. {}
  1903. //creat ShmPsuData
  1904. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  1905. {
  1906. DEBUG_ERROR("shmget ShmPsuData NG\n");
  1907. result = FAIL;
  1908. }
  1909. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1910. {
  1911. DEBUG_ERROR("shmat ShmPsuData NG\n");
  1912. result = FAIL;
  1913. }
  1914. else
  1915. {}
  1916. //creat ShmOCPP16Data
  1917. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1918. {
  1919. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  1920. result = FAIL;
  1921. }
  1922. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1923. {
  1924. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  1925. result = FAIL;
  1926. }
  1927. else
  1928. {}
  1929. /****************************** For Initial Settings************************************************/
  1930. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  1931. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  1932. // allocate Configuration memory address
  1933. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  1934. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  1935. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  1936. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  1937. //offline MeterValue Interval
  1938. TempMeterValueInterval = 0;
  1939. return result;
  1940. }
  1941. int ProcessShareMemory()
  1942. {
  1943. if(InitShareMemory() == FAIL)
  1944. {
  1945. DEBUG_ERROR("InitShareMemory NG\n");
  1946. if(ShmStatusCodeData!=NULL)
  1947. {
  1948. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1949. }
  1950. sleep(5);
  1951. return FAIL;
  1952. }
  1953. return PASS;
  1954. }
  1955. //---------------------common routine---------------------------//
  1956. int isOFFline(void)
  1957. {
  1958. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  1959. {
  1960. if(TempMeterValueInterval >= 2 )
  1961. {
  1962. TempMeterValueInterval = 0;
  1963. return TRUE;
  1964. }
  1965. else
  1966. {
  1967. TempMeterValueInterval = TempMeterValueInterval+ 1;
  1968. return FALSE;
  1969. }
  1970. }
  1971. else
  1972. {
  1973. return FALSE;
  1974. }
  1975. }
  1976. //---------------------------------------------
  1977. // new:
  1978. // enum SYSTEM_STATUS
  1979. // {
  1980. // SYS_MODE_BOOTING = 0,
  1981. // SYS_MODE_IDLE = 1,
  1982. // SYS_MODE_AUTHORIZING = 2,
  1983. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  1984. // SYS_MODE_REASSIGN = 4,
  1985. // SYS_MODE_PREPARING = 5,
  1986. // SYS_MODE_PREPARE_FOR_EV = 6,
  1987. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  1988. // SYS_MODE_CHARGING = 8,
  1989. // SYS_MODE_TERMINATING = 9,
  1990. // SYS_MODE_COMPLETE = 10,
  1991. // SYS_MODE_ALARM = 11,
  1992. // SYS_MODE_FAULT = 12,
  1993. // SYS_MODE_RESERVATION = 13,
  1994. // SYS_MODE_BOOKING = 14,
  1995. // SYS_MODE_MAINTAIN = 15,
  1996. // SYS_MODE_DEBUG = 16,
  1997. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  1998. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  1999. // SYS_MODE_UPDATE = 19
  2000. // };
  2001. //
  2002. //
  2003. //-----------------------------------------
  2004. void CheckSystemValue(void)
  2005. {
  2006. uint8_t reqSampleMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2007. uint8_t reqClockAlignMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2008. char filenmae[100]={0};
  2009. char str[100]={0};
  2010. int tempIndex = 0;
  2011. //===============================
  2012. // send Heartbeat
  2013. //===============================
  2014. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2015. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2016. {
  2017. clientTime.Heartbeat=time((time_t*)NULL);
  2018. if(server_sign == TRUE)
  2019. {
  2020. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2021. }
  2022. else
  2023. {
  2024. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2025. }
  2026. }
  2027. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  2028. {
  2029. //parameter for test
  2030. sendHeartbeatRequest(0);
  2031. //==============================================
  2032. // Reset Waiting Time
  2033. //==============================================
  2034. clientTime.Heartbeat=time((time_t*)NULL);
  2035. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  2036. }
  2037. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2038. {
  2039. //===============================
  2040. // CSU Trigger Reset Conf
  2041. //===============================
  2042. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2043. {
  2044. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2045. }
  2046. //===============================
  2047. // CSU Trigger Authorize Request
  2048. //===============================
  2049. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2050. {
  2051. sendAuthorizeRequest(0);
  2052. authorizeRetryTimes = authorizeRetryTimes + 1;
  2053. if(authorizeRetryTimes < 3)
  2054. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2055. }
  2056. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2057. {
  2058. authorizeRetryTimes = 0;
  2059. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  2060. server_sign = FALSE;
  2061. }
  2062. else if((server_sign == FALSE) && (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0)&& (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1))
  2063. {
  2064. sendAuthorizeRequest(0);
  2065. }
  2066. //===============================
  2067. // CSU Trigger Smart Charging Profilw
  2068. //===============================
  2069. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2070. {
  2071. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  2072. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2073. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  2074. }
  2075. //==============================================
  2076. // Charger start transaction
  2077. //==============================================
  2078. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2079. {
  2080. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  2081. sendStartTransactionRequest(gun_index);
  2082. clientTime.StartTransaction = time((time_t*)NULL);
  2083. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2084. }
  2085. //==============================================
  2086. // Charger stop transaction
  2087. //==============================================
  2088. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2089. {
  2090. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  2091. sendStopTransactionRequest(gun_index);
  2092. clientTime.StopTransaction = time((time_t*)NULL);
  2093. }
  2094. //==============================================
  2095. // Charger status report
  2096. //==============================================
  2097. //--- Check Mode Change ---//
  2098. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2099. if(gunType[gun_index] == 'J')
  2100. {
  2101. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2102. {
  2103. tempIndex = ((gun_index==2) ? 1: 0);
  2104. }
  2105. else
  2106. {
  2107. tempIndex = gun_index;
  2108. }
  2109. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2110. {
  2111. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2112. {
  2113. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2114. {
  2115. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2116. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2117. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2118. statusModeChage[gun_index] = TRUE;
  2119. }
  2120. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2121. {
  2122. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2123. if((access(filenmae,F_OK))!=-1)
  2124. {
  2125. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2126. sprintf(str,"rm -f %s",filenmae);
  2127. system(str);
  2128. }
  2129. }
  2130. #if 1 // for TempStopTransaction
  2131. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2132. {
  2133. checkTempStopTransaction(gun_index);
  2134. }
  2135. #endif
  2136. }
  2137. }
  2138. }
  2139. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2140. {
  2141. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2142. {
  2143. tempIndex = ((gun_index==2) ? 1: 0);
  2144. }
  2145. else
  2146. {
  2147. tempIndex = gun_index;
  2148. }
  2149. for (int index = 0; index < CCS_QUANTITY; index++)
  2150. {
  2151. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2152. {
  2153. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  2154. {
  2155. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2156. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2157. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2158. statusModeChage[gun_index] = TRUE;
  2159. }
  2160. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2161. {
  2162. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2163. if((access(filenmae,F_OK))!=-1)
  2164. {
  2165. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2166. sprintf(str,"rm -f %s",filenmae);
  2167. system(str);
  2168. }
  2169. }
  2170. #if 1 // for TempStopTransaction
  2171. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2172. {
  2173. checkTempStopTransaction(gun_index);
  2174. }
  2175. #endif
  2176. }
  2177. }
  2178. }
  2179. else if(gunType[gun_index] == 'G')
  2180. {
  2181. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2182. {
  2183. tempIndex = ((gun_index==2) ? 1: 0);
  2184. }
  2185. else
  2186. {
  2187. tempIndex = gun_index;
  2188. }
  2189. for (int index = 0; index < GB_QUANTITY; index++)
  2190. {
  2191. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2192. {
  2193. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2194. {
  2195. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2196. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2197. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2198. statusModeChage[gun_index] = TRUE;
  2199. }
  2200. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2201. {
  2202. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2203. if((access(filenmae,F_OK))!=-1)
  2204. {
  2205. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2206. sprintf(str,"rm -f %s",filenmae);
  2207. system(str);
  2208. }
  2209. }
  2210. #if 1 // for TempStopTransaction
  2211. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2212. {
  2213. checkTempStopTransaction(gun_index);
  2214. }
  2215. #endif
  2216. }
  2217. }
  2218. }
  2219. else
  2220. {
  2221. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2222. {
  2223. tempIndex = 2;
  2224. }
  2225. else
  2226. {
  2227. tempIndex = gun_index;
  2228. }
  2229. for (int index = 0; index < AC_QUANTITY; index++)
  2230. {
  2231. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2232. {
  2233. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2234. {
  2235. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2236. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2237. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2238. statusModeChage[gun_index] = TRUE;
  2239. }
  2240. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2241. {
  2242. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2243. if((access(filenmae,F_OK))!=-1)
  2244. {
  2245. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2246. sprintf(str,"rm -f %s",filenmae);
  2247. system(str);
  2248. }
  2249. }
  2250. #if 1 // for TempStopTransaction
  2251. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2252. {
  2253. checkTempStopTransaction(gun_index);
  2254. }
  2255. #endif
  2256. }
  2257. }// END
  2258. }
  2259. if(isWebsocketSendable &&
  2260. (((statusModeChage[gun_index] == TRUE) || ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 10)))) )
  2261. {
  2262. if(SystemInitial > 0)
  2263. SystemInitial -= 1;
  2264. sendStatusNotificationRequest(gun_index);
  2265. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2266. statusModeChage[gun_index] = FALSE;
  2267. }
  2268. //==============================================
  2269. // Meter report
  2270. //==============================================
  2271. if(cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2272. {
  2273. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2274. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2275. }
  2276. if(/*(server_sign == TRUE) &&(isOFFline() == TRUE) ||*/
  2277. (((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1)) || ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE)))
  2278. {
  2279. //check Transaction active
  2280. if(gunType[gun_index] == 'J')
  2281. {
  2282. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2283. {
  2284. tempIndex = ((gun_index==2) ? 1: 0);
  2285. }
  2286. else
  2287. {
  2288. tempIndex = gun_index;
  2289. }
  2290. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2291. {
  2292. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2293. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2294. {
  2295. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2296. {
  2297. reqSampleMeter[gun_index] = 1;
  2298. }
  2299. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2300. {
  2301. reqClockAlignMeter[gun_index] = 1;
  2302. }
  2303. }
  2304. }// End for CHAdeMO
  2305. }
  2306. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2307. {
  2308. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2309. {
  2310. tempIndex = ((gun_index==2) ? 1: 0);
  2311. }
  2312. else
  2313. {
  2314. tempIndex = gun_index;
  2315. }
  2316. for (int index = 0; index < CCS_QUANTITY; index++)
  2317. {
  2318. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2319. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2320. {
  2321. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2322. {
  2323. reqSampleMeter[gun_index] = 1;
  2324. }
  2325. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2326. {
  2327. reqClockAlignMeter[gun_index] = 1;
  2328. }
  2329. }
  2330. } // End for CCS
  2331. }
  2332. else if(gunType[gun_index] == 'G')
  2333. {
  2334. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2335. {
  2336. tempIndex = ((gun_index==2) ? 1: 0);
  2337. }
  2338. else
  2339. {
  2340. tempIndex = gun_index;
  2341. }
  2342. for (int index = 0; index < GB_QUANTITY; index++)
  2343. {
  2344. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2345. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2346. {
  2347. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2348. {
  2349. reqSampleMeter[gun_index] = 1;
  2350. }
  2351. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2352. {
  2353. reqClockAlignMeter[gun_index] = 1;
  2354. }
  2355. }
  2356. }// End for GB
  2357. }
  2358. else
  2359. {
  2360. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2361. {
  2362. tempIndex = 2;
  2363. }
  2364. else
  2365. {
  2366. tempIndex = gun_index;
  2367. }
  2368. for (int index = 0; index < AC_QUANTITY; index++)
  2369. {
  2370. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2371. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2372. {
  2373. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2374. {
  2375. reqSampleMeter[gun_index] = 1;
  2376. }
  2377. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2378. {
  2379. reqClockAlignMeter[gun_index] = 1;
  2380. }
  2381. }
  2382. }//End for AC
  2383. }
  2384. if(reqSampleMeter[gun_index] == 1)
  2385. {
  2386. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2387. storeTempStopTransaction(gun_index);
  2388. }
  2389. else if(reqClockAlignMeter[gun_index] == 1)
  2390. {
  2391. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2392. }
  2393. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2394. sleep(1);
  2395. }
  2396. //==============================================
  2397. // Check Connector reserved
  2398. //==============================================
  2399. //===============================
  2400. // Check if Reserve is expired
  2401. //===============================
  2402. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2403. {
  2404. double diff_t;
  2405. struct tm tp;
  2406. // current time
  2407. time_t t = time(NULL);
  2408. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2409. tp.tm_isdst = -1;
  2410. time_t utc = mktime(&tp);
  2411. diff_t = difftime(utc, t);
  2412. if(diff_t <= 0)
  2413. {
  2414. DEBUG_INFO("reserve expired.\n");
  2415. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2416. }
  2417. }//END OF Check if Reserve is expired
  2418. //==========================================
  2419. // csu trigger FirmwareStatusNotificationReq
  2420. //==========================================
  2421. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2422. {
  2423. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2424. }
  2425. //==========================================
  2426. // csu trigger CancelReservationConf
  2427. //==========================================
  2428. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2429. {
  2430. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2431. }
  2432. //==========================================
  2433. // csu trigger ChangeAvailabilityConf
  2434. //==========================================
  2435. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2436. {
  2437. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2438. }
  2439. //==========================================
  2440. // csu trigger UnlockConnectorConf
  2441. //==========================================
  2442. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2443. {
  2444. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2445. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2446. }
  2447. //==========================================
  2448. // csu trigger ReserveNowConf
  2449. //==========================================
  2450. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2451. {
  2452. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2453. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2454. }
  2455. //==========================================
  2456. // csu trigger DataTransferReq
  2457. //==========================================
  2458. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2459. {
  2460. sendDataTransferRequest(gun_index);
  2461. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2462. }
  2463. }
  2464. }
  2465. //==========================================
  2466. // send request routine
  2467. //==========================================
  2468. int sendAuthorizeRequest(int gun_index)
  2469. {
  2470. mtrace();
  2471. int result = FAIL;
  2472. char message[100]={0};
  2473. char guid[37];
  2474. char tempdata[65]={0};
  2475. DEBUG_INFO("sendAuthorizeRequest...\n");
  2476. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2477. //Local Authorize
  2478. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2479. {
  2480. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2481. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2482. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2483. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2484. result = PASS;
  2485. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2486. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2487. authorizeRetryTimes = 0;
  2488. return result;
  2489. }
  2490. else if(((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||
  2491. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2492. {
  2493. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2494. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2495. {
  2496. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2497. {
  2498. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2499. }
  2500. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2501. {
  2502. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2503. }
  2504. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  2505. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2506. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2507. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2508. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2509. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2510. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2511. authorizeRetryTimes = 0;
  2512. return result;
  2513. }
  2514. else
  2515. {
  2516. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  2517. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2518. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2519. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2520. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2521. result = PASS;
  2522. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2523. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2524. authorizeRetryTimes = 0;
  2525. return result;
  2526. }
  2527. }
  2528. //initailize struct Authorize
  2529. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2530. //get data from shared memory
  2531. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2532. random_uuid(guid);
  2533. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2534. LWS_Send(message);
  2535. sprintf(tempdata, "Authorize,%d", gun_index);
  2536. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2537. {
  2538. result = PASS;
  2539. DEBUG_INFO("Authorize mapItem pass\n");
  2540. }
  2541. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2542. return result;
  2543. }
  2544. int sendBootNotificationRequest(void)
  2545. {
  2546. mtrace();
  2547. int result = FAIL;
  2548. char message[500]={0}, payload[700]={0};
  2549. char guid[37]={0};
  2550. char tempdata[65]={0};
  2551. /*
  2552. int IsGunCharging = FALSE;
  2553. //check Transaction active
  2554. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2555. {
  2556. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2557. {
  2558. IsGunCharging = TRUE;
  2559. }
  2560. }
  2561. for (int index = 0; index < CCS_QUANTITY; index++)
  2562. {
  2563. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2564. {
  2565. IsGunCharging = TRUE;
  2566. }
  2567. }
  2568. for (int index = 0; index < GB_QUANTITY; index++)
  2569. {
  2570. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2571. {
  2572. IsGunCharging = TRUE;
  2573. }
  2574. }
  2575. for (int index = 0; index < AC_QUANTITY; index++)
  2576. {
  2577. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2578. {
  2579. IsGunCharging = TRUE;
  2580. }
  2581. }
  2582. if(IsGunCharging == TRUE)
  2583. {
  2584. server_sign = TRUE;
  2585. return result;
  2586. }
  2587. */
  2588. // Fill BootNotification fields
  2589. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2590. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2591. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2592. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2593. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2594. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2595. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2596. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2597. ShmOCPP16Data->ChargeBoxId
  2598. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2599. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2600. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2601. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2602. ,ShmOCPP16Data->BootNotification.CpIccid
  2603. ,ShmOCPP16Data->BootNotification.CpImsi);
  2604. random_uuid(guid);
  2605. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2606. LWS_Send(message);
  2607. sprintf(tempdata, "BootNotification,0");
  2608. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid,mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2609. {
  2610. result = PASS;
  2611. }
  2612. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2613. strcpy(queuedata,message);
  2614. return result;
  2615. }
  2616. int sendDataTransferRequest(int gun_index)
  2617. {
  2618. mtrace();
  2619. char message[1000]={0};
  2620. char guid[37]={0};
  2621. char tempdata[65]={0};
  2622. int result = FAIL;
  2623. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2624. random_uuid(guid);
  2625. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2626. MESSAGE_TYPE_CALL,
  2627. guid,
  2628. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2629. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2630. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2631. LWS_Send(message);
  2632. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2633. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2634. {
  2635. result = PASS;
  2636. DEBUG_INFO("DataTransfer mapItem pass\n");
  2637. }
  2638. return result;
  2639. }
  2640. int sendDiagnosticsStatusNotificationRequest(char *status)
  2641. {
  2642. mtrace();
  2643. int result = FAIL;
  2644. char message[110]={0};
  2645. char guid[37]={0};
  2646. char tempdata[65]={0};
  2647. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2648. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2649. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2650. random_uuid(guid);
  2651. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2652. LWS_Send(message);
  2653. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2654. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2655. {
  2656. result = PASS;
  2657. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2658. }
  2659. //#ifdef SystemLogMessage
  2660. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2661. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2662. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2663. //#endif
  2664. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2665. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2666. //record status
  2667. if(strcmp(status,"Idle")==0)
  2668. {
  2669. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2670. }
  2671. else if(strcmp(status,"Uploaded")==0)
  2672. {
  2673. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2674. }
  2675. else if(strcmp(status,"UploadFailed")==0)
  2676. {
  2677. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2678. }
  2679. else if(strcmp(status,"Uploading")==0)
  2680. {
  2681. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2682. }
  2683. return result;
  2684. }
  2685. int sendFirmwareStatusNotificationRequest(char *status)
  2686. {
  2687. mtrace();
  2688. int result = FAIL;
  2689. char message[110]={0};
  2690. char guid[37]={0};
  2691. char tempdata[65]={0};
  2692. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2693. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2694. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2695. random_uuid(guid);
  2696. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2697. LWS_Send(message);
  2698. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2699. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2700. {
  2701. result = PASS;
  2702. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2703. }
  2704. //#ifdef SystemLogMessage
  2705. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2706. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2707. //#endif
  2708. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2709. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2710. //record status
  2711. if(strcmp(status,"Downloaded")==0)
  2712. {
  2713. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2714. }
  2715. else if(strcmp(status,"DownloadFailed")==0)
  2716. {
  2717. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  2718. }
  2719. else if(strcmp(status,"Downloading")==0)
  2720. {
  2721. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2722. }
  2723. else if(strcmp(status,"Idle")==0)
  2724. {
  2725. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2726. }
  2727. else if(strcmp(status,"InstallationFailed")==0)
  2728. {
  2729. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2730. }
  2731. else if(strcmp(status,"Installing")==0)
  2732. {
  2733. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2734. }
  2735. else if(strcmp(status,"Installed")==0)
  2736. {
  2737. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2738. }
  2739. return result;
  2740. }
  2741. int sendHeartbeatRequest(int gun_index)
  2742. {
  2743. mtrace();
  2744. int result = FAIL;
  2745. char message[80]={0};
  2746. char guid[37]={0};
  2747. char tempdata[65]={0};
  2748. random_uuid(guid);
  2749. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2750. , MESSAGE_TYPE_CALL
  2751. , guid );
  2752. LWS_Send(message);
  2753. sprintf(tempdata, "Heartbeat,%d", 0);
  2754. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2755. {
  2756. result = PASS;
  2757. }
  2758. return result;
  2759. }
  2760. int sendStartTransactionRequest(int gun_index)
  2761. {
  2762. mtrace();
  2763. int result = FAIL;
  2764. char message[250]={0};
  2765. char guid[37]={0};
  2766. struct timeval tmnow;
  2767. struct tm *tm;
  2768. char buf[28];//, usec_buf[6];
  2769. char tempdata[65]={0};
  2770. int tempIndex = 0;
  2771. DEBUG_INFO("sendStartTransactionRequest...\n");
  2772. gettimeofday(&tmnow, NULL);
  2773. time_t t;
  2774. t = time(NULL);
  2775. /*UTC time and date*/
  2776. tm = gmtime(&t);
  2777. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2778. #if 0 // remove temporally
  2779. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2780. strcat(buf,".");
  2781. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2782. strcat(buf,usec_buf);
  2783. #endif
  2784. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2785. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2786. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2787. // clear StartTransaction Response
  2788. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2789. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2790. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2791. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2792. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2793. if(gunType[gun_index] == 'J')
  2794. {
  2795. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2796. {
  2797. tempIndex = ((gun_index==2) ? 1: 0);
  2798. }
  2799. else
  2800. {
  2801. tempIndex = gun_index;
  2802. }
  2803. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2804. {
  2805. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2806. {
  2807. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  2808. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2809. }
  2810. }
  2811. }
  2812. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2813. {
  2814. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2815. {
  2816. tempIndex = ((gun_index==2) ? 1: 0);
  2817. }
  2818. else
  2819. {
  2820. tempIndex = gun_index;
  2821. }
  2822. for (int index = 0; index < CCS_QUANTITY; index++)
  2823. {
  2824. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2825. {
  2826. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  2827. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  2828. }
  2829. }
  2830. }
  2831. else if(gunType[gun_index] == 'G')
  2832. {
  2833. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2834. {
  2835. tempIndex = ((gun_index==2) ? 1: 0);
  2836. }
  2837. else
  2838. {
  2839. tempIndex = gun_index;
  2840. }
  2841. for (int index = 0; index < GB_QUANTITY; index++)
  2842. {
  2843. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2844. {
  2845. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  2846. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  2847. }
  2848. }
  2849. }
  2850. else
  2851. {
  2852. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2853. {
  2854. tempIndex = 2;
  2855. }
  2856. else
  2857. {
  2858. tempIndex = gun_index;
  2859. }
  2860. for (int index = 0; index < AC_QUANTITY; index++)
  2861. {
  2862. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2863. {
  2864. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  2865. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  2866. }
  2867. }
  2868. }
  2869. random_uuid(guid);
  2870. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  2871. {
  2872. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  2873. , gun_index +1
  2874. , MESSAGE_TYPE_CALL
  2875. , guid
  2876. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2877. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2878. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2879. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2880. }
  2881. else
  2882. {
  2883. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  2884. , gun_index +1
  2885. , MESSAGE_TYPE_CALL
  2886. , guid
  2887. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2888. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2889. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2890. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  2891. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2892. }
  2893. #if 1
  2894. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  2895. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2896. {
  2897. result = PASS;
  2898. }
  2899. #endif
  2900. strcpy(queuedata, message);
  2901. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2902. /*
  2903. if(GetTransactionQueueNum() == 1)
  2904. {
  2905. LWS_Send(message + 2);
  2906. }*/
  2907. return result;
  2908. }
  2909. int sendStatusNotificationRequest(int gun_index)
  2910. {
  2911. mtrace();
  2912. int result = FAIL;
  2913. char message[600]={0};
  2914. char guid[37];
  2915. int currentStatus = 0;
  2916. struct timeval tmnow;
  2917. struct tm *tm;
  2918. char buf[28];//, usec_buf[6];
  2919. char tempdata[65]={0};
  2920. int tempIndex = 0;
  2921. gettimeofday(&tmnow, NULL);
  2922. time_t t;
  2923. t = time(NULL);
  2924. /*UTC time and date*/
  2925. tm = gmtime(&t);
  2926. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2927. #if 0 // remove temporally
  2928. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2929. strcat(buf,".");
  2930. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2931. strcat(buf,usec_buf);
  2932. #endif
  2933. printf("%s",buf);
  2934. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  2935. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  2936. // it's option
  2937. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  2938. /*
  2939. enum _SYSTEM_STATUS
  2940. {
  2941. S_BOOTING = 0,
  2942. S_IDLE, = 1
  2943. S_AUTHORIZING, =2
  2944. S_REASSIGN_CHECK, =3
  2945. S_REASSIGN, =4
  2946. S_PRECHARGE, =5
  2947. S_PREPARING_FOR_EV, =6
  2948. S_PREPARING_FOR_EVSE, =7
  2949. S_CHARGING, =8
  2950. S_TERMINATING, =9
  2951. S_COMPLETE, =10
  2952. S_ALARM, =11
  2953. S_FAULT =12
  2954. }
  2955. */
  2956. //check Transaction active
  2957. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2958. if(gunType[gun_index] == 'J')
  2959. {
  2960. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2961. {
  2962. tempIndex = ((gun_index==2) ? 1: 0);
  2963. }
  2964. else
  2965. {
  2966. tempIndex = gun_index;
  2967. }
  2968. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2969. {
  2970. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  2971. {
  2972. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  2973. {
  2974. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  2975. {
  2976. currentStatus = 1; //OCPP Status: Preparing
  2977. }
  2978. else
  2979. {
  2980. currentStatus = 0; //OCPP Status: Available
  2981. }
  2982. }
  2983. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  2984. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  2985. ) //S_PRECHARGE
  2986. {
  2987. currentStatus = 1; //OCPP Status: Preparing
  2988. }
  2989. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2990. {
  2991. currentStatus = 2; //OCPP Status: Charging
  2992. }
  2993. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  2994. {
  2995. currentStatus = 5; //OCPP Status: Finishing
  2996. }
  2997. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  2998. {
  2999. currentStatus = 4; //OCPP Status: SuspendedEV
  3000. }
  3001. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3002. {
  3003. currentStatus = 7; //OCPP Status: Unavailable
  3004. }
  3005. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3006. {
  3007. currentStatus = 8; //OCPP Status: Faulted
  3008. }
  3009. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3010. {
  3011. currentStatus = 6; //OCPP Status: Reserved
  3012. }
  3013. } //end of the same index
  3014. }//end of for CHAdeMO_QUANTITY
  3015. }
  3016. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3017. {
  3018. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3019. {
  3020. tempIndex = ((gun_index==2) ? 1: 0);
  3021. }
  3022. else
  3023. {
  3024. tempIndex = gun_index;
  3025. }
  3026. for (int index = 0; index < CCS_QUANTITY; index++)
  3027. {
  3028. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3029. {
  3030. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3031. {
  3032. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3033. {
  3034. currentStatus = 1; //OCPP Status: Preparing
  3035. }
  3036. else
  3037. {
  3038. currentStatus = 0; //OCPP Status: Available
  3039. }
  3040. }
  3041. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3042. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3043. ) //S_PRECHARGE
  3044. {
  3045. currentStatus = 1; //OCPP Status: Preparing
  3046. }
  3047. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3048. {
  3049. currentStatus = 2; //OCPP Status: Charging
  3050. }
  3051. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3052. {
  3053. currentStatus = 5; //OCPP Status: Finishing
  3054. }
  3055. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3056. {
  3057. currentStatus = 4; //OCPP Status: SuspendedEV
  3058. }
  3059. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3060. {
  3061. currentStatus = 7; //OCPP Status : Unavailable
  3062. }
  3063. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3064. {
  3065. currentStatus = 8; //OCPP Status: Faulted
  3066. }
  3067. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3068. {
  3069. currentStatus = 6; //OCPP Status: Reserved
  3070. }
  3071. } //end of the same index
  3072. } // end of for CCS_QUANTITY
  3073. }
  3074. else if(gunType[gun_index] == 'G')
  3075. {
  3076. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3077. {
  3078. tempIndex = ((gun_index==2) ? 1: 0);
  3079. }
  3080. else
  3081. {
  3082. tempIndex = gun_index;
  3083. }
  3084. for (int index = 0; index < GB_QUANTITY; index++)
  3085. {
  3086. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3087. {
  3088. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3089. {
  3090. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3091. {
  3092. currentStatus = 1; //OCPP Status: Preparing
  3093. }
  3094. else
  3095. {
  3096. currentStatus = 0; //OCPP Status: Available
  3097. }
  3098. }
  3099. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3100. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3101. ) //S_PRECHARGE
  3102. {
  3103. currentStatus = 1; //OCPP Status: Preparing
  3104. }
  3105. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3106. {
  3107. currentStatus = 2; //OCPP Status: Charging
  3108. }
  3109. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3110. {
  3111. currentStatus = 5; //OCPP Status: Finishing
  3112. }
  3113. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3114. {
  3115. currentStatus = 4; //OCPP Status: SuspendedEV
  3116. }
  3117. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3118. {
  3119. currentStatus = 7; //OCPP Status: Unavailable
  3120. }
  3121. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3122. {
  3123. currentStatus = 8; //OCPP Status: Faulted
  3124. }
  3125. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3126. {
  3127. currentStatus = 6; //OCPP Status: Reserved
  3128. }
  3129. } //end of the same index
  3130. } // end of for GB_QUANTITY
  3131. }
  3132. else
  3133. {
  3134. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3135. {
  3136. tempIndex = 2;
  3137. }
  3138. else
  3139. {
  3140. tempIndex = gun_index;
  3141. }
  3142. for (int index = 0; index < AC_QUANTITY; index++)
  3143. {
  3144. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3145. {
  3146. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3147. {
  3148. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  3149. {
  3150. currentStatus = 1; //OCPP Status: Preparing
  3151. }
  3152. else
  3153. {
  3154. currentStatus = 0; //OCPP Status: Available
  3155. }
  3156. }
  3157. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3158. {
  3159. currentStatus = 1; //OCPP Status: Preparing
  3160. }
  3161. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3162. {
  3163. currentStatus = 2; //OCPP Status: Charging
  3164. }
  3165. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3166. {
  3167. currentStatus = 5; //OCPP Status: Finishing
  3168. }
  3169. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3170. {
  3171. currentStatus = 4; //OCPP Status: SuspendedEV
  3172. }
  3173. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3174. {
  3175. currentStatus = 7; //OCPP Status: Unavailable
  3176. }
  3177. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3178. {
  3179. currentStatus = 8; //OCPP Status: Faulted
  3180. }
  3181. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3182. {
  3183. currentStatus = 6; //OCPP Status: Reserved
  3184. }
  3185. }//end of the same index
  3186. }//end of for AC_QUANTITY
  3187. }
  3188. //it's option
  3189. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3190. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3191. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3192. random_uuid(guid);
  3193. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3194. , MESSAGE_TYPE_CALL
  3195. , guid
  3196. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3197. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3198. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3199. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3200. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3201. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3202. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3203. if((server_sign == TRUE))
  3204. {
  3205. LWS_Send(message);
  3206. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3207. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  3208. {
  3209. //DEBUG_ERROR("statusNotification mapitem pass");
  3210. result = PASS;
  3211. }
  3212. }
  3213. else
  3214. {
  3215. result = PASS;
  3216. }
  3217. return result;
  3218. }
  3219. int sendStopTransactionRequest(int gun_index)
  3220. {
  3221. mtrace();
  3222. int result = FAIL;
  3223. //char message[1500]={0};
  3224. char guid[37]={0};
  3225. char tempdata[65]={0};
  3226. int tempIndex = 0;
  3227. char TempStopTransaction[256];
  3228. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3229. //int idx_sample=0;
  3230. DEBUG_ERROR("sendStopTransactionRequest \n");
  3231. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3232. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3233. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3234. if(gunType[gun_index] == 'J')
  3235. {
  3236. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3237. {
  3238. tempIndex = ((gun_index==2) ? 1: 0);
  3239. }
  3240. else
  3241. {
  3242. tempIndex = gun_index;
  3243. }
  3244. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3245. {
  3246. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3247. {
  3248. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3249. }
  3250. }// END OF CHAdeMO_QUANTITY
  3251. }
  3252. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3253. {
  3254. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3255. {
  3256. tempIndex = ((gun_index==2) ? 1: 0);
  3257. }
  3258. else
  3259. {
  3260. tempIndex = gun_index;
  3261. }
  3262. for (int index = 0; index < CCS_QUANTITY; index++)
  3263. {
  3264. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3265. {
  3266. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3267. }
  3268. }// END OF CCS_QUANTITY
  3269. }
  3270. else if(gunType[gun_index] == 'G')
  3271. {
  3272. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3273. {
  3274. tempIndex = ((gun_index==2) ? 1: 0);
  3275. }
  3276. else
  3277. {
  3278. tempIndex = gun_index;
  3279. }
  3280. for (int index = 0; index < GB_QUANTITY; index++)
  3281. {
  3282. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3283. {
  3284. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3285. }
  3286. }// END OF GB_QUANTITY
  3287. }
  3288. else
  3289. {
  3290. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3291. {
  3292. tempIndex = 2;
  3293. }
  3294. else
  3295. {
  3296. tempIndex = gun_index;
  3297. }
  3298. for (int index = 0; index < AC_QUANTITY; index++)
  3299. {
  3300. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3301. {
  3302. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3303. }
  3304. }// END OF AC_QUANTITY
  3305. }
  3306. //====================================== Stop Transaction Time =====================================================
  3307. struct timeval tmnow;
  3308. struct tm *tm;
  3309. char buf[28];//, usec_buf[6];
  3310. gettimeofday(&tmnow, NULL);
  3311. time_t t;
  3312. t = time(NULL);
  3313. /*UTC time and date*/
  3314. tm = gmtime(&t);
  3315. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3316. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3317. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3318. random_uuid(guid);
  3319. /***********************************transactionData******************************************************/
  3320. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3321. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3322. //=================================
  3323. // Transaction_Begin
  3324. //=================================
  3325. //============================================ Energy.Active.Import.Interval ================================
  3326. //idx_sample=0;
  3327. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  3328. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3329. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3330. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  3331. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3332. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3333. {
  3334. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3335. }
  3336. else
  3337. {
  3338. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3339. }
  3340. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3341. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3342. //=================================
  3343. // Transaction_End
  3344. //=================================
  3345. // ================================= Current.Import L1 ===============================================
  3346. //idx_sample=1;
  3347. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3348. if(gunType[gun_index] == 'J')
  3349. {
  3350. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3351. {
  3352. tempIndex = ((gun_index==2) ? 1: 0);
  3353. }
  3354. else
  3355. {
  3356. tempIndex = gun_index;
  3357. }
  3358. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3359. {
  3360. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3361. {
  3362. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3363. }
  3364. }// End of for CHAdeMO_QUANTITY
  3365. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3366. }
  3367. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3368. {
  3369. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3370. {
  3371. tempIndex = ((gun_index==2) ? 1: 0);
  3372. }
  3373. else
  3374. {
  3375. tempIndex = gun_index;
  3376. }
  3377. for (int index = 0; index < CCS_QUANTITY; index++)
  3378. {
  3379. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3380. {
  3381. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3382. }
  3383. }// End of for CCS_QUANTITY
  3384. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3385. }
  3386. else if(gunType[gun_index] == 'G')
  3387. {
  3388. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3389. {
  3390. tempIndex = ((gun_index==2) ? 1: 0);
  3391. }
  3392. else
  3393. {
  3394. tempIndex = gun_index;
  3395. }
  3396. for (int index = 0; index < GB_QUANTITY; index++)
  3397. {
  3398. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3399. {
  3400. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3401. }
  3402. }// End of for GB_QUANTITY
  3403. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3404. }
  3405. else
  3406. {
  3407. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3408. {
  3409. tempIndex = 2;
  3410. }
  3411. else
  3412. {
  3413. tempIndex = gun_index;
  3414. }
  3415. for (int index = 0; index < AC_QUANTITY; index++)
  3416. {
  3417. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3418. {
  3419. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3420. }
  3421. }// End of for AC_QUANTITY
  3422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3423. }
  3424. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3425. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3426. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3427. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3428. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3429. // ================================= Energy.Active.Import.Interval ==============================================
  3430. //idx_sample=2;
  3431. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3432. if(gunType[gun_index] == 'J')
  3433. {
  3434. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3435. {
  3436. tempIndex = ((gun_index==2) ? 1: 0);
  3437. }
  3438. else
  3439. {
  3440. tempIndex = gun_index;
  3441. }
  3442. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3443. {
  3444. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3445. {
  3446. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3447. }
  3448. }// END OF CHAdeMO_QUANTITY
  3449. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3450. }
  3451. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3452. {
  3453. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3454. {
  3455. tempIndex = ((gun_index==2) ? 1: 0);
  3456. }
  3457. else
  3458. {
  3459. tempIndex = gun_index;
  3460. }
  3461. for (int index = 0; index < CCS_QUANTITY; index++)
  3462. {
  3463. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3464. {
  3465. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3466. }
  3467. }// END OF CCS_QUANTITY
  3468. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3469. }
  3470. else if(gunType[gun_index] == 'G')
  3471. {
  3472. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3473. {
  3474. tempIndex = ((gun_index==2) ? 1: 0);
  3475. }
  3476. else
  3477. {
  3478. tempIndex = gun_index;
  3479. }
  3480. for (int index = 0; index < GB_QUANTITY; index++)
  3481. {
  3482. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3483. {
  3484. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3485. }
  3486. }// END OF GB_QUANTITY
  3487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3488. }
  3489. else
  3490. {
  3491. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3492. {
  3493. tempIndex = 2;
  3494. }
  3495. else
  3496. {
  3497. tempIndex = gun_index;
  3498. }
  3499. for (int index = 0; index < AC_QUANTITY; index++)
  3500. {
  3501. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3502. {
  3503. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3504. }
  3505. }// END OF AC_QUANTITY
  3506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3507. }
  3508. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3512. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3513. //=================================== Power.Active.Import ==================================================
  3514. //idx_sample=3;
  3515. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3516. if(gunType[gun_index] == 'J')
  3517. {
  3518. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3519. {
  3520. tempIndex = ((gun_index==2) ? 1: 0);
  3521. }
  3522. else
  3523. {
  3524. tempIndex = gun_index;
  3525. }
  3526. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3527. {
  3528. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3529. {
  3530. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3531. }
  3532. } // End for CHAdeMO_QUANTITY
  3533. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3534. }
  3535. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3536. {
  3537. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3538. {
  3539. tempIndex = ((gun_index==2) ? 1: 0);
  3540. }
  3541. else
  3542. {
  3543. tempIndex = gun_index;
  3544. }
  3545. for (int index = 0; index < CCS_QUANTITY; index++)
  3546. {
  3547. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3548. {
  3549. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3550. }
  3551. } // END for CCS_QUANTITY
  3552. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3553. }
  3554. else if(gunType[gun_index] == 'G')
  3555. {
  3556. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3557. {
  3558. tempIndex = ((gun_index==2) ? 1: 0);
  3559. }
  3560. else
  3561. {
  3562. tempIndex = gun_index;
  3563. }
  3564. for (int index = 0; index < GB_QUANTITY; index++)
  3565. {
  3566. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3567. {
  3568. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3569. }
  3570. }// END for GB_QUANTITY
  3571. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3572. }
  3573. else
  3574. {
  3575. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3576. {
  3577. tempIndex = 2;
  3578. }
  3579. else
  3580. {
  3581. tempIndex = gun_index;
  3582. }
  3583. for (int index = 0; index < AC_QUANTITY; index++)
  3584. {
  3585. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3586. {
  3587. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3588. }
  3589. } // END for AC_QUANTITY
  3590. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3591. }
  3592. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3593. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3596. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3597. //============================ Voltage L1 ====================================
  3598. //idx_sample=4;
  3599. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3600. if(gunType[gun_index] == 'J')
  3601. {
  3602. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3603. {
  3604. tempIndex = ((gun_index==2) ? 1: 0);
  3605. }
  3606. else
  3607. {
  3608. tempIndex = gun_index;
  3609. }
  3610. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3611. {
  3612. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3613. {
  3614. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3615. }
  3616. } // END OF FOR CHAdeMO_QUANTITY
  3617. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3618. }
  3619. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3620. {
  3621. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3622. {
  3623. tempIndex = ((gun_index==2) ? 1: 0);
  3624. }
  3625. else
  3626. {
  3627. tempIndex = gun_index;
  3628. }
  3629. for (int index = 0; index < CCS_QUANTITY; index++)
  3630. {
  3631. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3632. {
  3633. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3634. }
  3635. } // END OF FOR CCS_QUANTITY
  3636. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3637. }
  3638. else if(gunType[gun_index] == 'G')
  3639. {
  3640. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3641. {
  3642. tempIndex = ((gun_index==2) ? 1: 0);
  3643. }
  3644. else
  3645. {
  3646. tempIndex = gun_index;
  3647. }
  3648. for (int index = 0; index < GB_QUANTITY; index++)
  3649. {
  3650. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3651. {
  3652. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3653. }
  3654. } // END OF FOR GB_QUANTITY
  3655. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3656. }
  3657. else
  3658. {
  3659. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3660. {
  3661. tempIndex = 2;
  3662. }
  3663. else
  3664. {
  3665. tempIndex = gun_index;
  3666. }
  3667. for (int index = 0; index < AC_QUANTITY; index++)
  3668. {
  3669. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3670. {
  3671. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  3672. }
  3673. } // END OF FOR AC_QUANTITY
  3674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3675. }
  3676. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3677. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3678. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3679. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3680. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3681. //====================== SoC ================================
  3682. //idx_sample=5;
  3683. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3684. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3685. {
  3686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3687. {
  3688. tempIndex = ((gun_index==2) ? 1: 0);
  3689. }
  3690. else
  3691. {
  3692. tempIndex = gun_index;
  3693. }
  3694. if(gunType[gun_index] == 'J')
  3695. {
  3696. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3697. {
  3698. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3699. {
  3700. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3701. }
  3702. }
  3703. }
  3704. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3705. {
  3706. for (int index = 0; index < CCS_QUANTITY; index++)
  3707. {
  3708. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3709. {
  3710. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3711. }
  3712. }
  3713. }
  3714. else if(gunType[gun_index] == 'G')
  3715. {
  3716. for (int index = 0; index < GB_QUANTITY; index++)
  3717. {
  3718. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3719. {
  3720. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  3721. }
  3722. }
  3723. }
  3724. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3725. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  3726. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  3727. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  3728. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  3729. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  3730. } // END FOR DC CASE
  3731. // ================================= Current.Import L2 ===============================================
  3732. //idx_sample=6;
  3733. // AC 3 phse L2 current
  3734. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3735. {
  3736. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3737. {
  3738. tempIndex = 2;
  3739. }
  3740. else
  3741. {
  3742. tempIndex = gun_index;
  3743. }
  3744. for (int index = 0; index < AC_QUANTITY; index++)
  3745. {
  3746. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3747. {
  3748. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  3749. }
  3750. }// End of for AC_QUANTITY
  3751. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  3752. }
  3753. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3754. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  3755. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  3756. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  3757. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3758. // ================================= Current.Import L3 ===============================================
  3759. //idx_sample=7;
  3760. // AC 3 phse L3 current
  3761. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3762. {
  3763. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3764. {
  3765. tempIndex = 2;
  3766. }
  3767. else
  3768. {
  3769. tempIndex = gun_index;
  3770. }
  3771. for (int index = 0; index < AC_QUANTITY; index++)
  3772. {
  3773. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3774. {
  3775. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  3776. }
  3777. }// End of for AC_QUANTITY
  3778. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  3779. }
  3780. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3781. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  3782. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  3783. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  3784. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3785. //============================ Voltage L2 ====================================
  3786. //idx_sample=8;
  3787. // AC 3 phse L2 voltage
  3788. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3789. {
  3790. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3791. {
  3792. tempIndex = 2;
  3793. }
  3794. else
  3795. {
  3796. tempIndex = gun_index;
  3797. }
  3798. for (int index = 0; index < AC_QUANTITY; index++)
  3799. {
  3800. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3801. {
  3802. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  3803. }
  3804. } // END OF FOR AC_QUANTITY
  3805. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  3806. }
  3807. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3808. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  3809. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  3810. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  3811. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3812. //============================ Voltage L3 ====================================
  3813. //idx_sample=8;
  3814. // AC 3 phse L3 voltage
  3815. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3816. {
  3817. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3818. {
  3819. tempIndex = 2;
  3820. }
  3821. else
  3822. {
  3823. tempIndex = gun_index;
  3824. }
  3825. for (int index = 0; index < AC_QUANTITY; index++)
  3826. {
  3827. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3828. {
  3829. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  3830. }
  3831. } // END OF FOR AC_QUANTITY
  3832. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  3833. }
  3834. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3835. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  3836. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  3837. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  3838. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3839. //================================================ Message create ====================================================
  3840. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3841. {
  3842. sprintf(queuedata,"%d,[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  3843. ,gun_index+1
  3844. ,MESSAGE_TYPE_CALL
  3845. ,guid
  3846. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3847. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3848. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3849. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3850. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3851. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3852. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3853. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3854. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3855. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3856. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3857. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3858. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3859. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3860. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3861. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3862. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3863. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3864. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3865. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3866. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3867. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3868. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3869. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3870. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3871. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  3888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  3889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  3890. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  3891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  3892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  3893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  3894. );
  3895. }
  3896. else
  3897. {
  3898. if((ShmSysConfigAndInfo->SysConfig.ModelName[2]!='Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2]!='W'))
  3899. {
  3900. sprintf(queuedata,"%d,[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  3901. ,gun_index+1
  3902. ,MESSAGE_TYPE_CALL
  3903. ,guid
  3904. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3905. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3906. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3907. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3908. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3909. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3910. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3911. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3912. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3913. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3914. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3915. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3916. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3917. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3918. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3919. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3920. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3921. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3922. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3923. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3924. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3925. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3926. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3927. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3928. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3929. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3930. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3931. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3932. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3933. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3934. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3935. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3936. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3937. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3938. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3939. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3940. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3941. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3942. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3943. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3944. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3945. );
  3946. }
  3947. else
  3948. {
  3949. sprintf(queuedata,"%d,[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  3950. ,gun_index+1
  3951. ,MESSAGE_TYPE_CALL
  3952. ,guid
  3953. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3954. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3955. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3956. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3957. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3958. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3959. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3960. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3961. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3962. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3963. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3964. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3965. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3966. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3967. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3968. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3969. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3970. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3971. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3972. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3973. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3974. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3975. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3976. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3977. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3978. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3979. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3980. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3981. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3982. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3983. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3984. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3985. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3986. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3987. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3988. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3989. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3990. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3991. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3992. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3993. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3994. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  3995. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  3996. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  3997. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  3998. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  3999. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  4000. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  4001. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  4002. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  4003. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  4004. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  4005. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  4006. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  4007. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  4008. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  4009. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  4010. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  4011. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  4012. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  4013. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  4014. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  4015. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  4016. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  4017. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  4018. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  4019. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  4020. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  4021. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  4022. );
  4023. }
  4024. }
  4025. #if 1 // for TempStopTransaction
  4026. //Delete TempStopTransaction
  4027. if((access(TempStopTransaction,F_OK))!=-1)
  4028. {
  4029. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4030. }
  4031. #endif
  4032. #if 1
  4033. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4034. if(hashmap_operation(0, guid, tempdata) == 1)
  4035. {
  4036. result = PASS;
  4037. DEBUG_INFO("StopTransaction mapitem pass\n");
  4038. }
  4039. #endif
  4040. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4041. /*
  4042. if(GetTransactionQueueNum() == 1)
  4043. {
  4044. LWS_Send(queuedata+2);
  4045. }*/
  4046. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4047. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4048. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4049. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4050. {
  4051. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4052. }
  4053. //for test
  4054. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4055. return result;
  4056. }
  4057. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4058. {
  4059. mtrace();
  4060. int result = FAIL;
  4061. char guid[37]={0};
  4062. char tempdata[65]={0};
  4063. int tempIndex = 0;
  4064. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4065. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4066. //set value
  4067. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4068. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) ? ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId : 0);
  4069. random_uuid(guid);
  4070. //UTC Date time
  4071. struct timeval tmnow;
  4072. struct tm *tm;
  4073. char buf[28];//, usec_buf[6];
  4074. gettimeofday(&tmnow, NULL);
  4075. time_t t;
  4076. t = time(NULL);
  4077. /*UTC time and date*/
  4078. tm = gmtime(&t);
  4079. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4080. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4081. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4082. //idx_sample=0;
  4083. //********************************(1)Current.Import L1************************************************/
  4084. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4085. if(gunType[gun_index] == 'J')
  4086. {
  4087. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4088. {
  4089. tempIndex = ((gun_index==2) ? 1: 0);
  4090. }
  4091. else
  4092. {
  4093. tempIndex = gun_index;
  4094. }
  4095. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4096. {
  4097. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4098. {
  4099. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4100. }
  4101. }
  4102. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4103. }
  4104. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4105. {
  4106. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4107. {
  4108. tempIndex = ((gun_index==2) ? 1: 0);
  4109. }
  4110. else
  4111. {
  4112. tempIndex = gun_index;
  4113. }
  4114. for (int index = 0; index < CCS_QUANTITY; index++)
  4115. {
  4116. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4117. {
  4118. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4119. }
  4120. }
  4121. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4122. }
  4123. else if(gunType[gun_index] == 'G')
  4124. {
  4125. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4126. {
  4127. tempIndex = ((gun_index==2) ? 1: 0);
  4128. }
  4129. else
  4130. {
  4131. tempIndex = gun_index;
  4132. }
  4133. for (int index = 0; index < GB_QUANTITY; index++)
  4134. {
  4135. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4136. {
  4137. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4138. }
  4139. }
  4140. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4141. }
  4142. else
  4143. {
  4144. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4145. {
  4146. tempIndex = 2;
  4147. }
  4148. else
  4149. {
  4150. tempIndex = gun_index;
  4151. }
  4152. for (int index = 0; index < AC_QUANTITY; index++)
  4153. {
  4154. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4155. {
  4156. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4157. }
  4158. }
  4159. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4160. }
  4161. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4162. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4163. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4164. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4165. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4166. //idx_sample=1;
  4167. //********************************(2)Energy.Active.Import.Register ************************************************/
  4168. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4169. if(gunType[gun_index] == 'J')
  4170. {
  4171. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4172. {
  4173. tempIndex = ((gun_index==2) ? 1: 0);
  4174. }
  4175. else
  4176. {
  4177. tempIndex = gun_index;
  4178. }
  4179. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4180. {
  4181. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4182. {
  4183. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4184. }
  4185. }
  4186. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4187. }
  4188. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4189. {
  4190. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4191. {
  4192. tempIndex = ((gun_index==2) ? 1: 0);
  4193. }
  4194. else
  4195. {
  4196. tempIndex = gun_index;
  4197. }
  4198. for (int index = 0; index < CCS_QUANTITY; index++)
  4199. {
  4200. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4201. {
  4202. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4203. }
  4204. }
  4205. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4206. }
  4207. else if(gunType[gun_index] == 'G')
  4208. {
  4209. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4210. {
  4211. tempIndex = ((gun_index==2) ? 1: 0);
  4212. }
  4213. else
  4214. {
  4215. tempIndex = gun_index;
  4216. }
  4217. for (int index = 0; index < GB_QUANTITY; index++)
  4218. {
  4219. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4220. {
  4221. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4222. }
  4223. }
  4224. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4225. }
  4226. else
  4227. {
  4228. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4229. {
  4230. tempIndex = 2;
  4231. }
  4232. else
  4233. {
  4234. tempIndex = gun_index;
  4235. }
  4236. for (int index = 0; index < AC_QUANTITY; index++)
  4237. {
  4238. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4239. {
  4240. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4241. }
  4242. }
  4243. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4244. }
  4245. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4246. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4247. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4248. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4249. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4250. //idx_sample=2;
  4251. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4252. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4253. if(gunType[gun_index] == 'J')
  4254. {
  4255. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4256. {
  4257. tempIndex = ((gun_index==2) ? 1: 0);
  4258. }
  4259. else
  4260. {
  4261. tempIndex = gun_index;
  4262. }
  4263. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4264. {
  4265. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4266. {
  4267. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4268. }
  4269. } // END OF FOR CHAdeMO_QUANTITY
  4270. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4271. }
  4272. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4273. {
  4274. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4275. {
  4276. tempIndex = ((gun_index==2) ? 1: 0);
  4277. }
  4278. else
  4279. {
  4280. tempIndex = gun_index;
  4281. }
  4282. for (int index = 0; index < CCS_QUANTITY; index++)
  4283. {
  4284. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4285. {
  4286. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4287. }
  4288. } // END OF CCS_QUANTITY
  4289. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4290. }
  4291. else if(gunType[gun_index] == 'G')
  4292. {
  4293. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4294. {
  4295. tempIndex = ((gun_index==2) ? 1: 0);
  4296. }
  4297. else
  4298. {
  4299. tempIndex = gun_index;
  4300. }
  4301. for (int index = 0; index < GB_QUANTITY; index++)
  4302. {
  4303. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4304. {
  4305. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4306. }
  4307. } // END OF GB_QUANTITY
  4308. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4309. }
  4310. else
  4311. {
  4312. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4313. {
  4314. tempIndex = 2;
  4315. }
  4316. else
  4317. {
  4318. tempIndex = gun_index;
  4319. }
  4320. for (int index = 0; index < AC_QUANTITY; index++)
  4321. {
  4322. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4323. {
  4324. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4325. }
  4326. }
  4327. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4328. }
  4329. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4330. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4331. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4332. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4333. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4334. //idx_sample=3;
  4335. //********************************(4)Power.Active.Import************************************************/
  4336. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4337. if(gunType[gun_index] == 'J')
  4338. {
  4339. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4340. {
  4341. tempIndex = ((gun_index==2) ? 1: 0);
  4342. }
  4343. else
  4344. {
  4345. tempIndex = gun_index;
  4346. }
  4347. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4348. {
  4349. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4350. {
  4351. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4352. }
  4353. } // END OF FOR
  4354. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4355. }
  4356. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4357. {
  4358. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4359. {
  4360. tempIndex = ((gun_index==2) ? 1: 0);
  4361. }
  4362. else
  4363. {
  4364. tempIndex = gun_index;
  4365. }
  4366. for (int index = 0; index < CCS_QUANTITY; index++)
  4367. {
  4368. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4369. {
  4370. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4371. }
  4372. }
  4373. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4374. }
  4375. else if(gunType[gun_index] == 'G')
  4376. {
  4377. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4378. {
  4379. tempIndex = ((gun_index==2) ? 1: 0);
  4380. }
  4381. else
  4382. {
  4383. tempIndex = gun_index;
  4384. }
  4385. for (int index = 0; index < GB_QUANTITY; index++)
  4386. {
  4387. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4388. {
  4389. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4390. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4391. }
  4392. }
  4393. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4394. }
  4395. else
  4396. {
  4397. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4398. {
  4399. tempIndex = 2;
  4400. }
  4401. else
  4402. {
  4403. tempIndex = gun_index;
  4404. }
  4405. for (int index = 0; index < AC_QUANTITY; index++)
  4406. {
  4407. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4408. {
  4409. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4410. }
  4411. }
  4412. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4413. }
  4414. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4415. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4416. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4417. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4418. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4419. //idx_sample=4;
  4420. //***********************************************(5)VOLTAGE L1******************************************************/
  4421. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4422. if(gunType[gun_index] == 'J')
  4423. {
  4424. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4425. {
  4426. tempIndex = ((gun_index==2) ? 1: 0);
  4427. }
  4428. else
  4429. {
  4430. tempIndex = gun_index;
  4431. }
  4432. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4433. {
  4434. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4435. {
  4436. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4437. }
  4438. }
  4439. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4440. }
  4441. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4442. {
  4443. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4444. {
  4445. tempIndex = ((gun_index==2) ? 1: 0);
  4446. }
  4447. else
  4448. {
  4449. tempIndex = gun_index;
  4450. }
  4451. for (int index = 0; index < CCS_QUANTITY; index++)
  4452. {
  4453. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4454. {
  4455. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4456. }
  4457. }
  4458. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4459. }
  4460. else if(gunType[gun_index] == 'G')
  4461. {
  4462. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4463. {
  4464. tempIndex = ((gun_index==2) ? 1: 0);
  4465. }
  4466. else
  4467. {
  4468. tempIndex = gun_index;
  4469. }
  4470. for (int index = 0; index < GB_QUANTITY; index++)
  4471. {
  4472. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4473. {
  4474. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4475. }
  4476. }
  4477. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4478. }
  4479. else
  4480. {
  4481. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4482. {
  4483. tempIndex = 2;
  4484. }
  4485. else
  4486. {
  4487. tempIndex = gun_index;
  4488. }
  4489. for (int index = 0; index < AC_QUANTITY; index++)
  4490. {
  4491. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4492. {
  4493. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4494. }
  4495. }
  4496. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4497. }
  4498. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4499. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4500. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4501. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4502. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4503. //***********************************************(6)SOC******************************************************/
  4504. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4505. {
  4506. //idx_sample=5;
  4507. //sampledValue = NULL;
  4508. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4509. {
  4510. tempIndex = ((gun_index==2) ? 1: 0);
  4511. }
  4512. else
  4513. {
  4514. tempIndex = gun_index;
  4515. }
  4516. if(gunType[gun_index] == 'J')
  4517. {
  4518. //tempIndex = ((gun_index==2) ? 1: 0);
  4519. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4520. {
  4521. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4522. {
  4523. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4524. }
  4525. }
  4526. }
  4527. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4528. {
  4529. //tempIndex = ((gun_index==2) ? 1: 0);
  4530. for (int index = 0; index < CCS_QUANTITY; index++)
  4531. {
  4532. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4533. {
  4534. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4535. }
  4536. }
  4537. }
  4538. else if(gunType[gun_index] == 'G')
  4539. {
  4540. //tempIndex = ((gun_index==2) ? 1: 0);
  4541. for (int index = 0; index < GB_QUANTITY; index++)
  4542. {
  4543. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4544. {
  4545. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4546. }
  4547. }
  4548. }
  4549. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4550. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4551. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4552. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4553. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_Outlet]);
  4554. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4555. }
  4556. //********************************(7)Current.Import L2************************************************/
  4557. // Only for AC 3 phase
  4558. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4559. {
  4560. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4561. {
  4562. tempIndex = 2;
  4563. }
  4564. else
  4565. {
  4566. tempIndex = gun_index;
  4567. }
  4568. for (int index = 0; index < AC_QUANTITY; index++)
  4569. {
  4570. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4571. {
  4572. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  4573. }
  4574. }
  4575. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  4576. }
  4577. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  4578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  4579. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  4580. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  4581. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4582. //********************************(8)Current.Import L3************************************************/
  4583. // Only for AC 3 phase
  4584. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4585. {
  4586. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4587. {
  4588. tempIndex = 2;
  4589. }
  4590. else
  4591. {
  4592. tempIndex = gun_index;
  4593. }
  4594. for (int index = 0; index < AC_QUANTITY; index++)
  4595. {
  4596. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4597. {
  4598. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  4599. }
  4600. }
  4601. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  4602. }
  4603. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  4604. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  4605. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  4606. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  4607. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4608. //***********************************************(9)VOLTAGE L2******************************************************/
  4609. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4610. {
  4611. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4612. {
  4613. tempIndex = 2;
  4614. }
  4615. else
  4616. {
  4617. tempIndex = gun_index;
  4618. }
  4619. for (int index = 0; index < AC_QUANTITY; index++)
  4620. {
  4621. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4622. {
  4623. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  4624. }
  4625. }
  4626. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  4627. }
  4628. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  4629. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  4630. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  4631. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  4632. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4633. //***********************************************(10)VOLTAGE L3******************************************************/
  4634. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4635. {
  4636. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4637. {
  4638. tempIndex = 2;
  4639. }
  4640. else
  4641. {
  4642. tempIndex = gun_index;
  4643. }
  4644. for (int index = 0; index < AC_QUANTITY; index++)
  4645. {
  4646. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4647. {
  4648. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  4649. }
  4650. }
  4651. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  4652. }
  4653. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  4654. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  4655. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  4656. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  4657. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4658. // Message create ====================================================================================================
  4659. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4660. {
  4661. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  4662. ,gun_index + 1
  4663. ,MESSAGE_TYPE_CALL
  4664. ,guid
  4665. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4666. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4667. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4668. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4669. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4670. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4671. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4672. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4673. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4674. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4675. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4676. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4677. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4678. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4679. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4680. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4681. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4682. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4683. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4684. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4685. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4686. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4687. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4688. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4689. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4690. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4691. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4692. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4693. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4694. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4695. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4696. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4697. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4698. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4699. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4700. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4701. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4702. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4703. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value
  4704. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context
  4705. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format
  4706. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand
  4707. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase
  4708. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location
  4709. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit
  4710. );
  4711. }
  4712. else
  4713. {
  4714. if((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W'))
  4715. {
  4716. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  4717. ,gun_index + 1
  4718. ,MESSAGE_TYPE_CALL
  4719. ,guid
  4720. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4721. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4722. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4723. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4724. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4725. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4726. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4727. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4728. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4729. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4730. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4731. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4732. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4733. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4734. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4735. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4736. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4737. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4738. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4739. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4740. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4741. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4742. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4743. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4744. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4745. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4746. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4747. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4748. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4749. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4750. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4751. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4752. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4753. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4754. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4755. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4756. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4757. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4758. );
  4759. }
  4760. else
  4761. {
  4762. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  4763. ,gun_index + 1
  4764. ,MESSAGE_TYPE_CALL
  4765. ,guid
  4766. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4767. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4768. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4769. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4770. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4771. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4772. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4773. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4774. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4775. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4776. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4777. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4778. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4779. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4780. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4781. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4782. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4783. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4784. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4785. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4786. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4787. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4788. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4789. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4790. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4791. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4792. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4793. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4794. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4795. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4796. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4797. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4798. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4799. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4800. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4801. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4802. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4803. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4804. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value
  4805. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context
  4806. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format
  4807. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand
  4808. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase
  4809. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location
  4810. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit
  4811. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value
  4812. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context
  4813. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format
  4814. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand
  4815. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase
  4816. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location
  4817. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit
  4818. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value
  4819. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context
  4820. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format
  4821. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand
  4822. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase
  4823. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location
  4824. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit
  4825. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value
  4826. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context
  4827. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format
  4828. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand
  4829. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase
  4830. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location
  4831. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit
  4832. );
  4833. }
  4834. }
  4835. // Put request guid to hash map
  4836. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4837. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  4838. {
  4839. result = PASS;
  4840. DEBUG_INFO("MeterValues mapitem pass\n");
  4841. }
  4842. if(dataType != ReadingContext_Trigger)
  4843. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4844. else
  4845. LWS_Send(queuedata +2);
  4846. /*
  4847. if(GetTransactionQueueNum() == 1)
  4848. {
  4849. LWS_Send(queuedata +2);
  4850. }*/
  4851. return result;
  4852. }
  4853. //==========================================
  4854. // send confirm routine
  4855. //==========================================
  4856. int sendCancelReservationConfirmation(char *uuid,char *payload)
  4857. {
  4858. mtrace();
  4859. int result = FAIL;
  4860. char message[100]={0};
  4861. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  4862. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4863. LWS_Send(message);
  4864. result = TRUE;
  4865. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  4866. return result;
  4867. }
  4868. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  4869. {
  4870. mtrace();
  4871. int result = FAIL;
  4872. char message[100]={0};
  4873. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  4874. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4875. LWS_Send(message);
  4876. result = TRUE;
  4877. return result;
  4878. }
  4879. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  4880. {
  4881. mtrace();
  4882. int result = FAIL;
  4883. char message[100]={0};
  4884. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  4885. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4886. LWS_Send(message);
  4887. result = TRUE;
  4888. return result;
  4889. }
  4890. int sendClearCacheConfirmation(char *uuid,char *payload)
  4891. {
  4892. mtrace();
  4893. int result = FAIL;
  4894. char message[500]={0};
  4895. DEBUG_INFO("sendClearCacheConfirmation...\n");
  4896. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4897. LWS_Send(message);
  4898. return result;
  4899. }
  4900. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  4901. {
  4902. mtrace();
  4903. int result = FAIL;
  4904. char message[500]={0};
  4905. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  4906. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4907. LWS_Send(message);
  4908. return result;
  4909. }
  4910. int sendDataTransferConfirmation(char *uuid,char *payload)
  4911. {
  4912. mtrace();
  4913. char statusStr[20]={0};
  4914. char dataStr[10]={0};
  4915. char sstr[20]={0};
  4916. int c = 0;
  4917. char *loc;
  4918. int result = FAIL;
  4919. DEBUG_INFO("sendDataTransferConfirmation...\n");
  4920. /**********************status**************************/
  4921. loc = strstr(payload, "status");
  4922. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4923. c = 0;
  4924. while (loc[3+strlen("status")+c] != '\"')
  4925. {
  4926. sstr[c] = loc[3+strlen("status")+c];
  4927. c++;
  4928. }
  4929. sstr[c] = '\0';
  4930. strcpy(statusStr, sstr);
  4931. /**********************data**************************/
  4932. loc = strstr(payload, "data");
  4933. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4934. c = 0;
  4935. while (loc[3+strlen("data")+c] != '\"')
  4936. {
  4937. sstr[c] = loc[3+strlen("data")+c];
  4938. c++;
  4939. }
  4940. sstr[c] = '\0';
  4941. strcpy(dataStr, sstr);
  4942. return result;
  4943. }
  4944. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  4945. {
  4946. mtrace();
  4947. int result = FAIL;
  4948. char message[1000]={0};
  4949. int CompositeScheduleIndex = 0;
  4950. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  4951. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  4952. if(nPeriod == 0)
  4953. {
  4954. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  4955. {
  4956. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  4957. ,MESSAGE_TYPE_CALLRESULT
  4958. ,uuid
  4959. ,payload
  4960. ,connectorIdInt);
  4961. }
  4962. else
  4963. {
  4964. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  4965. ,MESSAGE_TYPE_CALLRESULT
  4966. ,uuid
  4967. ,payload
  4968. ,connectorIdInt
  4969. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4970. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4971. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4972. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  4973. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  4974. }
  4975. }
  4976. else
  4977. {
  4978. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  4979. ,MESSAGE_TYPE_CALLRESULT
  4980. ,uuid
  4981. ,payload
  4982. ,connectorIdInt
  4983. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4984. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4985. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4986. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  4987. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  4988. {
  4989. if (idx_sample == 0)
  4990. {
  4991. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4992. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4993. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4994. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4995. }
  4996. else
  4997. {
  4998. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4999. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5000. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5001. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5002. }
  5003. }
  5004. sprintf(message + strlen(message), "]}}]");
  5005. }
  5006. LWS_Send(message);
  5007. result = TRUE;
  5008. return result;
  5009. }
  5010. int sendGetConfigurationConfirmation(char *uuid)
  5011. {
  5012. mtrace();
  5013. int result = FAIL;
  5014. int MaxKeySupported = 0;
  5015. int sentConfigurationNumber= 0;
  5016. int sentunConfigurationNumber= 0;
  5017. char message[4000]={0};
  5018. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5019. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5020. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5021. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5022. ,MESSAGE_TYPE_CALLRESULT
  5023. ,uuid );
  5024. //configuration key
  5025. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5026. {
  5027. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5028. {
  5029. if (sentConfigurationNumber == 0)
  5030. {
  5031. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5032. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5033. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5034. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5035. }
  5036. else
  5037. {
  5038. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5039. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5040. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5041. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5042. }
  5043. sentConfigurationNumber = sentConfigurationNumber + 1;
  5044. }
  5045. }
  5046. sprintf(message + strlen(message), "]");
  5047. if(UnknownKeynum != 0)
  5048. {
  5049. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5050. //unkown key
  5051. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5052. {
  5053. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5054. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5055. if(sentunConfigurationNumber == 0)
  5056. {
  5057. sprintf(message + strlen(message), "\"%s\""
  5058. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5059. }
  5060. else
  5061. {
  5062. sprintf(message + strlen(message), ",\"%s\""
  5063. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5064. }
  5065. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5066. }
  5067. sprintf(message + strlen(message), "]");
  5068. }
  5069. sprintf(message + strlen(message), "}]");
  5070. LWS_Send(message);
  5071. return result;
  5072. }
  5073. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5074. {
  5075. mtrace();
  5076. int result = FAIL;
  5077. char message[400]={0};
  5078. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5079. if(strcmp(payload,"")==0)
  5080. {
  5081. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5082. }
  5083. else
  5084. {
  5085. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5086. }
  5087. LWS_Send(message);
  5088. result = TRUE;
  5089. return result;
  5090. }
  5091. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5092. {
  5093. mtrace();
  5094. int result = FAIL;
  5095. char message[80]={0};
  5096. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5097. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5098. LWS_Send(message);
  5099. result = TRUE;
  5100. return result;
  5101. }
  5102. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5103. {
  5104. mtrace();
  5105. int result = FAIL;
  5106. char message[80]={0};
  5107. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5108. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5109. LWS_Send(message);
  5110. result = TRUE;
  5111. return result;
  5112. }
  5113. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5114. {
  5115. mtrace();
  5116. int result = FAIL;
  5117. char message[80]={0};
  5118. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5119. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5120. LWS_Send(message);
  5121. result = TRUE;
  5122. return result;
  5123. }
  5124. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5125. {
  5126. mtrace();
  5127. int result = FAIL;
  5128. char message[80]={0};
  5129. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5130. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5131. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5132. LWS_Send(message);
  5133. result = TRUE;
  5134. return result;
  5135. }
  5136. int sendResetConfirmation(char *uuid,char *payload)
  5137. {
  5138. mtrace();
  5139. int result = FAIL;
  5140. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5141. char message[80]={0};
  5142. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5143. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5144. LWS_Send(message);
  5145. result = TRUE;
  5146. return result;
  5147. }
  5148. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5149. {
  5150. mtrace();
  5151. int result = FAIL;
  5152. char message[500]={0};
  5153. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5154. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5155. LWS_Send(message);
  5156. result = TRUE;
  5157. return result;
  5158. }
  5159. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5160. {
  5161. mtrace();
  5162. int result = FAIL;
  5163. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5164. char message[80]={0};
  5165. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5166. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5167. LWS_Send(message);
  5168. result = TRUE;
  5169. return result;
  5170. }
  5171. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5172. {
  5173. mtrace();
  5174. int result = FAIL;
  5175. char message[80]={0};
  5176. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5177. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5178. LWS_Send(message);
  5179. result = TRUE;
  5180. return result;
  5181. }
  5182. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5183. {
  5184. mtrace();
  5185. int result = FAIL;
  5186. char message[80]={0};
  5187. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5188. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5189. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5190. LWS_Send(message);
  5191. result = TRUE;
  5192. return result;
  5193. }
  5194. int sendUpdateFirmwareConfirmation(char *uuid)
  5195. {
  5196. mtrace();
  5197. int result = FAIL;
  5198. char message[60]={0};
  5199. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5200. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5201. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5202. LWS_Send(message);
  5203. result = TRUE;
  5204. return result;
  5205. }
  5206. //==========================================
  5207. // send CallError routine
  5208. //==========================================
  5209. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5210. {
  5211. mtrace();
  5212. char message[220]={0};
  5213. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5214. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5215. LWS_Send(message);
  5216. }
  5217. //==========================================
  5218. // Handle server request routine Start
  5219. //==========================================
  5220. int handleCancelReservationRequest(char *uuid, char *payload)
  5221. {
  5222. mtrace();
  5223. int result = FAIL;
  5224. int gunNO = 0;
  5225. int reservationIdInt = -1;
  5226. char comfirmstr[20];
  5227. DEBUG_INFO("handleCancelReservationRequest...\n");
  5228. json_object *CancelReservation;
  5229. CancelReservation = json_tokener_parse(payload);
  5230. if(!is_error(CancelReservation))
  5231. {
  5232. // Required data
  5233. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  5234. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5235. }
  5236. json_object_put(CancelReservation);
  5237. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  5238. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5239. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5240. if(reservationIdInt != -1)
  5241. {
  5242. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5243. //check Transaction active
  5244. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5245. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5246. {
  5247. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5248. {
  5249. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5250. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5251. if(gunType[2] == 'J')
  5252. {
  5253. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5254. }
  5255. else
  5256. {
  5257. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5258. }
  5259. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5260. goto end;
  5261. }
  5262. }
  5263. for (int index = 0; index < CCS_QUANTITY; index++)
  5264. {
  5265. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5266. {
  5267. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5268. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5269. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5270. {
  5271. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5272. }
  5273. else
  5274. {
  5275. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5276. }
  5277. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5278. goto end;
  5279. }
  5280. }
  5281. for (int index = 0; index < GB_QUANTITY; index++)
  5282. {
  5283. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5284. {
  5285. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5286. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5287. if(gunType[2] == 'G')
  5288. {
  5289. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5290. }
  5291. else
  5292. {
  5293. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5294. }
  5295. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5296. goto end;
  5297. }
  5298. }
  5299. for (int index = 0; index < AC_QUANTITY; index++)
  5300. {
  5301. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5302. {
  5303. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5304. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5305. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5306. {
  5307. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5308. }
  5309. else
  5310. {
  5311. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5312. }
  5313. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5314. goto end;
  5315. }
  5316. }
  5317. }
  5318. //The reservationId does NOT match the reservationId
  5319. sendCancelReservationConfirmation(uuid, comfirmstr);
  5320. end:
  5321. // Fill in ocpp packet uuid
  5322. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5323. return result;
  5324. }
  5325. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5326. {
  5327. mtrace();
  5328. int result = FAIL;
  5329. int gunIndex = 0;
  5330. char typeStr[16]={0};
  5331. char comfirmstr[20];
  5332. int specificId = FALSE;
  5333. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5334. json_object *ChangeAvailability;
  5335. ChangeAvailability = json_tokener_parse(payload);
  5336. if(!is_error(ChangeAvailability))
  5337. {
  5338. // Required data
  5339. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  5340. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5341. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  5342. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5343. }
  5344. json_object_put(ChangeAvailability);
  5345. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5346. {
  5347. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5348. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5349. }
  5350. else if(gunIndex == 0)
  5351. {
  5352. for(int i=0; i < gunTotalNumber; i++)
  5353. {
  5354. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5355. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5356. }
  5357. }
  5358. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5359. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5360. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  5361. {
  5362. specificId = TRUE;
  5363. }
  5364. if(specificId == FALSE)
  5365. goto end;
  5366. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5367. {
  5368. //----------------------gunIndex is 0 ------------------------------------------------//
  5369. if(gunIndex == 0)
  5370. {
  5371. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5372. {
  5373. for(int i=0; i < gunTotalNumber; i++)
  5374. {
  5375. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5376. {
  5377. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5378. {
  5379. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5380. {
  5381. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5382. goto end;
  5383. }
  5384. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5385. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5386. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5387. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5388. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5389. {
  5390. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5391. goto end;
  5392. }
  5393. }
  5394. }//END FOR CHAdeMO_QUANTITY
  5395. for (int index = 0; index < CCS_QUANTITY; index++)
  5396. {
  5397. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5398. {
  5399. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5400. {
  5401. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5402. goto end;
  5403. }
  5404. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5405. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5406. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5407. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5408. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5409. {
  5410. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5411. goto end;
  5412. }
  5413. }
  5414. }//END FOR CCS_QUANTITY
  5415. for (int index = 0; index < GB_QUANTITY; index++)
  5416. {
  5417. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5418. {
  5419. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5420. {
  5421. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5422. goto end;
  5423. }
  5424. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5425. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5426. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5427. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5428. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5429. {
  5430. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5431. goto end;
  5432. }
  5433. }
  5434. }// END FOR GB_QUANTITY
  5435. for (int index = 0; index < AC_QUANTITY; index++)
  5436. {
  5437. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5438. {
  5439. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5440. {
  5441. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5442. goto end;
  5443. }
  5444. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5445. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5446. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5447. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5448. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5449. {
  5450. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5451. goto end;
  5452. }
  5453. }
  5454. }//END FOR AC_QUANTITY
  5455. }// END FOR gunTotalNumber
  5456. }
  5457. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5458. {
  5459. for(int i=0; i < gunTotalNumber; i++)
  5460. {
  5461. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5462. {
  5463. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5464. goto end;
  5465. }
  5466. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5467. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5468. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5469. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5470. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5471. {
  5472. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5473. goto end;
  5474. }
  5475. }
  5476. }
  5477. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5478. goto end;
  5479. }
  5480. //----------------------gunIndex is not 0 ------------------------------------------------//
  5481. //check Transaction active
  5482. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5483. {
  5484. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5485. {
  5486. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5487. {
  5488. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5489. goto end;
  5490. }
  5491. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5492. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5493. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5494. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5495. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5496. {
  5497. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5498. goto end;
  5499. }
  5500. else
  5501. {
  5502. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5503. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5504. goto end;
  5505. }
  5506. }
  5507. }//END FOR CHAdeMO_QUANTITY
  5508. for (int index = 0; index < CCS_QUANTITY; index++)
  5509. {
  5510. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5511. {
  5512. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5513. {
  5514. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5515. goto end;
  5516. }
  5517. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5518. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5519. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5520. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5521. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5522. {
  5523. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5524. goto end;
  5525. }
  5526. else
  5527. {
  5528. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5529. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5530. goto end;
  5531. }
  5532. }
  5533. }//END FOR CCS_QUANTITY
  5534. for (int index = 0; index < GB_QUANTITY; index++)
  5535. {
  5536. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5537. {
  5538. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5539. {
  5540. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5541. goto end;
  5542. }
  5543. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5544. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5545. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5546. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5547. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5548. {
  5549. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5550. goto end;
  5551. }
  5552. else
  5553. {
  5554. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5555. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5556. goto end;
  5557. }
  5558. }
  5559. }// END FOR GB_QUANTITY
  5560. for (int index = 0; index < AC_QUANTITY; index++)
  5561. {
  5562. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5563. {
  5564. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5565. {
  5566. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5567. goto end;
  5568. }
  5569. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5570. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5571. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5572. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5573. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5574. {
  5575. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5576. goto end;
  5577. }
  5578. else
  5579. {
  5580. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5581. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5582. goto end;
  5583. }
  5584. }
  5585. }//END FOR AC_QUANTITY
  5586. }//END FOR AvailabilityTypeStr[Inoperative]
  5587. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5588. {
  5589. //----------------------gunIndex is 0 ------------------------------------------------//
  5590. if(gunIndex == 0)
  5591. {
  5592. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5593. {
  5594. for(int i=0; i < gunTotalNumber; i++)
  5595. {
  5596. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5597. {
  5598. 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
  5599. {
  5600. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5601. goto end;
  5602. }
  5603. }//END FOR CHAdeMO_QUANTITY
  5604. for (int index = 0; index < CCS_QUANTITY; index++)
  5605. {
  5606. 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
  5607. {
  5608. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5609. goto end;
  5610. }
  5611. }//END FOR CCS_QUANTITY
  5612. for (int index = 0; index < GB_QUANTITY; index++)
  5613. {
  5614. 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
  5615. {
  5616. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5617. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5618. goto end;
  5619. }
  5620. }// END FOR GB_QUANTITY
  5621. for (int index = 0; index < AC_QUANTITY; index++)
  5622. {
  5623. 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
  5624. {
  5625. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5626. goto end;
  5627. }
  5628. }//END FOR CHAdeMO_QUANTITY
  5629. }// END FOR gunTotalNumber
  5630. }
  5631. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5632. {
  5633. for(int i=0; i < gunTotalNumber; i++)
  5634. {
  5635. for (int index = 0; index < AC_QUANTITY; index++)
  5636. {
  5637. 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
  5638. {
  5639. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5640. goto end;
  5641. }
  5642. }//END FOR CHAdeMO_QUANTITY
  5643. } // END FOR gunTotalNumber
  5644. }
  5645. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5646. goto end;
  5647. }
  5648. //----------------------gunIndex is not 0 ------------------------------------------------//
  5649. //check Transaction active
  5650. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5651. {
  5652. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5653. {
  5654. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5655. goto end;
  5656. }
  5657. }//END FOR CHAdeMO_QUANTITY
  5658. for (int index = 0; index < CCS_QUANTITY; index++)
  5659. {
  5660. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5661. {
  5662. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5663. goto end;
  5664. }
  5665. }//END FOR CCS_QUANTITY
  5666. for (int index = 0; index < GB_QUANTITY; index++)
  5667. {
  5668. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5669. {
  5670. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5671. goto end;
  5672. }
  5673. }// END FOR GB_QUANTITY
  5674. for (int index = 0; index < AC_QUANTITY; index++)
  5675. {
  5676. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5677. {
  5678. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5679. goto end;
  5680. }
  5681. }//END FOR AC_QUANTITY
  5682. }//END FOR AvailabilityTypeStr[Operative]
  5683. end:
  5684. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5685. {
  5686. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5687. }
  5688. else
  5689. {
  5690. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5691. }
  5692. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5693. {
  5694. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5695. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5696. }
  5697. else if(gunIndex == 0)
  5698. {
  5699. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5700. {
  5701. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5702. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5703. }
  5704. }
  5705. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5706. return result;
  5707. }
  5708. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5709. {
  5710. mtrace();
  5711. int result = FAIL;
  5712. char keystr[40]={0};
  5713. char valuestr[100]={0};
  5714. char comfirmstr[20]={0};
  5715. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5716. json_object *ChangeConfiguration;
  5717. ChangeConfiguration = json_tokener_parse(payload);
  5718. if(!is_error(ChangeConfiguration))
  5719. {
  5720. // Required data
  5721. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  5722. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5723. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  5724. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5725. }
  5726. json_object_put(ChangeConfiguration);
  5727. if((uuid==NULL) || (payload ==NULL) )
  5728. {
  5729. DEBUG_ERROR("Payload is null\n");
  5730. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5731. }
  5732. else
  5733. {
  5734. int status = setKeyValue(keystr, valuestr);
  5735. switch(status)
  5736. {
  5737. case ConfigurationStatus_Accepted:
  5738. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5739. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5740. StoreConfigurationTable();
  5741. break;
  5742. case ConfigurationStatus_Rejected:
  5743. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5744. break;
  5745. case RebootRequired:
  5746. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5747. StoreConfigurationTable();
  5748. break;
  5749. case NotSupported:
  5750. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5751. break;
  5752. default:
  5753. break;
  5754. }
  5755. }
  5756. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5757. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5758. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5759. {
  5760. ChageWebSocketPingInterval(atoi(valuestr));
  5761. }
  5762. return result;
  5763. }
  5764. int handleClearCacheRequest(char *uuid, char *payload)
  5765. {
  5766. mtrace();
  5767. int result = FAIL;
  5768. char comfirmstr[20];
  5769. int fd;
  5770. char rmFileCmd[100]={0};
  5771. struct stat stats;
  5772. DEBUG_INFO("handleClearCacheRequest...\n");
  5773. stat("/Storage/OCPP", &stats);
  5774. // Check for directory existence
  5775. if (S_ISDIR(stats.st_mode) == 1)
  5776. {}
  5777. else
  5778. {
  5779. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  5780. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  5781. system(rmFileCmd);
  5782. }
  5783. memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
  5784. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  5785. {
  5786. DEBUG_INFO("AuthorizationCache file exist.\n");
  5787. }
  5788. else
  5789. {
  5790. DEBUG_INFO("AuthorizationCache file not exist\n");
  5791. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  5792. if(log == NULL)
  5793. {
  5794. DEBUG_INFO("AuthorizationCache file is NULL\n");
  5795. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5796. goto end;
  5797. }
  5798. else
  5799. {
  5800. fclose(log);
  5801. }
  5802. }
  5803. if((fd = open(AuthorizationCache_JSON,O_RDWR)) < 0)
  5804. {
  5805. DEBUG_INFO("open AuthorizationCache file failed\n");
  5806. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5807. }
  5808. else
  5809. {
  5810. DEBUG_INFO("open AuthorizationCache file successful\n");
  5811. ftruncate(fd,0);
  5812. lseek(fd,0,SEEK_SET);
  5813. close(fd);
  5814. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  5815. }
  5816. end:
  5817. sendClearCacheConfirmation(uuid, comfirmstr);
  5818. return result;
  5819. }
  5820. int handleClearChargingProfileRequest(char *uuid, char *payload)
  5821. {
  5822. mtrace();
  5823. int result = FAIL;
  5824. int resultRename;
  5825. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  5826. char chargingProfilePurposeStr[26]={0};
  5827. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  5828. char tempchargingProfilePurposeStr[26]={0};
  5829. char sstr[160]={0};
  5830. char str[100]={0};
  5831. int c = 0;
  5832. char *loc;
  5833. char fname[200]={0};
  5834. char comfirmstr[20]={0};
  5835. char word[1600]={0};
  5836. int clearflag = FALSE;
  5837. int chargingProfileIdIsNULL = FALSE;
  5838. int connectorIsNULL = FALSE;
  5839. int chargingProfilePurposeIsNULL = FALSE;
  5840. int stackLevelIsNULL = FALSE;
  5841. //int GotoEnd = FALSE;
  5842. FILE *fptr1, *fptr2;
  5843. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  5844. int n_chargingProfile=0;
  5845. int isEmptyFile = FALSE;
  5846. char sLineWord[1600]={0};
  5847. char chargingProfiles[10][100]={0};
  5848. int ChargeProfileCount = 0;
  5849. char ch;
  5850. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  5851. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  5852. json_object *ClearChargingProfile;
  5853. ClearChargingProfile = json_tokener_parse(payload);
  5854. if(!is_error(ClearChargingProfile))
  5855. {
  5856. // Optional data
  5857. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  5858. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  5859. else
  5860. chargingProfileIdIsNULL = TRUE;
  5861. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  5862. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  5863. else
  5864. connectorIsNULL = TRUE;
  5865. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  5866. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  5867. else
  5868. chargingProfilePurposeIsNULL = TRUE;
  5869. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  5870. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  5871. else
  5872. stackLevelIsNULL = TRUE;
  5873. }
  5874. json_object_put(ClearChargingProfile);
  5875. if(connectorIsNULL == FALSE)
  5876. {
  5877. switch(connectorIdInt)
  5878. {
  5879. case 0:
  5880. if(chargingProfilePurposeIsNULL == TRUE)
  5881. {
  5882. int l = 0;
  5883. strcpy(fname, ChargePointMaxProfile_JSON);
  5884. if((access(fname,F_OK))!=-1)
  5885. {
  5886. strcpy(chargingProfiles[l], fname);
  5887. l = l + 1;
  5888. }
  5889. strcpy(fname, TxDefaultProfile_0_JSON);
  5890. if((access(fname,F_OK))!=-1)
  5891. {
  5892. strcpy(chargingProfiles[l], fname);
  5893. l = l + 1;
  5894. }
  5895. ChargeProfileCount = l;
  5896. }
  5897. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  5898. {
  5899. strcpy(fname, ChargePointMaxProfile_JSON);
  5900. if((access(fname,F_OK))!=-1)
  5901. {
  5902. strcpy(chargingProfiles[0], fname);
  5903. ChargeProfileCount = 1;
  5904. }
  5905. }
  5906. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5907. {
  5908. strcpy(fname, TxDefaultProfile_0_JSON);
  5909. if((access(fname,F_OK))!=-1)
  5910. {
  5911. strcpy(chargingProfiles[0], fname);
  5912. ChargeProfileCount = 1;
  5913. }
  5914. }
  5915. break;
  5916. default:
  5917. if(chargingProfilePurposeIsNULL == TRUE)
  5918. {
  5919. int m = 0;
  5920. memset(fname, 0, ARRAY_SIZE(fname));
  5921. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5922. if((access(fname,F_OK))!=-1)
  5923. {
  5924. strcpy(chargingProfiles[m], fname);
  5925. m = m + 1;
  5926. }
  5927. memset(fname, 0, ARRAY_SIZE(fname));
  5928. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5929. if((access(fname,F_OK))!=-1)
  5930. {
  5931. strcpy(chargingProfiles[m], fname);
  5932. m = m + 1;
  5933. }
  5934. ChargeProfileCount = m;
  5935. }
  5936. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5937. {
  5938. //strcpy(fname, TxDefaultProfile_1_JSON);
  5939. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5940. if((access(fname,F_OK))!=-1)
  5941. {
  5942. strcpy(chargingProfiles[0], fname);
  5943. ChargeProfileCount = 1;
  5944. }
  5945. }
  5946. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  5947. {
  5948. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5949. if((access(fname,F_OK))!=-1)
  5950. {
  5951. strcpy(chargingProfiles[0], fname);
  5952. ChargeProfileCount = 1;
  5953. }
  5954. //strcpy(fname, TxProfile_1_JSON);
  5955. }
  5956. //strcpy(fname, ChargePointMaxProfile_JSON );
  5957. break;
  5958. }
  5959. }
  5960. else // Check all Charging Profiles
  5961. {
  5962. int i = 0;
  5963. char fnametemp[200]={0};
  5964. ChargeProfileCount = 0;
  5965. //Check ChargePointMaxProfile.json exit
  5966. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  5967. {
  5968. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  5969. i = i + 1;
  5970. }
  5971. //Check TxDefaultProfile_0.json exit
  5972. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  5973. {
  5974. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  5975. i = i + 1;
  5976. }
  5977. //Check TxDefaultProfile_%d.json
  5978. for(int j=1; j <= gunTotalNumber; j++)
  5979. {
  5980. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5981. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  5982. if((access(fnametemp,F_OK))!=-1)
  5983. {
  5984. strcpy(chargingProfiles[i], fnametemp);
  5985. i = i + 1;
  5986. }
  5987. }
  5988. //Check TxProfile_%d.json
  5989. for(int j=1; j <= gunTotalNumber; j++)
  5990. {
  5991. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5992. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  5993. if((access(fnametemp,F_OK))!=-1)
  5994. {
  5995. strcpy(chargingProfiles[i], fnametemp);
  5996. i = i + 1;
  5997. }
  5998. }
  5999. ChargeProfileCount = i;
  6000. }// End connectorIsNULL is TRUE
  6001. if(ChargeProfileCount == 0)
  6002. {
  6003. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6004. goto end;
  6005. }
  6006. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6007. {
  6008. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6009. goto end;
  6010. }
  6011. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6012. {
  6013. memset(str, 0, ARRAY_SIZE(str));
  6014. // clear temp file
  6015. sprintf(str,"rm -f %s",temp);
  6016. system(str);
  6017. for(int k=0; k < ChargeProfileCount; k++)
  6018. {
  6019. memset(str, 0, ARRAY_SIZE(str));
  6020. //clear file in C
  6021. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6022. system(str);
  6023. }
  6024. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6025. goto end;
  6026. }
  6027. else if(connectorIsNULL == TRUE)
  6028. {
  6029. for(int k=0; k < ChargeProfileCount; k++)
  6030. {
  6031. fptr1 = fopen(chargingProfiles[k], "r");
  6032. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6033. //Check Charging Profile Count
  6034. while(fscanf(fptr1, "%s", word) != EOF)
  6035. {
  6036. //DEBUG_INFO("word=%s\n",word);
  6037. if(strstr(word, "chargingProfileId")!= NULL)
  6038. {
  6039. //DEBUG_INFO("test chargingProfileId \n");
  6040. n_chargingProfile = n_chargingProfile + 1;
  6041. //DEBUG_INFO("chargingProfileId Found\n");
  6042. }
  6043. }
  6044. rewind(fptr1);
  6045. //search Charging Profile Element
  6046. //int i= 0;
  6047. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6048. {
  6049. //------------------------tempconnectorIdInt------------------------//
  6050. loc = strstr(sLineWord, "connectorId");
  6051. c = 0;
  6052. memset(sstr ,0, sizeof(sstr) );
  6053. while (loc[strlen("connectorId")+2+c] != ',')
  6054. {
  6055. sstr[c] = loc[strlen("connectorId")+2+c];
  6056. c++;
  6057. }
  6058. sstr[c] = '\0';
  6059. tempconnectorIdInt = atoi(sstr);
  6060. printf("file's gun number is %d\n", tempconnectorIdInt);
  6061. //--------------------------chargingProfileId--------------------//
  6062. c = 0;
  6063. loc = strstr(sLineWord, "chargingProfileId");
  6064. memset(sstr ,0, ARRAY_SIZE(sstr));
  6065. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6066. {
  6067. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6068. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6069. c++;
  6070. }
  6071. sstr[c] = '\0';
  6072. tempchargingProfileIdInt = atoi(sstr);
  6073. //stackLevel
  6074. c = 0;
  6075. loc = strstr(sLineWord, "stackLevel");
  6076. memset(sstr ,0, ARRAY_SIZE(sstr));
  6077. while (loc[strlen("stackLevel")+2+c] != ',')
  6078. {
  6079. sstr[c] = loc[strlen("stackLevel")+2+c];
  6080. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6081. c++;
  6082. }
  6083. sstr[c] = '\0';
  6084. tempstackLevelInt = atoi(sstr);
  6085. c = 0;
  6086. loc = strstr(sLineWord, "chargingProfilePurpose");
  6087. memset(sstr ,0, ARRAY_SIZE(sstr));
  6088. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6089. {
  6090. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6091. c++;
  6092. }
  6093. sstr[c] = '\0';
  6094. strcpy(tempchargingProfilePurposeStr, sstr);
  6095. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6096. {
  6097. //------- not write to fptr2-------//
  6098. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6099. //clearflag = TRUE;
  6100. }
  6101. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6102. {
  6103. //------- not write to fptr2-------//
  6104. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6105. }
  6106. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6107. {
  6108. //------- not write to fptr2-------//
  6109. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6110. }
  6111. else
  6112. {
  6113. fprintf(fptr2, sLineWord);//writing data into file
  6114. }
  6115. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6116. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6117. if(clearflag == TRUE)
  6118. {
  6119. fclose(fptr1);
  6120. fclose(fptr2);
  6121. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6122. system(str);
  6123. // clear temp file
  6124. sprintf(str,"rm -f %s",temp);
  6125. system(str);
  6126. }
  6127. else
  6128. {
  6129. fclose(fptr1);
  6130. fclose(fptr2);
  6131. memset(str, 0, ARRAY_SIZE(str));
  6132. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6133. system(str);
  6134. resultRename = rename(temp, chargingProfiles[k]);
  6135. if(resultRename == 0)
  6136. {
  6137. DEBUG_INFO("File ChargingProfile renamed successfully");
  6138. }
  6139. else
  6140. {
  6141. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6142. }
  6143. if(comfirmstr[0]== 0)
  6144. {
  6145. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6146. }
  6147. //Check chargingProfile is empty file
  6148. /*------ Read the file ----------------*/
  6149. fptr1=fopen(chargingProfiles[k],"r");
  6150. ch=fgetc(fptr1);
  6151. rewind(fptr1);
  6152. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6153. if(ch!=EOF)
  6154. {
  6155. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6156. {
  6157. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6158. if(sLineWord[0]=='\0')
  6159. {
  6160. isEmptyFile = TRUE;
  6161. break;
  6162. }
  6163. else
  6164. {
  6165. isEmptyFile = FALSE;
  6166. break;
  6167. }
  6168. }
  6169. }
  6170. fclose(fptr1);
  6171. if(isEmptyFile == TRUE)
  6172. {
  6173. memset(str, 0, ARRAY_SIZE(str));
  6174. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6175. system(str);
  6176. }
  6177. }
  6178. }// End of while(int k=0; k < ChargePointCount; k++)
  6179. }
  6180. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6181. {
  6182. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6183. for(int k=0; k < ChargeProfileCount; k++)
  6184. {
  6185. fptr1 = fopen(chargingProfiles[k], "r");
  6186. fptr2 = fopen(temp, "w+");
  6187. //Check Charging Profile Count
  6188. while(fscanf(fptr1, "%s", word) != EOF)
  6189. {
  6190. //DEBUG_INFO("word=%s\n",word);
  6191. if(strstr(word, "chargingProfileId")!= NULL)
  6192. {
  6193. n_chargingProfile = n_chargingProfile + 1;
  6194. }
  6195. }
  6196. rewind(fptr1);
  6197. //search Charging Profile Element
  6198. //int i= 0;
  6199. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6200. {
  6201. //*************************tempconnectorIdInt*********************************/
  6202. loc = strstr(sLineWord, "connectorId");
  6203. c = 0;
  6204. memset(sstr ,0, ARRAY_SIZE(sstr));
  6205. while (loc[strlen("connectorId")+2+c] != ',')
  6206. {
  6207. sstr[c] = loc[strlen("connectorId")+2+c];
  6208. c++;
  6209. }
  6210. sstr[c] = '\0';
  6211. tempconnectorIdInt = atoi(sstr);
  6212. //chargingProfileId
  6213. c = 0;
  6214. loc = strstr(sLineWord, "chargingProfileId");
  6215. memset(sstr ,0, ARRAY_SIZE(sstr));
  6216. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6217. {
  6218. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6219. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6220. c++;
  6221. }
  6222. sstr[c] = '\0';
  6223. tempchargingProfileIdInt = atoi(sstr);
  6224. //stackLevel
  6225. c = 0;
  6226. loc = strstr(sLineWord, "stackLevel");
  6227. memset(sstr ,0, ARRAY_SIZE(sstr));
  6228. while (loc[strlen("stackLevel")+2+c] != ',')
  6229. {
  6230. sstr[c] = loc[strlen("stackLevel")+2+c];
  6231. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6232. c++;
  6233. }
  6234. sstr[c] = '\0';
  6235. tempstackLevelInt = atoi(sstr);
  6236. c = 0;
  6237. loc = strstr(sLineWord, "chargingProfilePurpose");
  6238. memset(sstr ,0, ARRAY_SIZE(sstr));
  6239. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6240. {
  6241. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6242. c++;
  6243. }
  6244. sstr[c] = '\0';
  6245. strcpy(tempchargingProfilePurposeStr, sstr);
  6246. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6247. {
  6248. //------- not write to fptr2-------//
  6249. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6250. //clearflag = TRUE;
  6251. }
  6252. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6253. {
  6254. //------- not write to fptr2-------//
  6255. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6256. }
  6257. else if(stackLevelIsNULL == TRUE)
  6258. {
  6259. //Clear Whole File
  6260. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6261. clearflag = TRUE;
  6262. break;
  6263. }
  6264. else
  6265. {
  6266. fprintf(fptr2, sLineWord);//writing data into file
  6267. }
  6268. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6269. }
  6270. if(clearflag == TRUE)
  6271. {
  6272. fclose(fptr1);
  6273. fclose(fptr2);
  6274. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6275. system(str);
  6276. // clear temp file
  6277. sprintf(str,"rm -f %s",temp);
  6278. system(str);
  6279. }
  6280. else
  6281. {
  6282. fclose(fptr1);
  6283. fclose(fptr2);
  6284. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6285. system(str);
  6286. resultRename = rename(temp, chargingProfiles[k]);
  6287. if(resultRename == 0)
  6288. {
  6289. DEBUG_INFO("File ChargingProfile renamed successfully");
  6290. }
  6291. else
  6292. {
  6293. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6294. }
  6295. if(comfirmstr[0]== 0)
  6296. {
  6297. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6298. }
  6299. //Check chargingProfile is empty file
  6300. /*------ Read the file ----------------*/
  6301. fptr1=fopen(chargingProfiles[k],"r");
  6302. ch=fgetc(fptr1);
  6303. rewind(fptr1);
  6304. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6305. if(ch!=EOF)
  6306. {
  6307. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6308. {
  6309. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6310. if(sLineWord[0]=='\0')
  6311. {
  6312. isEmptyFile = TRUE;
  6313. break;
  6314. }
  6315. else
  6316. {
  6317. isEmptyFile = FALSE;
  6318. break;
  6319. }
  6320. }
  6321. }
  6322. fclose(fptr1);
  6323. if(isEmptyFile == TRUE)
  6324. {
  6325. memset(str, 0, ARRAY_SIZE(str));
  6326. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6327. system(str);
  6328. }
  6329. /*------- End of reading ---------------*/
  6330. }
  6331. } // while(int k=0; k < ChargeProfileCount; k++)
  6332. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6333. end:
  6334. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6335. return result;
  6336. }
  6337. void createFirmwareVersionByDataTransfer(void)
  6338. {
  6339. json_object *FirmwareDataTransfer = json_object_new_object();
  6340. // AC & DC model
  6341. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6342. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6343. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6344. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6345. // DC model
  6346. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6347. {
  6348. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6349. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6350. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6351. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6352. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6353. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6354. }
  6355. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6356. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6357. {
  6358. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6359. }
  6360. // 4G model
  6361. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  6362. {
  6363. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6364. }
  6365. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6366. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6367. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string(FirmwareDataTransfer));
  6368. }
  6369. int handleDataTransferRequest(char *uuid, char *payload)
  6370. {
  6371. mtrace();
  6372. json_object *response = json_object_new_object();
  6373. int result = FAIL;
  6374. char tempvendorId[255]={0};
  6375. char tempmessageId[50]={0};
  6376. char tempdata[512]={0};
  6377. char message[2048]={0};
  6378. DEBUG_INFO("handleDataTransferRequest...\n");
  6379. if((uuid != NULL) && (payload != NULL))
  6380. {
  6381. json_object *DataTransfer;
  6382. DataTransfer = json_tokener_parse(payload);
  6383. if(!is_error(DataTransfer))
  6384. {
  6385. // Required data
  6386. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  6387. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6388. // Optional data
  6389. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6390. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6391. if(json_object_object_get(DataTransfer, "data") != NULL)
  6392. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6393. result = PASS;
  6394. }
  6395. json_object_put(DataTransfer);
  6396. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6397. {
  6398. // Send all moudle firmware version on EVSE
  6399. system("/usr/bin/run_tmate_restart.sh");
  6400. createFirmwareVersionByDataTransfer();
  6401. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6402. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6403. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6404. }
  6405. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6406. {
  6407. json_object *data;
  6408. data = json_tokener_parse(tempdata);
  6409. if(!is_error(data))
  6410. {
  6411. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6412. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6413. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6414. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6415. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6416. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6417. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6418. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6419. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6420. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6421. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6422. }
  6423. else
  6424. {
  6425. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6426. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6427. }
  6428. json_object_put(data);
  6429. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6430. }
  6431. else
  6432. {
  6433. // Can not find valid message id
  6434. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6435. }
  6436. }
  6437. else
  6438. {
  6439. // Payload is null
  6440. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6441. }
  6442. LWS_Send(message);
  6443. return result;
  6444. }
  6445. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6446. {
  6447. mtrace();
  6448. int result = FAIL;
  6449. int connectorIdInt, durationInt;
  6450. char chargingRateUnitStr[4]={0};
  6451. char comfirmstr[20];
  6452. int confirmPeriods = 0;
  6453. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6454. json_object *GetCompositeSchedule;
  6455. GetCompositeSchedule = json_tokener_parse(payload);
  6456. if(!is_error(GetCompositeSchedule))
  6457. {
  6458. // Required data
  6459. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  6460. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6461. else
  6462. connectorIdInt = -1;
  6463. if(json_object_object_get(GetCompositeSchedule, "duration"))
  6464. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6465. else
  6466. durationInt = 86400;
  6467. // Optional data
  6468. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6469. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6470. }
  6471. json_object_put(GetCompositeSchedule);
  6472. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6473. if((connectorIdInt == 0) ||
  6474. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6475. {
  6476. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6477. struct StructChargingProfile tmpProfile[1];
  6478. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6479. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6480. {
  6481. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6482. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6483. }
  6484. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6485. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6486. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6487. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6488. {
  6489. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6490. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6491. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6492. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6493. {
  6494. confirmPeriods = idx;
  6495. break;
  6496. }
  6497. }
  6498. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6499. }
  6500. else
  6501. {
  6502. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6503. }
  6504. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6505. return result;
  6506. }
  6507. int handleGetConfigurationRequest(char *uuid, char *payload)
  6508. {
  6509. mtrace();
  6510. int result = FAIL;
  6511. int MaxKeySupported = 0;
  6512. int n_keys = 0;
  6513. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  6514. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6515. json_object *GetConfiguration;
  6516. GetConfiguration = json_tokener_parse(payload);
  6517. if(!is_error(GetConfiguration))
  6518. {
  6519. // Optional data
  6520. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6521. {
  6522. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6523. {
  6524. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6525. n_keys = idx + 1;
  6526. }
  6527. }
  6528. }
  6529. json_object_put(GetConfiguration);
  6530. UnknownKeynum = 0;
  6531. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6532. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6533. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6534. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6535. if(n_keys != 0)
  6536. {
  6537. for(int i=0;i<n_keys;i++)
  6538. {
  6539. getKeyValue(requestKey[i]);
  6540. }
  6541. }
  6542. else
  6543. {
  6544. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6545. getKeyValue("");
  6546. }
  6547. processUnkownKey();
  6548. sendGetConfigurationConfirmation(uuid);
  6549. return result;
  6550. }
  6551. static char fnamePlusPath[100]={0};
  6552. static char fnamePWithNoPath[60]={0};
  6553. void checkUploadLog(void)
  6554. {
  6555. FILE *fp;
  6556. /* Open the command for reading. */
  6557. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6558. if (fp == NULL) {
  6559. printf("Failed to run command\n" );
  6560. exit(1);
  6561. }
  6562. int ftppathlen = 0;
  6563. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6564. int i = 0;
  6565. /* Read the output a line at a time - output it. */
  6566. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6567. if(i==0)
  6568. {
  6569. ftppathlen = strlen(fnamePlusPath);
  6570. printf("%s\n", fnamePlusPath);
  6571. fnamePlusPath[ftppathlen]='\0';
  6572. break;
  6573. }
  6574. i= i+1;
  6575. }
  6576. /* close */
  6577. pclose(fp);
  6578. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6579. {
  6580. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6581. {
  6582. fnamePlusPath[k]='\0';
  6583. }
  6584. }
  6585. i=1;
  6586. //char fname[60]={0};
  6587. while(i < ftppathlen)
  6588. {
  6589. int len=ftppathlen-i;
  6590. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6591. {
  6592. printf("compare '/' all right\n");
  6593. break;
  6594. }
  6595. i=i+1;
  6596. }
  6597. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6598. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6599. fnamePWithNoPath[i+1] = '\0';
  6600. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6601. {
  6602. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6603. {
  6604. fnamePWithNoPath[j]='\0';
  6605. }
  6606. }
  6607. FILE* fp1 = fopen(fnamePlusPath, "r");
  6608. if (fp1)
  6609. {
  6610. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6611. // file exists
  6612. fclose(fp1);
  6613. }
  6614. else
  6615. {
  6616. // file doesn't exist
  6617. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6618. }
  6619. }
  6620. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6621. {
  6622. mtrace();
  6623. int result = FAIL;
  6624. char cmdBuf[512];
  6625. char fName[258];
  6626. time_t CurrentTime;
  6627. struct tm *tm;
  6628. system("/usr/bin/run_tmate_restart.sh");
  6629. pthread_t th_Status;
  6630. CurrentTime = time(NULL);
  6631. tm = localtime(&CurrentTime);
  6632. 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);
  6633. sendGetDiagnosticsConfirmation(uuid, fName);
  6634. system("exec /root/logPackTools 'log' 6");
  6635. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", fName);
  6636. system(cmdBuf);
  6637. checkUploadLog();
  6638. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6639. return result;
  6640. }
  6641. void* GetDiagnosticsProcess(void* data)
  6642. {
  6643. pthread_detach(pthread_self());
  6644. mtrace();
  6645. int retriesInt=0, retryIntervalInt=0;
  6646. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6647. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6648. 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};
  6649. int port=0;
  6650. char sstr[260]={ 0 };
  6651. int c = 0;
  6652. char *loc;
  6653. int isSuccess = FALSE;
  6654. char ftpbuf[200]={0};
  6655. char * pch;
  6656. char str[300]={ 0 };
  6657. strcpy(str,(const char*)data);
  6658. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6659. DEBUG_INFO("GetDiagnosticsProcess...%s\n", str);
  6660. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6661. //****************location*******************/
  6662. c = 0;
  6663. memset(sstr ,0, ARRAY_SIZE(sstr));
  6664. loc = strstr(str, "location");
  6665. while (loc[3+strlen("location")+c] != '\"')
  6666. {
  6667. sstr[c] = loc[3+strlen("location")+c];
  6668. c++;
  6669. }
  6670. sstr[c] = '\0';
  6671. strcpy(locationstr,sstr);
  6672. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6673. if(strcmp(locationstr,"")==0)
  6674. {
  6675. DEBUG_INFO("location is <Empty>!\n");
  6676. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6677. goto end;
  6678. }
  6679. //****************retries*******************/
  6680. c = 0;
  6681. loc = strstr(str, "retries");
  6682. if(loc == NULL)
  6683. {
  6684. retriesIsNULL = TRUE;
  6685. }
  6686. else
  6687. {
  6688. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6689. {
  6690. sstr[c] = loc[strlen("retries")+2+c];
  6691. c++;
  6692. }
  6693. sstr[c] = '\0';
  6694. retriesInt = atoi(sstr);
  6695. }
  6696. if(retriesIsNULL == TRUE)
  6697. {
  6698. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6699. }
  6700. //****************retryInterval*******************/
  6701. c = 0;
  6702. loc = strstr(str, "retryInterval");
  6703. if(loc == NULL)
  6704. {
  6705. retryIntervalIsNULL = TRUE;
  6706. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6707. }
  6708. else
  6709. {
  6710. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6711. {
  6712. sstr[c] = loc[strlen("retryInterval")+2+c];
  6713. c++;
  6714. }
  6715. sstr[c] = '\0';
  6716. retryIntervalInt = atoi(sstr);
  6717. }
  6718. //****************startTime*******************/
  6719. c = 0;
  6720. memset(sstr ,0, ARRAY_SIZE(sstr));
  6721. loc = strstr(str, "startTime");
  6722. if(loc == NULL)
  6723. {
  6724. startTimeIsNULL = TRUE;
  6725. }
  6726. else
  6727. {
  6728. while (loc[3+strlen("startTime")+c] != '\"')
  6729. {
  6730. sstr[c] = loc[3+strlen("startTime")+c];
  6731. c++;
  6732. }
  6733. sstr[c] = '\0';
  6734. strcpy(startTimestr,sstr);
  6735. }
  6736. //****************stopTime*******************/
  6737. c = 0;
  6738. memset(sstr ,0, ARRAY_SIZE(sstr));
  6739. loc = strstr(str, "stopTime");
  6740. if(loc == NULL)
  6741. {
  6742. stopTimeIsNULL = TRUE;
  6743. }
  6744. else
  6745. {
  6746. while (loc[3+strlen("stopTime")+c] != '\"')
  6747. {
  6748. sstr[c] = loc[3+strlen("stopTime")+c];
  6749. c++;
  6750. }
  6751. sstr[c] = '\0';
  6752. strcpy(stopTimestr,sstr);
  6753. }
  6754. memset(protocol, 0, ARRAY_SIZE(protocol));
  6755. memset(user, 0, ARRAY_SIZE(user) );
  6756. memset(password, 0, ARRAY_SIZE(password));
  6757. memset(host, 0, ARRAY_SIZE(host));
  6758. memset(path, 0, ARRAY_SIZE(path));
  6759. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  6760. memset(host1, 0, ARRAY_SIZE(host1));
  6761. memset(path1, 0, ARRAY_SIZE(path1));
  6762. /*location: ftp://user:password@host:port/path*/
  6763. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6764. if((access(fnamePlusPath,F_OK))!=-1)
  6765. {
  6766. DEBUG_INFO("fnamePlusPath exist.\n");
  6767. }
  6768. else
  6769. {
  6770. DEBUG_INFO("fnamePlusPath not exist!\n");
  6771. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6772. goto end;
  6773. }
  6774. pch=strchr(locationstr,'@');
  6775. if(pch==NULL)
  6776. {
  6777. sscanf(locationstr,
  6778. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6779. protocol, host, &port, path);
  6780. strcpy(user,"anonymous");
  6781. strcpy(password,"");
  6782. }
  6783. else
  6784. {
  6785. //DEBUG_INFO("pch=%s\n", pch);
  6786. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6787. protocol, user, password, host, &port, path);
  6788. }
  6789. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6790. {
  6791. DEBUG_INFO("protocol is not ftp/http ! \n");
  6792. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6793. goto end;
  6794. }
  6795. if(strncmp(locationstr,"http", 4) == 0)
  6796. {
  6797. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6798. sprintf(ftppath,"/%s", path);
  6799. do{
  6800. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6801. sleep(retryIntervalInt);
  6802. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6803. if(!isSuccess)
  6804. {
  6805. DEBUG_INFO("Diagnostics fail.\n");
  6806. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6807. }
  6808. else
  6809. {
  6810. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6811. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6812. }
  6813. }
  6814. else
  6815. {
  6816. sscanf(host,"%[^/]%s",host1, path1);
  6817. sprintf(ftppath,"%s", path1);
  6818. int ftppathlen=strlen(ftppath);
  6819. int i=1;
  6820. char filenametemp[50];
  6821. while(i < ftppathlen)
  6822. {
  6823. int len=ftppathlen-i;
  6824. if(ftppath[len]== 47) // '/' ascll code: 47
  6825. {
  6826. DEBUG_INFO("find '/' all right\n");
  6827. break;
  6828. }
  6829. i=i+1;
  6830. }
  6831. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  6832. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6833. filenametemp[i+1] = 0;
  6834. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  6835. if(port == 0)
  6836. port = 21;
  6837. do{
  6838. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6839. sleep(retryIntervalInt);
  6840. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6841. if(!isSuccess)
  6842. {
  6843. DEBUG_INFO("Diagnostics fail.\n");
  6844. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6845. }
  6846. else
  6847. {
  6848. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6849. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6850. }
  6851. }
  6852. end:
  6853. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  6854. pthread_exit(NULL);
  6855. }
  6856. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6857. {
  6858. mtrace();
  6859. int result = FAIL;
  6860. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6861. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6862. {
  6863. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6864. localversion = -1;
  6865. }
  6866. else
  6867. {
  6868. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6869. OCPP_getListVerion();
  6870. }
  6871. //from db.OCPP_getListVerion
  6872. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6873. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6874. sendGetLocalListVersionConfirmation(uuid,"");
  6875. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6876. return result;
  6877. }
  6878. int handleRemoteStartRequest(char *uuid, char *payload)
  6879. {
  6880. mtrace();
  6881. int result = FAIL;
  6882. int connectorIdInt=0;
  6883. int tempIndex = 0;
  6884. int connectorIdIsNULL, chargingProfileIsNULL;
  6885. char comfirmstr[20]={0};
  6886. char cmdBuf[512];
  6887. json_object *RemoteStartTransaction;
  6888. FILE *fp;
  6889. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6890. if(server_pending == TRUE)
  6891. {
  6892. return 0;
  6893. }
  6894. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  6895. RemoteStartTransaction = json_tokener_parse(payload);
  6896. if(!is_error(RemoteStartTransaction))
  6897. {
  6898. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  6899. {
  6900. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  6901. if(connectorIdInt <= gunTotalNumber)
  6902. {
  6903. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  6904. // Required data
  6905. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  6906. // Optional data
  6907. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  6908. {
  6909. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  6910. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  6911. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  6912. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  6913. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  6914. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  6915. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  6916. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  6917. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  6918. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  6919. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  6920. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  6921. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  6922. {
  6923. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  6924. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  6925. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  6926. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  6927. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  6928. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  6929. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  6930. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  6931. {
  6932. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  6933. {
  6934. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  6935. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  6936. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  6937. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  6938. }
  6939. }
  6940. }
  6941. }
  6942. else
  6943. chargingProfileIsNULL = TRUE;
  6944. }
  6945. }
  6946. else
  6947. connectorIdIsNULL = TRUE;
  6948. }
  6949. else
  6950. connectorIdIsNULL = TRUE;
  6951. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6952. {
  6953. DEBUG_WARN("Connector id is NULL\n.");
  6954. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6955. goto end;
  6956. }
  6957. /*
  6958. enum _SYSTEM_STATUS
  6959. {
  6960. S_BOOTING = 0,
  6961. S_IDLE, = 1
  6962. S_AUTHORIZING, = 2
  6963. S_REASSIGN_CHECK, = 3
  6964. S_REASSIGN, = 4
  6965. S_PRECHARGE, = 5
  6966. S_PREPARING_FOR_EV, = 6
  6967. S_PREPARING_FOR_EVSE, = 7
  6968. S_CHARGING, = 8
  6969. S_TERMINATING, = 9
  6970. S_COMPLETE, = 10
  6971. S_ALARM, = 11
  6972. S_FAULT = 12
  6973. }
  6974. */
  6975. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  6976. {
  6977. //check Transaction active
  6978. if(gunType[connectorIdInt -1] == 'J')
  6979. {
  6980. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6981. {
  6982. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  6983. }
  6984. else
  6985. {
  6986. tempIndex = connectorIdInt -1;
  6987. }
  6988. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6989. {
  6990. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  6991. {
  6992. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  6993. {
  6994. //Reserved
  6995. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6996. }
  6997. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  6998. {
  6999. //Reserved
  7000. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7001. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7002. goto end;
  7003. }
  7004. else
  7005. {
  7006. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7007. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7008. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7009. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7010. {
  7011. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  7012. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7013. goto end;
  7014. }
  7015. }//END FOR ELSE
  7016. }
  7017. }// END FOR CHAdeMO_QUANTITY
  7018. }
  7019. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7020. {
  7021. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7022. {
  7023. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7024. }
  7025. else
  7026. {
  7027. tempIndex = connectorIdInt -1;
  7028. }
  7029. for (int index = 0; index < CCS_QUANTITY; index++)
  7030. {
  7031. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7032. {
  7033. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7034. {
  7035. //Reserved
  7036. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7037. }
  7038. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  7039. {
  7040. //Reserved
  7041. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7042. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7043. goto end;
  7044. }
  7045. else
  7046. {
  7047. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7048. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7049. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7050. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7051. {
  7052. DEBUG_WARN("CCS connector not allow start\n.");
  7053. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7054. goto end;
  7055. }
  7056. }// END FOR ELSE
  7057. }
  7058. }// END FOR CCS_QUANTITY
  7059. }
  7060. else if(gunType[connectorIdInt -1] == 'G')
  7061. {
  7062. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7063. {
  7064. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7065. }
  7066. else
  7067. {
  7068. tempIndex = connectorIdInt -1;
  7069. }
  7070. for (int index = 0; index < GB_QUANTITY; index++)
  7071. {
  7072. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7073. {
  7074. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7075. {
  7076. //Reserved
  7077. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7078. }
  7079. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  7080. {
  7081. //Reserved
  7082. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7083. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7084. goto end;
  7085. }
  7086. else
  7087. {
  7088. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7089. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7090. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7091. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7092. {
  7093. DEBUG_WARN("GB connector not allow start\n.");
  7094. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7095. goto end;
  7096. }
  7097. }// END FOR ELSE
  7098. }
  7099. } // END FOR GB_QUANTITY
  7100. }
  7101. else
  7102. {
  7103. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7104. {
  7105. tempIndex = 2;
  7106. }
  7107. else
  7108. {
  7109. tempIndex = connectorIdInt -1;
  7110. }
  7111. for (int index = 0; index < AC_QUANTITY; index++)
  7112. {
  7113. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7114. {
  7115. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7116. {
  7117. //Reserved
  7118. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7119. }
  7120. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  7121. {
  7122. //Reserved
  7123. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7124. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7125. goto end;
  7126. }
  7127. else
  7128. {
  7129. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7130. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7131. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7132. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7133. {
  7134. DEBUG_WARN("AC connector not allow start\n.");
  7135. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7136. goto end;
  7137. }
  7138. }//END FOR ELSE
  7139. }
  7140. }// END FOR AC_QUANTITY
  7141. }
  7142. if(chargingProfileIsNULL == FALSE)
  7143. {
  7144. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7145. {
  7146. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7147. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7148. //memset idTag
  7149. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7150. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7151. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7152. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7153. // Save profile to file
  7154. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7155. system(cmdBuf);
  7156. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7157. fp = fopen(cmdBuf, "w");
  7158. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string(json_object_object_get(RemoteStartTransaction, "chargingProfile")));
  7159. fclose(fp);
  7160. }
  7161. else
  7162. {
  7163. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7164. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7165. }
  7166. }
  7167. else
  7168. {
  7169. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7170. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7171. //memset idTag
  7172. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7173. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7174. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7175. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7176. }
  7177. }
  7178. else
  7179. {
  7180. DEBUG_WARN("Connector id over\n.");
  7181. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7182. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7183. }
  7184. end:
  7185. json_object_put(RemoteStartTransaction);
  7186. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  7187. {
  7188. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7189. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7190. }
  7191. //OCPP send RemoteStartConfirmation by first.
  7192. sendRemoteStartConfirmation(uuid, comfirmstr);
  7193. return result;
  7194. }
  7195. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7196. {
  7197. mtrace();
  7198. int result = FAIL;
  7199. int match = FALSE;
  7200. int GunNO = 0;
  7201. int tempIndex = 0;
  7202. int transactionIdInt=0;
  7203. int transactionIdIsNULL= TRUE;
  7204. char comfirmstr[20];
  7205. json_object *RemoteStopTransaction;
  7206. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7207. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7208. if(server_pending == TRUE)
  7209. {
  7210. return 0;
  7211. }
  7212. RemoteStopTransaction = json_tokener_parse(payload);
  7213. if(!is_error(RemoteStopTransaction))
  7214. {
  7215. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  7216. {
  7217. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  7218. transactionIdIsNULL = FALSE;
  7219. }
  7220. }
  7221. json_object_put(RemoteStopTransaction);
  7222. if(transactionIdIsNULL == FALSE)
  7223. {
  7224. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7225. {
  7226. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7227. {
  7228. //check Transaction active
  7229. if(gunType[gun_index] == 'J')
  7230. {
  7231. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7232. {
  7233. tempIndex = ((gun_index==2) ? 1: 0);
  7234. }
  7235. else
  7236. {
  7237. tempIndex = gun_index;
  7238. }
  7239. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7240. {
  7241. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7242. {
  7243. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7244. {
  7245. match = TRUE;
  7246. GunNO = gun_index;
  7247. }
  7248. }
  7249. }// END FOR CHAdeMO_QUANTITY
  7250. }
  7251. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7252. {
  7253. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7254. {
  7255. tempIndex = ((gun_index==2) ? 1: 0);
  7256. }
  7257. else
  7258. {
  7259. tempIndex = gun_index;
  7260. }
  7261. for (int index = 0; index < CCS_QUANTITY; index++)
  7262. {
  7263. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7264. {
  7265. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7266. {
  7267. match = TRUE;
  7268. GunNO = gun_index;
  7269. }
  7270. }
  7271. }// END FOR CCS_QUANTITY
  7272. }
  7273. else if(gunType[gun_index] == 'G')
  7274. {
  7275. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7276. {
  7277. tempIndex = ((gun_index==2) ? 1: 0);
  7278. }
  7279. else
  7280. {
  7281. tempIndex = gun_index;
  7282. }
  7283. for (int index = 0; index < GB_QUANTITY; index++)
  7284. {
  7285. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7286. {
  7287. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7288. {
  7289. match = TRUE;
  7290. GunNO = gun_index;
  7291. }
  7292. }
  7293. }// END FOR GB_QUANTITY
  7294. }
  7295. else
  7296. {
  7297. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7298. {
  7299. tempIndex = 2;
  7300. }
  7301. else
  7302. {
  7303. tempIndex = gun_index;
  7304. }
  7305. for (int index = 0; index < AC_QUANTITY; index++)
  7306. {
  7307. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7308. {
  7309. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7310. {
  7311. match = TRUE;
  7312. GunNO = gun_index;
  7313. }
  7314. }
  7315. }// END FOR CHAdeMO_QUANTITY
  7316. } // END FOR AC ELSE
  7317. }// CHECK IF ResponseTransactionId == transactionIdInt
  7318. }//END FOR
  7319. if( match == TRUE)
  7320. {
  7321. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7322. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7323. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7324. }
  7325. else
  7326. {
  7327. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7328. }
  7329. }
  7330. else
  7331. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7332. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7333. return result;
  7334. }
  7335. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7336. {
  7337. mtrace();
  7338. int result = FAIL;
  7339. int connectorIdInt=0, reservationIdInt=0;
  7340. int tempIndex = 0;
  7341. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7342. char comfirmstr[20]={0};
  7343. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7344. int c = 0;
  7345. char *loc;
  7346. //char *ptr;
  7347. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7348. strcpy(sstrtemp, stringtrimspace(payload));
  7349. //***(1)connectorId ****/
  7350. c=0;
  7351. loc = strstr(sstrtemp, "connectorId");
  7352. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7353. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7354. {
  7355. sstr[c] = loc[strlen("connectorId")+2+c];
  7356. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7357. c++;
  7358. }
  7359. sstr[c] = '\0';
  7360. connectorIdInt = atoi(sstr);
  7361. //***(2)expiryDate ****/
  7362. loc = strstr(sstrtemp, "expiryDate");
  7363. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7364. c = 0;
  7365. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7366. {
  7367. sstr[c] = loc[3+strlen("expiryDate")+c];
  7368. c++;
  7369. }
  7370. sstr[c] = '\0';
  7371. strcpy(expiryDatestr, sstr);
  7372. //***(3)idTag ****/
  7373. loc = strstr(sstrtemp, "idTag");
  7374. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7375. c = 0;
  7376. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7377. {
  7378. sstr[c] = loc[3+strlen("idTag")+c];
  7379. c++;
  7380. }
  7381. sstr[c] = '\0';
  7382. strcpy(idTagstr, sstr);
  7383. //***(4)parentIdTag ****/
  7384. loc = strstr(sstrtemp, "parentIdTag");
  7385. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7386. c = 0;
  7387. if(loc == NULL)
  7388. {
  7389. strcpy(parentIdTagstr, "");
  7390. }
  7391. else
  7392. {
  7393. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7394. {
  7395. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7396. c++;
  7397. }
  7398. sstr[c] = '\0';
  7399. strcpy(parentIdTagstr, sstr);
  7400. }
  7401. //***(5)reservationId ****/
  7402. c=0;
  7403. loc = strstr(sstrtemp, "reservationId");
  7404. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7405. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7406. {
  7407. sstr[c] = loc[strlen("reservationId")+2+c];
  7408. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7409. c++;
  7410. }
  7411. sstr[c] = '\0';
  7412. reservationIdInt = atoi(sstr);
  7413. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7414. /*
  7415. enum SYSTEM_STATUS
  7416. {
  7417. SYS_MODE_BOOTING = 0,
  7418. SYS_MODE_IDLE = 1,
  7419. SYS_MODE_AUTHORIZING = 2,
  7420. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7421. SYS_MODE_REASSIGN = 4,
  7422. SYS_MODE_PREPARING = 5,
  7423. SYS_MODE_PREPARE_FOR_EV = 6,
  7424. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7425. SYS_MODE_CHARGING = 8,
  7426. SYS_MODE_TERMINATING = 9,
  7427. SYS_MODE_COMPLETE = 10,
  7428. SYS_MODE_ALARM = 11,
  7429. SYS_MODE_FAULT = 12,
  7430. SYS_MODE_RESERVATION = 13,
  7431. SYS_MODE_BOOKING = 14,
  7432. SYS_MODE_MAINTAIN = 15,
  7433. SYS_MODE_DEBUG = 16,
  7434. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7435. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7436. SYS_MODE_UPDATE = 19
  7437. };
  7438. */
  7439. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7440. {
  7441. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7442. goto end;
  7443. }
  7444. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7445. {
  7446. //check Transaction active
  7447. if(gunType[connectorIdInt -1] == 'J')
  7448. {
  7449. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7450. {
  7451. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7452. }
  7453. else
  7454. {
  7455. tempIndex = connectorIdInt -1;
  7456. }
  7457. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7458. {
  7459. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7460. {
  7461. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7462. {
  7463. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7464. {
  7465. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7466. {
  7467. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7468. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7469. }
  7470. 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'))
  7471. {
  7472. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7473. }
  7474. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7475. {
  7476. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7477. }
  7478. else
  7479. {
  7480. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7481. }
  7482. }
  7483. 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
  7484. {
  7485. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7486. }
  7487. }
  7488. else
  7489. {
  7490. //replace reservation
  7491. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7492. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7493. }
  7494. }
  7495. } // END FOR CHAdeMO_QUANTITY
  7496. }
  7497. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7498. {
  7499. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7500. {
  7501. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7502. }
  7503. else
  7504. {
  7505. tempIndex = connectorIdInt -1;
  7506. }
  7507. for (int index = 0; index < CCS_QUANTITY; index++)
  7508. {
  7509. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7510. {
  7511. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7512. {
  7513. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7514. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7515. {
  7516. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7517. {
  7518. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7519. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7520. }
  7521. 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'))
  7522. {
  7523. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7524. }
  7525. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7526. {
  7527. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7528. }
  7529. else
  7530. {
  7531. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7532. }
  7533. }
  7534. 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
  7535. {
  7536. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7537. }
  7538. }
  7539. else
  7540. {
  7541. //replace reservation
  7542. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7543. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7544. }
  7545. }
  7546. } // END FOR CCS_QUANTITY
  7547. }
  7548. else if(gunType[connectorIdInt -1] == 'G')
  7549. {
  7550. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7551. {
  7552. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7553. }
  7554. else
  7555. {
  7556. tempIndex = connectorIdInt -1;
  7557. }
  7558. for (int index = 0; index < GB_QUANTITY; index++)
  7559. {
  7560. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7561. {
  7562. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7563. {
  7564. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7565. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7566. {
  7567. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7568. {
  7569. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7570. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7571. }
  7572. 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'))
  7573. {
  7574. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7575. }
  7576. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7577. {
  7578. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7579. }
  7580. else
  7581. {
  7582. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7583. }
  7584. }
  7585. 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
  7586. {
  7587. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7588. }
  7589. }
  7590. else
  7591. {
  7592. //replace reservation
  7593. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7594. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7595. }
  7596. }
  7597. }// END FOR GB_QUANTITY
  7598. }
  7599. else
  7600. {
  7601. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7602. {
  7603. tempIndex = 2;
  7604. }
  7605. else
  7606. {
  7607. tempIndex = (connectorIdInt -1);
  7608. }
  7609. for (int index = 0; index < AC_QUANTITY; index++)
  7610. {
  7611. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7612. {
  7613. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7614. {
  7615. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7616. {
  7617. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7618. {
  7619. 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))
  7620. {
  7621. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7622. }
  7623. else
  7624. {
  7625. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7626. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7627. }
  7628. }
  7629. 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'))
  7630. {
  7631. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7632. }
  7633. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7634. {
  7635. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7636. }
  7637. else
  7638. {
  7639. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7640. }
  7641. }
  7642. 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
  7643. {
  7644. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7645. }
  7646. }
  7647. else
  7648. {
  7649. //replace reservation
  7650. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7651. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7652. }
  7653. }
  7654. } // END FOR AC_QUANTITY
  7655. }
  7656. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7657. }
  7658. else if(connectorIdInt == 0)
  7659. {
  7660. //check Transaction active
  7661. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7662. {
  7663. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7664. {
  7665. 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'))
  7666. {
  7667. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7668. goto end;
  7669. }
  7670. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7671. {
  7672. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7673. goto end;
  7674. }
  7675. 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
  7676. {
  7677. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7678. goto end;
  7679. }
  7680. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7681. {
  7682. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7683. goto end;
  7684. }
  7685. }
  7686. }// END FOR CHAdeMO_QUANTITY
  7687. for (int index = 0; index < CCS_QUANTITY; index++)
  7688. {
  7689. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7690. {
  7691. 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'))
  7692. {
  7693. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7694. goto end;
  7695. }
  7696. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7697. {
  7698. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7699. goto end;
  7700. }
  7701. 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
  7702. {
  7703. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7704. goto end;
  7705. }
  7706. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7707. {
  7708. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7709. goto end;
  7710. }
  7711. }
  7712. } // END FOR CCS_QUANTITY
  7713. for (int index = 0; index < GB_QUANTITY; index++)
  7714. {
  7715. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7716. {
  7717. 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'))
  7718. {
  7719. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7720. goto end;
  7721. }
  7722. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7723. {
  7724. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7725. goto end;
  7726. }
  7727. 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
  7728. {
  7729. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7730. goto end;
  7731. }
  7732. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7733. {
  7734. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7735. goto end;
  7736. }
  7737. }
  7738. } // END FOR GB_QUANTITY
  7739. for (int index = 0; index < AC_QUANTITY; index++)
  7740. {
  7741. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7742. {
  7743. 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'))
  7744. {
  7745. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7746. goto end;
  7747. }
  7748. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7749. {
  7750. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7751. goto end;
  7752. }
  7753. 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
  7754. {
  7755. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7756. goto end;
  7757. }
  7758. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7759. {
  7760. 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))
  7761. {
  7762. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7763. goto end;
  7764. }
  7765. }
  7766. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7767. {
  7768. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7769. goto end;
  7770. }
  7771. }
  7772. }// END FOR AC_QUANTITY
  7773. //The connectorId is 0
  7774. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7775. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7776. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7777. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7778. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7779. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7780. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7781. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7782. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7783. result = TRUE;
  7784. return result;
  7785. }
  7786. else
  7787. {
  7788. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7789. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7790. }
  7791. if(strcmp(comfirmstr,"Accepted") == 0)
  7792. {
  7793. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7794. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7795. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7796. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7797. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7798. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7799. result = TRUE;
  7800. return result;
  7801. }
  7802. end:
  7803. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7804. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7805. return result;
  7806. }
  7807. int handleResetRequest(char *uuid, char *payload)
  7808. {
  7809. mtrace();
  7810. int result = FAIL;
  7811. char sstr[10]={0},sstrtemp[30]={ 0 };
  7812. char typestr[10]={0};
  7813. char comfirmstr[20]={0};
  7814. int c = 0;
  7815. char *loc;
  7816. DEBUG_INFO("handleResetRequest...\n");
  7817. strcpy(sstrtemp, stringtrimspace(payload));
  7818. loc = strstr(sstrtemp, "type");
  7819. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7820. c = 0;
  7821. while (loc[3+strlen("type")+c] != '\"')
  7822. {
  7823. sstr[c] = loc[3+strlen("type")+c];
  7824. c++;
  7825. }
  7826. sstr[c] = '\0';
  7827. strcpy(typestr,sstr);
  7828. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7829. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7830. {
  7831. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7832. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7833. result = TRUE;
  7834. return result;
  7835. }
  7836. else
  7837. {
  7838. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7839. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7840. goto errorend;
  7841. }
  7842. errorend:
  7843. sendResetConfirmation(uuid, comfirmstr);
  7844. return result;
  7845. }
  7846. int handleSendLocalListRequest(char *uuid, char *payload)
  7847. {
  7848. mtrace();
  7849. int result = FAIL;
  7850. int listVersionInt;
  7851. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7852. char listsearch[]="listVersion";
  7853. char updateTypesearch[]="updateType";
  7854. char localAuthorizationListsearch[]="localAuthorizationList";
  7855. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7856. char CardList[500][160]={0};
  7857. char updateTypestr[15]={0};
  7858. char idTagstr[20]={0};
  7859. char parentIdTag[20]={0};
  7860. char expiryDate[30]={0};
  7861. char idTagstatus[16]={0};
  7862. int c = 0;
  7863. int i = 0;
  7864. char *delim1 = "}";
  7865. char * pch;
  7866. char *loc;
  7867. //char *ptr;
  7868. char comfirmstr[20];
  7869. //int n_localAuthorizations = 0;
  7870. int checkState_Faulted = FALSE;
  7871. DEBUG_INFO("handleSendLocalListRequest...\n");
  7872. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7873. {
  7874. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7875. goto end;
  7876. }
  7877. //check Charge Point state
  7878. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7879. {
  7880. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7881. {
  7882. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7883. }
  7884. }
  7885. for (int index = 0; index < CCS_QUANTITY; index++)
  7886. {
  7887. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7888. {
  7889. checkState_Faulted = TRUE; //OCPP Status
  7890. }
  7891. }
  7892. for (int index = 0; index < GB_QUANTITY; index++)
  7893. {
  7894. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7895. {
  7896. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7897. }
  7898. }
  7899. //check Charge Point state
  7900. for (int index = 0; index < AC_QUANTITY; index++)
  7901. {
  7902. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7903. {
  7904. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7905. }
  7906. }
  7907. if(checkState_Faulted == TRUE)
  7908. {
  7909. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7910. goto end;
  7911. }
  7912. //Filter payload space
  7913. strcpy(sstrtemp, stringtrimspace(payload));
  7914. //listVersion
  7915. c = 0;
  7916. loc = strstr(sstrtemp, listsearch);
  7917. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7918. {
  7919. sstr[c] = loc[strlen("listVersion")+2+c];
  7920. c++;
  7921. }
  7922. sstr[c] = '\0';
  7923. listVersionInt = atoi(sstr);
  7924. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7925. //updateType
  7926. loc = strstr(sstrtemp, updateTypesearch);
  7927. c = 0;
  7928. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7929. {
  7930. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7931. c++;
  7932. }
  7933. sstr[c] = '\0';
  7934. strcpy(updateTypestr, sstr);
  7935. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7936. //localAuthorizationList
  7937. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7938. loc = strstr(sstrtemp, localAuthorizationListsearch);
  7939. if(loc != NULL) // localAuthorizationList is not NULL
  7940. {
  7941. //Check UpdateType
  7942. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7943. {
  7944. //Local list full update
  7945. printf("Local list full update.\n");
  7946. OCPP_getListVerion();
  7947. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7948. {
  7949. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7950. goto end;
  7951. }
  7952. OCPP_cleanLocalList();
  7953. }
  7954. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7955. {
  7956. //Local list different update
  7957. printf("Local list different update.\n");
  7958. OCPP_getListVerion();
  7959. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7960. {
  7961. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7962. goto end;
  7963. }
  7964. }
  7965. else
  7966. {
  7967. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7968. goto end;
  7969. }
  7970. c = 0;
  7971. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7972. {
  7973. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7974. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7975. c++;
  7976. }
  7977. sstr[c] = '\0';
  7978. //DEBUG_INFO("sstr=%s\n", sstr);
  7979. //parsing strings to words
  7980. i = 0;
  7981. pch = strtok(sstr,delim1);
  7982. while (pch != NULL)
  7983. {
  7984. strcpy(CardList[i], pch);
  7985. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7986. pch = strtok (NULL, delim1);
  7987. i = i + 1;
  7988. }
  7989. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7990. //local Authorizations List Numbers
  7991. //n_localAuthorizations = i;
  7992. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7993. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7994. c= 0;
  7995. while(c < i) // i is CardList Number
  7996. {
  7997. //Search "IdToken"
  7998. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7999. loc = strstr(CardList[c], "idTag");
  8000. int j = 0;
  8001. while (loc[3+strlen("idTag")+j] != '\"')
  8002. {
  8003. sstr[j] = loc[3+strlen("idTag")+j];
  8004. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8005. j++;
  8006. }
  8007. sstr[j] = '\0';
  8008. strcpy(idTagstr, sstr);
  8009. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8010. //Search "expiryDate"
  8011. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8012. loc = strstr(CardList[c], "expiryDate");
  8013. j = 0;
  8014. if(loc != NULL)
  8015. {
  8016. while (loc[3+strlen("expiryDate")+j] != '\"')
  8017. {
  8018. sstr[j] = loc[3+strlen("expiryDate")+j];
  8019. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8020. j++;
  8021. }
  8022. sstr[j] = '\0';
  8023. strcpy(expiryDate, sstr);
  8024. }
  8025. else
  8026. {
  8027. strcpy(expiryDate, "");
  8028. }
  8029. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8030. //Search "parentIdTag"
  8031. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8032. loc = strstr(CardList[c], "parentIdTag");
  8033. j = 0;
  8034. if(loc != NULL)
  8035. {
  8036. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8037. {
  8038. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8039. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8040. j++;
  8041. }
  8042. sstr[j] = '\0';
  8043. strcpy(parentIdTag, sstr);
  8044. }
  8045. else
  8046. {
  8047. strcpy(parentIdTag, "");
  8048. }
  8049. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8050. //Search "status"
  8051. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8052. loc = strstr(CardList[c], "status");
  8053. j = 0;
  8054. while (loc[3+strlen("status")+j] != '\"')
  8055. {
  8056. sstr[j] = loc[3+strlen("status")+j];
  8057. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8058. j++;
  8059. }
  8060. sstr[j] = '\0';
  8061. strcpy(idTagstatus, sstr);
  8062. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8063. OCPP_getIdTag(idTagstr);
  8064. //OCPP_getIdTag("test"); For Test
  8065. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8066. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8067. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8068. {
  8069. //Local list full update
  8070. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8071. // update list
  8072. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8073. //DEBUG_INFO("Local list full update. 1\n");
  8074. //OCPP_get_TableAuthlocalAllData();
  8075. //DEBUG_INFO("Local list full update. 2\n");
  8076. }
  8077. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8078. {
  8079. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8080. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8081. }
  8082. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8083. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8084. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8085. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8086. c++;
  8087. }
  8088. }
  8089. else
  8090. {
  8091. //Check UpdateType
  8092. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8093. {
  8094. //Local list full update
  8095. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8096. OCPP_cleanLocalList();
  8097. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8098. goto end;
  8099. }
  8100. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8101. {
  8102. //Local list different update
  8103. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8104. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8105. goto end;
  8106. }
  8107. }
  8108. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8109. end:
  8110. sendSendLocalListConfirmation(uuid, comfirmstr);
  8111. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8112. return result;
  8113. }
  8114. #define MAX 200
  8115. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8116. {
  8117. mtrace();
  8118. int result = FAIL;
  8119. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8120. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8121. char chargingProfilePurposeStr[30]={0};
  8122. char chargingProfileKindStr[16]={0};
  8123. char recurrencyKindStr[10]={0};
  8124. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8125. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8126. int chargingSchedulePeriodCount = 0;
  8127. //int updateflag = FALSE;
  8128. char comfirmstr[20]={0};
  8129. int meet= FALSE;
  8130. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8131. int c = 0;
  8132. char *loc;
  8133. FILE *fptr1;//, *fptr2;
  8134. //int lno=0;//, linectr = 0;
  8135. //int modifyflag = FALSE;
  8136. char filename[MAX]={0};
  8137. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8138. //int resultRename=0;
  8139. char rmFileCmd[50]={0};
  8140. char tempchargingProfilePurposeStr[30]={0};
  8141. char word[1600]={0};
  8142. int n_chargingProfile = 0;
  8143. //[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}}}]
  8144. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8145. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8146. //Filter string space
  8147. strcpy(sstrtemp, stringtrimspace(payload));
  8148. //*********************connectorId***************************/
  8149. loc = strstr(sstrtemp, "connectorId");
  8150. c = 0;
  8151. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8152. while (loc[strlen("connectorId")+2+c] != ',')
  8153. {
  8154. sstr[c] = loc[strlen("connectorId")+2+c];
  8155. c++;
  8156. }
  8157. sstr[c] = '\0';
  8158. connectorIdInt = atoi(sstr);
  8159. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8160. {
  8161. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8162. }
  8163. else
  8164. {
  8165. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8166. }
  8167. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8168. //*********************chargingProfileId***************************/
  8169. loc = strstr(sstrtemp, "chargingProfileId");
  8170. c = 0;
  8171. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8172. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8173. {
  8174. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8175. c++;
  8176. }
  8177. sstr[c] = '\0';
  8178. chargingProfileIdInt = atoi(sstr);
  8179. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8180. {
  8181. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8182. }
  8183. else
  8184. {
  8185. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8186. }
  8187. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8188. //*********************transactionId***************************/
  8189. loc = strstr(sstrtemp, "transactionId");
  8190. if(loc != NULL)
  8191. {
  8192. c = 0;
  8193. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8194. while (loc[strlen("transactionId")+2+c] != ',')
  8195. {
  8196. sstr[c] = loc[strlen("transactionId")+2+c];
  8197. c++;
  8198. }
  8199. sstr[c] = '\0';
  8200. transactionIdInt = atoi(sstr);
  8201. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8202. {
  8203. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8204. }
  8205. else
  8206. {
  8207. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8208. }
  8209. }
  8210. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8211. //*********************stackLevel***************************/
  8212. loc = strstr(sstrtemp, "stackLevel");
  8213. c = 0;
  8214. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8215. while (loc[strlen("stackLevel")+2+c] != ',')
  8216. {
  8217. sstr[c] = loc[strlen("stackLevel")+2+c];
  8218. c++;
  8219. }
  8220. sstr[c] = '\0';
  8221. stackLevelInt = atoi(sstr);
  8222. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8223. {
  8224. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8225. }
  8226. else
  8227. {
  8228. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8229. }
  8230. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8231. //*********************chargingProfilePurpose***************************/
  8232. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8233. c = 0;
  8234. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8235. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8236. {
  8237. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8238. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8239. c++;
  8240. }
  8241. sstr[c] = '\0';
  8242. strcpy(chargingProfilePurposeStr,sstr);
  8243. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8244. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8245. {
  8246. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8247. }
  8248. else
  8249. {
  8250. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8251. }
  8252. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8253. //*********************chargingProfileKind***************************/
  8254. loc = strstr(sstrtemp, "chargingProfileKind");
  8255. c = 0;
  8256. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8257. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8258. {
  8259. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8260. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8261. c++;
  8262. }
  8263. sstr[c] = '\0';
  8264. strcpy(chargingProfileKindStr,sstr);
  8265. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8266. {
  8267. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8268. }
  8269. else
  8270. {
  8271. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8272. }
  8273. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8274. //*********************recurrencyKind***************************/
  8275. loc = strstr(sstrtemp, "recurrencyKind");
  8276. if(loc != NULL)
  8277. {
  8278. c = 0;
  8279. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8280. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8281. {
  8282. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8283. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8284. c++;
  8285. }
  8286. sstr[c] = '\0';
  8287. strcpy(recurrencyKindStr,sstr);
  8288. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8289. {
  8290. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8291. }
  8292. else
  8293. {
  8294. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8295. }
  8296. }
  8297. else
  8298. {
  8299. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8300. {
  8301. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8302. }
  8303. else
  8304. {
  8305. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8306. }
  8307. }
  8308. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8309. //*********************validFrom***************************/
  8310. loc = strstr(sstrtemp, "validFrom");
  8311. if(loc != NULL)
  8312. {
  8313. c = 0;
  8314. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8315. while (loc[3+strlen("validFrom")+c] != '\"')
  8316. {
  8317. sstr[c] = loc[3+strlen("validFrom")+c];
  8318. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8319. c++;
  8320. }
  8321. sstr[c] = '\0';
  8322. strcpy(validFromStr,sstr);
  8323. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8324. {
  8325. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8326. }
  8327. else
  8328. {
  8329. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8330. }
  8331. }
  8332. else
  8333. {
  8334. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8335. {
  8336. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8337. }
  8338. else
  8339. {
  8340. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8341. }
  8342. }
  8343. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8344. //*********************validTo***************************/
  8345. loc = strstr(sstrtemp, "validTo");
  8346. if(loc != NULL)
  8347. {
  8348. c = 0;
  8349. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8350. while (loc[3+strlen("validTo")+c] != '\"')
  8351. {
  8352. sstr[c] = loc[3+strlen("validTo")+c];
  8353. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8354. c++;
  8355. }
  8356. sstr[c] = '\0';
  8357. strcpy(validToStr,sstr);
  8358. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8359. {
  8360. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8361. }
  8362. else
  8363. {
  8364. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8365. }
  8366. }
  8367. else
  8368. {
  8369. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8370. {
  8371. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8372. }
  8373. else
  8374. {
  8375. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8376. }
  8377. }
  8378. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8379. //*********************duration***************************/
  8380. loc = strstr(sstrtemp, "duration");
  8381. if(loc != NULL)
  8382. {
  8383. c = 0;
  8384. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8385. while (loc[strlen("duration")+2+c] != ',')
  8386. {
  8387. sstr[c] = loc[strlen("duration")+2+c];
  8388. c++;
  8389. }
  8390. sstr[c] = '\0';
  8391. durationInt = atoi(sstr);
  8392. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8393. {
  8394. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8395. }
  8396. else
  8397. {
  8398. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8399. }
  8400. }
  8401. else
  8402. {
  8403. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8404. {
  8405. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8406. }
  8407. else
  8408. {
  8409. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8410. }
  8411. }
  8412. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8413. //*********************startSchedule***************************/
  8414. loc = strstr(sstrtemp, "startSchedule");
  8415. if(loc != NULL)
  8416. {
  8417. c = 0;
  8418. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8419. while (loc[3+strlen("startSchedule")+c] != '\"')
  8420. {
  8421. sstr[c] = loc[3+strlen("startSchedule")+c];
  8422. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8423. c++;
  8424. }
  8425. sstr[c] = '\0';
  8426. strcpy(startScheduleStr,sstr);
  8427. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8428. {
  8429. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8430. }
  8431. else
  8432. {
  8433. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8434. }
  8435. }
  8436. else
  8437. {
  8438. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8439. {
  8440. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8441. }
  8442. else
  8443. {
  8444. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8445. }
  8446. }
  8447. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8448. //*********************chargingRateUnit***************************/
  8449. loc = strstr(sstrtemp, "chargingRateUnit");
  8450. if(loc != NULL)
  8451. {
  8452. c = 0;
  8453. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8454. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8455. {
  8456. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8457. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8458. c++;
  8459. }
  8460. sstr[c] = '\0';
  8461. strcpy(chargingRateUnitStr,sstr);
  8462. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8463. {
  8464. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8465. }
  8466. else
  8467. {
  8468. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8469. }
  8470. }
  8471. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8472. //****************chargingSchedulePeriod count start*******************/
  8473. int what_len = strlen("startPeriod");
  8474. char tempChargingProfile[1600]={0};
  8475. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8476. char *where = tempChargingProfile;
  8477. if (what_len)
  8478. {
  8479. while ((where = strstr(where, "startPeriod"))) {
  8480. where += what_len;
  8481. chargingSchedulePeriodCount++;
  8482. }
  8483. }
  8484. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8485. {
  8486. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8487. goto end;
  8488. }
  8489. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8490. //where = payload;
  8491. int templength = 0;
  8492. //int searchstart = 0;
  8493. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8494. {
  8495. //****************startPeriod*******************/
  8496. c=0;
  8497. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8498. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8499. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8500. {
  8501. sstr[c] = loc[strlen("startPeriod")+2+c];
  8502. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8503. c++;
  8504. }
  8505. sstr[c] = '\0';
  8506. startPeriodInt[periodNums] = atoi(sstr);
  8507. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8508. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8509. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8510. {
  8511. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8512. }
  8513. else
  8514. {
  8515. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8516. }
  8517. templength = strlen("startPeriod")+2+c;
  8518. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8519. //****************limit*******************/
  8520. c=0;
  8521. loc = strstr(tempChargingProfile + templength, "limit");
  8522. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8523. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8524. {
  8525. sstr[c] = loc[strlen("limit")+2+c];
  8526. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8527. c++;
  8528. }
  8529. sstr[c] = '\0';
  8530. limitflaot[periodNums] = atof(sstr);
  8531. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8532. {
  8533. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8534. }
  8535. else
  8536. {
  8537. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8538. }
  8539. templength = templength + strlen("limit")+2+c;
  8540. //****************numberPhases*******************/
  8541. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8542. if(loc != NULL)
  8543. {
  8544. c=0;
  8545. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8546. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8547. {
  8548. sstr[c] = loc[strlen("numberPhases")+2+c];
  8549. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8550. c++;
  8551. }
  8552. sstr[c] = '\0';
  8553. numberPhasesInt[periodNums] = atoi(sstr);
  8554. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8555. {
  8556. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8557. }
  8558. else
  8559. {
  8560. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8561. }
  8562. templength = templength + strlen("numberPhases")+2+c;
  8563. }
  8564. //where = loc;
  8565. }
  8566. //****************chargingSchedulePeriod count end*******************/
  8567. //*********************minChargingRate***************************/
  8568. loc = strstr(sstrtemp, "minChargingRate");
  8569. if(loc != NULL)
  8570. {
  8571. c = 0;
  8572. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8573. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8574. {
  8575. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8576. c++;
  8577. }
  8578. sstr[c] = '\0';
  8579. minChargingRateFloat = atof(sstr);
  8580. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8581. {
  8582. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8583. }
  8584. else
  8585. {
  8586. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8587. }
  8588. }
  8589. else
  8590. {
  8591. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8592. {
  8593. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8594. }
  8595. else
  8596. {
  8597. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8598. }
  8599. }
  8600. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8601. {
  8602. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8603. if(connectorIdInt != 0)
  8604. {
  8605. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8606. goto end;
  8607. }
  8608. strcpy(filename, ChargePointMaxProfile_JSON );
  8609. fptr1 = fopen(filename, "r");
  8610. if (!fptr1)
  8611. {
  8612. //file not exist
  8613. DEBUG_INFO("Unable to open the input file!!\n");
  8614. fptr1 = fopen(filename, "w+");
  8615. }
  8616. else
  8617. {
  8618. //Check Charging Profile Count
  8619. while(fscanf(fptr1, "%s", word) != EOF)
  8620. {
  8621. //DEBUG_INFO("word=%s\n",word);
  8622. if(strstr(word, "chargingProfileId")!= NULL)
  8623. {
  8624. //DEBUG_INFO("test chargingProfileId \n");
  8625. n_chargingProfile = n_chargingProfile + 1;
  8626. //DEBUG_INFO("chargingProfileId Found\n");
  8627. }
  8628. }
  8629. }
  8630. fclose(fptr1);
  8631. }
  8632. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8633. {
  8634. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8635. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8636. {
  8637. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8638. goto end;
  8639. }
  8640. memset(filename, 0, ARRAY_SIZE(filename));
  8641. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8642. fptr1 = fopen(filename, "r");
  8643. if (!fptr1)
  8644. {
  8645. //file not exist
  8646. //DEBUG_INFO("Unable to open the input file!!\n");
  8647. fptr1 = fopen(filename, "w+");
  8648. }
  8649. else
  8650. {
  8651. //Check Charging Profile Count
  8652. while(fscanf(fptr1, "%s", word) != EOF)
  8653. {
  8654. //DEBUG_INFO("word=%s\n",word);
  8655. if(strstr(word, "chargingProfileId")!= NULL)
  8656. {
  8657. //DEBUG_INFO("test chargingProfileId \n");
  8658. n_chargingProfile = n_chargingProfile + 1;
  8659. //DEBUG_INFO("chargingProfileId Found\n");
  8660. }
  8661. }
  8662. }
  8663. fclose(fptr1);
  8664. }
  8665. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8666. {
  8667. //printf("set chargingProfile 1-4\n");
  8668. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8669. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8670. if(connectorIdInt == 0)
  8671. {
  8672. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8673. goto end;
  8674. }
  8675. int tempIndex = 0;
  8676. //check Transaction active
  8677. if(gunType[connectorIdInt -1] == 'J')
  8678. {
  8679. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8680. {
  8681. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8682. }
  8683. else
  8684. {
  8685. tempIndex = connectorIdInt -1;
  8686. }
  8687. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8688. {
  8689. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8690. {
  8691. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8692. {
  8693. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8694. {
  8695. meet = TRUE;
  8696. break;
  8697. }
  8698. }
  8699. }
  8700. }
  8701. }
  8702. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8703. {
  8704. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8705. {
  8706. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8707. }
  8708. else
  8709. {
  8710. tempIndex = connectorIdInt -1;
  8711. }
  8712. for (int index = 0; index < CCS_QUANTITY; index++)
  8713. {
  8714. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8715. {
  8716. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8717. {
  8718. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8719. {
  8720. meet = TRUE;
  8721. break;
  8722. }
  8723. }
  8724. }
  8725. }
  8726. }
  8727. else if(gunType[connectorIdInt -1] == 'G')
  8728. {
  8729. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8730. {
  8731. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8732. }
  8733. else
  8734. {
  8735. tempIndex = connectorIdInt -1;
  8736. }
  8737. for (int index = 0; index < GB_QUANTITY; index++)
  8738. {
  8739. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8740. {
  8741. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8742. {
  8743. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8744. {
  8745. meet = TRUE;
  8746. break;
  8747. }
  8748. }
  8749. }
  8750. }
  8751. }
  8752. else
  8753. {
  8754. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8755. {
  8756. tempIndex = 2;
  8757. }
  8758. else
  8759. {
  8760. tempIndex = (connectorIdInt -1);
  8761. }
  8762. for (int index = 0; index < AC_QUANTITY; index++)
  8763. {
  8764. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8765. {
  8766. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8767. {
  8768. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8769. {
  8770. meet = TRUE;
  8771. break;
  8772. }
  8773. }
  8774. }
  8775. }
  8776. }
  8777. //check Transaction active
  8778. if(meet == FALSE)
  8779. {
  8780. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8781. goto end;
  8782. }
  8783. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8784. {
  8785. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8786. goto end;
  8787. }
  8788. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8789. fptr1 = fopen(filename, "r");
  8790. if (!fptr1)
  8791. {
  8792. //file not exist
  8793. DEBUG_INFO("Unable to open the input file!!\n");
  8794. fptr1 = fopen(filename, "w+");
  8795. }
  8796. else
  8797. {
  8798. //Check Charging Profile Count
  8799. while(fscanf(fptr1, "%s", word) != EOF)
  8800. {
  8801. //DEBUG_INFO("word=%s\n",word);
  8802. if(strstr(word, "chargingProfileId")!= NULL)
  8803. {
  8804. //DEBUG_INFO("test chargingProfileId \n");
  8805. n_chargingProfile = n_chargingProfile + 1;
  8806. //DEBUG_INFO("chargingProfileId Found\n");
  8807. }
  8808. }
  8809. }
  8810. fclose(fptr1);
  8811. }
  8812. // Check ChargeProfileMaxStackLevel
  8813. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8814. {
  8815. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8816. goto end;
  8817. }
  8818. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8819. {
  8820. int i = 0;
  8821. char fnametemp[200]={0};
  8822. n_chargingProfile = 0;
  8823. //Check ChargePointMaxProfile.json exit
  8824. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8825. {
  8826. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8827. //Check Charging Profile Count
  8828. while(fscanf(fptr1, "%s", word) != EOF)
  8829. {
  8830. //DEBUG_INFO("word=%s\n",word);
  8831. if(strstr(word, "chargingProfileId")!= NULL)
  8832. {
  8833. //DEBUG_INFO("test chargingProfileId \n");
  8834. n_chargingProfile = n_chargingProfile + 1;
  8835. i = i + 1;
  8836. //DEBUG_INFO("chargingProfileId Found\n");
  8837. }
  8838. memset(word, 0, ARRAY_SIZE(word));
  8839. }
  8840. fclose(fptr1);
  8841. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8842. }
  8843. //Check TxDefaultProfile_0.json exit
  8844. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8845. {
  8846. i = 0;
  8847. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8848. //Check Charging Profile Count
  8849. while(fscanf(fptr1, "%s", word) != EOF)
  8850. {
  8851. //DEBUG_INFO("word=%s\n",word);
  8852. if(strstr(word, "chargingProfileId")!= NULL)
  8853. {
  8854. //DEBUG_INFO("test chargingProfileId \n");
  8855. n_chargingProfile = n_chargingProfile + 1;
  8856. i = i + 1;
  8857. //DEBUG_INFO("chargingProfileId Found\n");
  8858. }
  8859. memset(word, 0, ARRAY_SIZE(word));
  8860. }
  8861. fclose(fptr1);
  8862. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8863. }
  8864. //Check TxDefaultProfile_%d.json
  8865. for(int j=1; j <= gunTotalNumber; j++)
  8866. {
  8867. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8868. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8869. if((access(fnametemp,F_OK))!=-1)
  8870. {
  8871. i = 0;
  8872. fptr1 = fopen(fnametemp, "r");
  8873. //Check Charging Profile Count
  8874. while(fscanf(fptr1, "%s", word) != EOF)
  8875. {
  8876. //DEBUG_INFO("word=%s\n",word);
  8877. if(strstr(word, "chargingProfileId")!= NULL)
  8878. {
  8879. //DEBUG_INFO("test chargingProfileId \n");
  8880. n_chargingProfile = n_chargingProfile + 1;
  8881. i = i + 1;
  8882. //DEBUG_INFO("chargingProfileId Found\n");
  8883. }
  8884. memset(word, 0, ARRAY_SIZE(word));
  8885. }
  8886. fclose(fptr1);
  8887. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8888. }
  8889. }
  8890. //Check TxProfile_%d.json
  8891. for(int j=1; j <= gunTotalNumber; j++)
  8892. {
  8893. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8894. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8895. if((access(fnametemp,F_OK))!=-1)
  8896. {
  8897. i = 0;
  8898. fptr1 = fopen(fnametemp, "r");
  8899. //Check Charging Profile Count
  8900. while(fscanf(fptr1, "%s", word) != EOF)
  8901. {
  8902. //DEBUG_INFO("word=%s\n",word);
  8903. if(strstr(word, "chargingProfileId")!= NULL)
  8904. {
  8905. //DEBUG_INFO("test chargingProfileId \n");
  8906. n_chargingProfile = n_chargingProfile + 1;
  8907. i = i + 1;
  8908. //DEBUG_INFO("chargingProfileId Found\n");
  8909. }
  8910. memset(word, 0, ARRAY_SIZE(word));
  8911. }
  8912. fclose(fptr1);
  8913. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8914. }
  8915. }
  8916. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8917. {
  8918. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8919. goto end;
  8920. }
  8921. }
  8922. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8923. //**********************************Write to File********************************************************/
  8924. FILE *infile;
  8925. FILE *outfile;
  8926. // open file for writing
  8927. infile = fopen (filename, "r");
  8928. outfile = fopen (tempfile, "w");
  8929. int d =0;
  8930. d = fgetc(infile);
  8931. //DEBUG_INFO("d:%d\n",d);
  8932. rewind(infile);
  8933. //*璉 瘚 辣蝏     1嚗   0 */
  8934. if(d == EOF)
  8935. {
  8936. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8937. fprintf(outfile,"%s\n",payload);
  8938. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8939. fclose(infile);
  8940. fclose(outfile);
  8941. sprintf(rmFileCmd,"rm -f %s",filename);
  8942. system(rmFileCmd);
  8943. rename(tempfile, filename);
  8944. sleep(1);
  8945. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8946. //system(rmFileCmd);
  8947. }
  8948. else
  8949. {
  8950. char buf[1000]={0};
  8951. int ChargingProfileAdded = FALSE;
  8952. while (fgets(buf, sizeof(buf), infile) != NULL)
  8953. {
  8954. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8955. //*************************tempconnectorIdInt*********************************/
  8956. loc = strstr(buf, "connectorId");
  8957. c = 0;
  8958. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8959. while (loc[strlen("connectorId")+2+c] != ',')
  8960. {
  8961. sstr[c] = loc[strlen("connectorId")+2+c];
  8962. c++;
  8963. }
  8964. sstr[c] = '\0';
  8965. tempconnectorIdInt = atoi(sstr);
  8966. //*************************tempchargingProfileIdInt*********************************/
  8967. loc = strstr(buf, "chargingProfileId");
  8968. c = 0;
  8969. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8970. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8971. {
  8972. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8973. c++;
  8974. }
  8975. sstr[c] = '\0';
  8976. tempchargingProfileIdInt = atoi(sstr);
  8977. //*************************tempstackLevelInt*********************************/
  8978. loc = strstr(buf, "stackLevel");
  8979. c = 0;
  8980. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8981. while (loc[strlen("stackLevel")+2+c] != ',')
  8982. {
  8983. sstr[c] = loc[strlen("stackLevel")+2+c];
  8984. c++;
  8985. }
  8986. sstr[c] = '\0';
  8987. tempstackLevelInt = atoi(sstr);
  8988. //*************************tempchargingProfilePurposeStr*********************************/
  8989. loc = strstr(payload, "chargingProfilePurpose");
  8990. c = 0;
  8991. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8992. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8993. {
  8994. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8995. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8996. c++;
  8997. }
  8998. sstr[c] = '\0';
  8999. strcpy(tempchargingProfilePurposeStr,sstr);
  9000. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9001. {
  9002. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9003. {
  9004. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9005. if(ChargingProfileAdded == FALSE)
  9006. {
  9007. fprintf(outfile,"%s\n",payload);
  9008. ChargingProfileAdded = TRUE;
  9009. }
  9010. }
  9011. else
  9012. {
  9013. if(tempstackLevelInt < stackLevelInt)
  9014. {
  9015. if(ChargingProfileAdded == FALSE)
  9016. {
  9017. fprintf(outfile,"%s\n",payload);
  9018. ChargingProfileAdded = TRUE;
  9019. fprintf(outfile,"%s\n",buf);
  9020. }
  9021. else
  9022. {
  9023. fprintf(outfile,"%s\n",buf);
  9024. }
  9025. }
  9026. else
  9027. {
  9028. if(ChargingProfileAdded == FALSE)
  9029. {
  9030. fprintf(outfile,"%s\n",buf);
  9031. fprintf(outfile,"%s\n",payload);
  9032. ChargingProfileAdded = TRUE;
  9033. }
  9034. else
  9035. {
  9036. fprintf(outfile,"%s\n",buf);
  9037. }
  9038. }
  9039. }
  9040. }
  9041. else
  9042. {
  9043. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9044. {
  9045. if(ChargingProfileAdded == FALSE)
  9046. {
  9047. fprintf(outfile,"%s\n",payload);
  9048. ChargingProfileAdded = TRUE;
  9049. fprintf(outfile,"%s\n",buf);
  9050. }
  9051. else
  9052. {
  9053. fprintf(outfile,"%s\n",buf);
  9054. }
  9055. }
  9056. else if(tempstackLevelInt < stackLevelInt)
  9057. {
  9058. if(ChargingProfileAdded == FALSE)
  9059. {
  9060. fprintf(outfile,"%s\n",payload);
  9061. ChargingProfileAdded = TRUE;
  9062. fprintf(outfile,"%s\n",buf);
  9063. }
  9064. else
  9065. {
  9066. fprintf(outfile,"%s\n",buf);
  9067. }
  9068. }
  9069. else
  9070. {
  9071. if(ChargingProfileAdded == FALSE)
  9072. {
  9073. fprintf(outfile,"%s\n",buf);
  9074. fprintf(outfile,"%s\n",payload);
  9075. ChargingProfileAdded = TRUE;
  9076. }
  9077. else
  9078. {
  9079. fprintf(outfile,"%s\n",buf);
  9080. }
  9081. }
  9082. }
  9083. } // end of while loop
  9084. fclose(infile);
  9085. fclose(outfile);
  9086. sprintf(rmFileCmd,"rm -f %s",filename);
  9087. system(rmFileCmd);
  9088. rename(tempfile, filename);
  9089. sleep(1);
  9090. result = TRUE;
  9091. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9092. }
  9093. end:
  9094. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9095. return result;
  9096. return result;
  9097. }
  9098. int handleTriggerMessageRequest(char *uuid, char *payload)
  9099. {
  9100. mtrace();
  9101. int result = FAIL;
  9102. int connectorIdIsNULL = FALSE;
  9103. int connectorIdInt =0;
  9104. char sstr[40]={0},sstrtemp[100]={ 0 };
  9105. char requestedMessagestr[40]={0};
  9106. char comfirmstr[20]={0};
  9107. int c = 0;
  9108. char *loc;
  9109. DEBUG_INFO("handleTriggerMessageRequest\n");
  9110. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9111. strcpy(sstrtemp, stringtrimspace(payload));
  9112. c = 0;
  9113. loc = strstr(sstrtemp, "requestedMessage");
  9114. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9115. {
  9116. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9117. c++;
  9118. }
  9119. sstr[c] = '\0';
  9120. strcpy(requestedMessagestr, sstr);
  9121. c = 0;
  9122. loc = strstr(sstrtemp, "connectorId");
  9123. if(loc == NULL)
  9124. {
  9125. connectorIdIsNULL = TRUE;
  9126. }
  9127. else
  9128. {
  9129. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9130. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9131. {
  9132. sstr[c] = loc[strlen("connectorId")+2+c];
  9133. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9134. c++;
  9135. }
  9136. sstr[c] = '\0';
  9137. connectorIdInt = atoi(sstr);
  9138. }
  9139. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  9140. {
  9141. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9142. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9143. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9144. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9145. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9146. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9147. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9148. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9149. {
  9150. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9151. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9152. return TRUE;
  9153. }
  9154. else
  9155. {
  9156. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9157. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9158. }
  9159. }
  9160. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9161. {
  9162. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9163. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9164. return TRUE;
  9165. }
  9166. //==========================
  9167. // Trigger message
  9168. //==========================
  9169. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9170. {
  9171. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9172. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9173. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9174. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9175. {
  9176. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9177. }
  9178. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9179. }
  9180. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9181. {
  9182. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9183. }
  9184. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9185. {
  9186. //sendBootNotificationRequest();
  9187. server_sign = FALSE;
  9188. }
  9189. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9190. {
  9191. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9192. }
  9193. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9194. {
  9195. if(connectorIdIsNULL == FALSE)
  9196. {
  9197. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9198. {
  9199. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9200. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  9201. }
  9202. }
  9203. else
  9204. {
  9205. for(int idx=0;idx< gunTotalNumber;idx++)
  9206. {
  9207. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9208. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  9209. }
  9210. }
  9211. }
  9212. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9213. {
  9214. if(connectorIdIsNULL == FALSE)
  9215. {
  9216. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9217. {
  9218. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9219. }
  9220. }
  9221. else
  9222. {
  9223. for(int idx=0;idx< gunTotalNumber;idx++)
  9224. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9225. }
  9226. }
  9227. return result;
  9228. }
  9229. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9230. {
  9231. mtrace();
  9232. int result = FAIL;
  9233. int connectorIdInt =0;
  9234. char comfirmstr[20]={0};
  9235. int tempIndex = 0;
  9236. json_object *UnlockConnector;
  9237. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9238. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9239. UnlockConnector = json_tokener_parse(payload);
  9240. if(!is_error(UnlockConnector))
  9241. {
  9242. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  9243. {
  9244. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  9245. }
  9246. }
  9247. json_object_put(UnlockConnector);
  9248. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  9249. if(gunTotalNumber == 0)
  9250. {
  9251. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9252. goto end;
  9253. }
  9254. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9255. {
  9256. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9257. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9258. goto end;
  9259. }
  9260. else
  9261. {
  9262. //check Transaction active
  9263. if(gunType[connectorIdInt-1] == 'J')
  9264. {
  9265. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9266. {
  9267. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9268. }
  9269. else
  9270. {
  9271. tempIndex = connectorIdInt -1;
  9272. }
  9273. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9274. {
  9275. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9276. {
  9277. //stop Transaction
  9278. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9279. }
  9280. }
  9281. }
  9282. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9283. {
  9284. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9285. {
  9286. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9287. }
  9288. else
  9289. {
  9290. tempIndex = connectorIdInt -1;
  9291. }
  9292. for (int index = 0; index < CCS_QUANTITY; index++)
  9293. {
  9294. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9295. {
  9296. //stop Transaction
  9297. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9298. }
  9299. }
  9300. }
  9301. else if(gunType[connectorIdInt-1] == 'G')
  9302. {
  9303. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9304. {
  9305. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9306. }
  9307. else
  9308. {
  9309. tempIndex = connectorIdInt -1;
  9310. }
  9311. for (int index = 0; index < GB_QUANTITY; index++)
  9312. {
  9313. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9314. {
  9315. //stop Transaction
  9316. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9317. }
  9318. }
  9319. }
  9320. else
  9321. {
  9322. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9323. {
  9324. tempIndex = 2;
  9325. }
  9326. else
  9327. {
  9328. tempIndex = connectorIdInt-1;
  9329. }
  9330. for (int index = 0; index < AC_QUANTITY; index++)
  9331. {
  9332. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9333. {
  9334. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9335. }
  9336. }
  9337. }
  9338. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9339. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9340. result = TRUE;
  9341. return result;
  9342. }
  9343. end:
  9344. //json_object_put(obj); --- remove temporally
  9345. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9346. return result;
  9347. }
  9348. static char UpdateFirmwarepayloadData[300]={0};
  9349. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9350. {
  9351. mtrace();
  9352. int result = FAIL;
  9353. pthread_t t;
  9354. sendUpdateFirmwareConfirmation(uuid);
  9355. memset(UpdateFirmwarepayloadData, 0, 300);
  9356. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9357. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9358. ////pthread_join(t, NULL); //
  9359. //pthread_detach(t);
  9360. //sendUpdateFirmwareConfirmation(uuid);
  9361. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9362. return result;
  9363. }
  9364. void *UpdateFirmwareProcess(void *data)
  9365. {
  9366. pthread_detach(pthread_self());
  9367. mtrace();
  9368. int retriesInt =0, retryIntervalInt=0;
  9369. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9370. int port=0;
  9371. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9372. int isSuccess = 0;
  9373. char ftpbuf[200];
  9374. char temp[100];
  9375. char * pch;
  9376. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9377. json_object *UpdateFirmware;
  9378. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  9379. if(!is_error(UpdateFirmware))
  9380. {
  9381. // Required data
  9382. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  9383. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  9384. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  9385. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  9386. // Optional data
  9387. if(json_object_object_get(UpdateFirmware, "retries"))
  9388. {
  9389. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  9390. }
  9391. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  9392. {
  9393. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  9394. }
  9395. }
  9396. json_object_put(UpdateFirmware);
  9397. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9398. memset(path, 0, ARRAY_SIZE(path));
  9399. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9400. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9401. if(strncmp(locationstr,"http", 4) == 0)
  9402. {
  9403. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9404. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9405. // protocol, user, password, host, path);
  9406. sprintf(ftppath,"/%s", path);
  9407. DEBUG_INFO("locationstr: %s\n", locationstr);
  9408. DEBUG_INFO("protocol: %s\n",protocol);
  9409. DEBUG_INFO("host: %s\n",host);
  9410. DEBUG_INFO("path: %s\n",path);
  9411. DEBUG_INFO("ftppath: %s\n",ftppath);
  9412. int ftppathlen=strlen(ftppath);
  9413. int i=1;
  9414. char filenametemp[50];
  9415. while(i < ftppathlen)
  9416. {
  9417. int len=ftppathlen-i;
  9418. if(ftppath[len]== 47) // '/' ascll code: 47
  9419. {
  9420. DEBUG_INFO("compare '/' all right\n");
  9421. break;
  9422. }
  9423. i=i+1;
  9424. }
  9425. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9426. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9427. filenametemp[i+1] = 0;
  9428. do
  9429. {
  9430. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9431. sleep(retryIntervalInt);
  9432. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9433. if(!isSuccess)
  9434. {
  9435. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9436. }
  9437. else
  9438. {
  9439. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9440. }
  9441. }
  9442. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9443. {
  9444. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9445. memset(temp, 0, ARRAY_SIZE(temp));
  9446. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9447. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9448. int ftppathlen=strlen(ftpbuf);
  9449. int i=1;
  9450. char filenametemp[50];
  9451. while(i < ftppathlen)
  9452. {
  9453. int len=ftppathlen-i;
  9454. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9455. {
  9456. DEBUG_INFO(" compare '/' all right\n");
  9457. break;
  9458. }
  9459. i=i+1;
  9460. }
  9461. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9462. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9463. filenametemp[i+1] = 0;
  9464. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9465. pch=strchr(temp,'@');
  9466. if(pch==NULL)
  9467. {
  9468. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9469. protocol, host, &port, path);
  9470. strcpy(user,"anonymous");
  9471. strcpy(password,"");
  9472. }
  9473. else
  9474. {
  9475. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9476. protocol, user, password, host, &port, path);
  9477. }
  9478. sscanf(host,"%[^/]%s",host1, path1);
  9479. sprintf(ftppath,"%s", path1);
  9480. //DEBUG_INFO("protocol =%s\n",protocol);
  9481. //DEBUG_INFO("user =%s\n",user);
  9482. //DEBUG_INFO("password =%s\n",password);
  9483. //DEBUG_INFO("host1 =%s\n",host1);
  9484. //DEBUG_INFO("port =%d\n",port);
  9485. //DEBUG_INFO("path1 =%s\n",path1);
  9486. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9487. //ftpFile(host, user, password, port, ftppath, fname);
  9488. //download firmware pthred
  9489. if(port == 0)
  9490. {
  9491. port = 21;
  9492. }
  9493. do
  9494. {
  9495. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9496. sleep(retryIntervalInt);
  9497. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9498. if(!isSuccess)
  9499. {
  9500. //BulldogUtil.sleepMs(interval*1000);
  9501. DEBUG_INFO("Update firmware request and download file fail.\n");
  9502. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9503. }
  9504. else
  9505. {
  9506. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9507. }
  9508. }
  9509. else
  9510. {
  9511. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9512. }
  9513. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9514. pthread_exit(NULL);
  9515. }
  9516. //==========================================
  9517. // Handle server response routine
  9518. //==========================================
  9519. void handleAuthorizeResponse(char *payload, int gun_index)
  9520. {
  9521. mtrace();
  9522. char expiryDatestr[30]={0};
  9523. char parentIdTagstr[20]={0};
  9524. char statusstr[20]={0};
  9525. char expiryDatestrtemp[30]={0};
  9526. char parentIdTagstrtemp[20]={0};
  9527. char IdTagstrtemp[20]={0};
  9528. char statusstrtemp[20]={0};
  9529. int expiryDateISNULL=FALSE;
  9530. int parentIdTagISNULL=FALSE;
  9531. char sstr[160]={0};
  9532. char* filename = AuthorizationCache_JSON;
  9533. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9534. char *loc;
  9535. int resultRename=0;
  9536. int responseIdTagInfoAsZero= 0;
  9537. char rmFileCmd[50]={0};
  9538. DEBUG_INFO("handleAuthorizeResponse...\n");
  9539. json_object *Authorize;
  9540. Authorize = json_tokener_parse(payload);
  9541. if(!is_error(Authorize))
  9542. {
  9543. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9544. {
  9545. // Required data
  9546. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9547. // Optional data
  9548. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9549. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9550. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9551. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9552. }
  9553. }
  9554. json_object_put(Authorize);
  9555. if(expiryDateISNULL == FALSE)
  9556. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9557. if(parentIdTagISNULL == FALSE)
  9558. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9559. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9560. //Update idTag information to authorization cache if supproted
  9561. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9562. {
  9563. if((access(filename,F_OK))!=-1)
  9564. {
  9565. printf("AuthorizationCache exist.\n");
  9566. }
  9567. else
  9568. {
  9569. printf("AuthorizationCache not exist\n");
  9570. FILE *log = fopen(filename, "w+");
  9571. if(log == NULL)
  9572. {
  9573. printf("log is NULL\n");
  9574. goto out;
  9575. }
  9576. else
  9577. {
  9578. fclose(log);
  9579. }
  9580. }
  9581. FILE *infile;
  9582. FILE *outfile;
  9583. // open file for writing
  9584. infile = fopen (filename, "r");
  9585. outfile = fopen (tempfile, "w");
  9586. int c;
  9587. c = fgetc(infile);
  9588. //DEBUG_INFO("c:%d\n",c);
  9589. rewind(infile);
  9590. if(c == EOF)
  9591. {
  9592. DEBUG_INFO("Orignal File is NULL\n");
  9593. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9594. {
  9595. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9596. }
  9597. else
  9598. {
  9599. strcpy(expiryDatestrtemp, "");
  9600. }
  9601. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9602. {
  9603. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9604. }
  9605. else
  9606. {
  9607. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9608. }
  9609. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9610. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9611. fclose(infile);
  9612. fclose(outfile);
  9613. sprintf(rmFileCmd,"rm -f %s",filename);
  9614. system(rmFileCmd);
  9615. resultRename = rename(tempfile, filename);
  9616. if(resultRename == 0)
  9617. {
  9618. printf("File renamed successfully");
  9619. }
  9620. else
  9621. {
  9622. printf("Error: unable to rename the file");
  9623. }
  9624. }
  9625. else
  9626. {
  9627. char buf[160]={0};
  9628. while (fgets(buf, ARRAY_SIZE(buf), infile) != NULL)
  9629. {
  9630. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9631. memset(expiryDatestr, 0, ARRAY_SIZE(expiryDatestrtemp));
  9632. memset(parentIdTagstr,0, ARRAY_SIZE(parentIdTagstrtemp));
  9633. memset(statusstr, 0, ARRAY_SIZE(statusstrtemp));
  9634. memset(IdTagstrtemp, 0, ARRAY_SIZE(IdTagstrtemp));
  9635. memset(expiryDatestrtemp, 0, ARRAY_SIZE(expiryDatestrtemp));
  9636. memset(parentIdTagstrtemp, 0, ARRAY_SIZE(parentIdTagstrtemp));
  9637. memset(statusstrtemp, 0, ARRAY_SIZE(statusstrtemp));
  9638. //------------------IdTag-----------------------
  9639. loc = strstr(buf, "idTag");
  9640. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9641. c = 0;
  9642. while (loc[3+strlen("idTag")+c] != '\"')
  9643. {
  9644. sstr[c] = loc[3+strlen("idTag")+c];
  9645. c++;
  9646. }
  9647. sstr[c] = '\0';
  9648. strcpy(IdTagstrtemp,sstr);
  9649. //*********************expiryDate***************/
  9650. loc = strstr(buf, "expiryDate");
  9651. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9652. c = 0;
  9653. while (loc[3+strlen("expiryDate")+c] != '\"')
  9654. {
  9655. sstr[c] = loc[3+strlen("expiryDate")+c];
  9656. c++;
  9657. }
  9658. sstr[c] = '\0';
  9659. strcpy(expiryDatestr,sstr);
  9660. //*********************parentIdTag***************/
  9661. loc = strstr(buf, "parentIdTag");
  9662. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9663. c = 0;
  9664. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9665. {
  9666. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9667. c++;
  9668. }
  9669. sstr[c] = '\0';
  9670. strcpy(parentIdTagstr,sstr);
  9671. //*********************status***************/
  9672. loc = strstr(buf, "status");
  9673. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9674. c = 0;
  9675. while (loc[3+strlen("status")+c] != '\"')
  9676. {
  9677. sstr[c] = loc[3+strlen("status")+c];
  9678. c++;
  9679. }
  9680. sstr[c] = '\0';
  9681. strcpy(statusstr,sstr);
  9682. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9683. {
  9684. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9685. responseIdTagInfoAsZero = 1;
  9686. }
  9687. else
  9688. {
  9689. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9690. }
  9691. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9692. {
  9693. //modify item
  9694. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9695. {
  9696. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9697. }
  9698. else
  9699. {
  9700. strcpy(expiryDatestrtemp, "");
  9701. }
  9702. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9703. {
  9704. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9705. }
  9706. else
  9707. {
  9708. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9709. }
  9710. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9711. }
  9712. else
  9713. {
  9714. //wrie original item
  9715. strcpy(expiryDatestrtemp, expiryDatestr);
  9716. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9717. strcpy(statusstrtemp, statusstr);
  9718. }
  9719. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9720. }
  9721. fclose(infile);
  9722. fclose(outfile);
  9723. sprintf(rmFileCmd,"rm -f %s",filename);
  9724. system(rmFileCmd);
  9725. resultRename = rename(tempfile, filename);
  9726. if(resultRename == 0)
  9727. {
  9728. DEBUG_INFO("File renamed successfully");
  9729. }
  9730. else
  9731. {
  9732. DEBUG_INFO("Error: unable to rename the file");
  9733. }
  9734. }
  9735. }
  9736. out:
  9737. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9738. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9739. authorizeRetryTimes = 0;
  9740. }
  9741. char * strtrimc( char * s )
  9742. {
  9743. char * p1 = s;
  9744. char * p2 = s;
  9745. while(*p1 != '\0')
  9746. {
  9747. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9748. {
  9749. if(*p1 != ',')
  9750. {
  9751. p1 ++;
  9752. }
  9753. else
  9754. {
  9755. break;
  9756. }
  9757. }
  9758. if(*p1 != ',')
  9759. {
  9760. * p2 ++ = *p1 ++;
  9761. //printf("p2=%s\n",p2);
  9762. }
  9763. else
  9764. {
  9765. break;
  9766. }
  9767. }
  9768. *p2 = '\0';
  9769. return (s);
  9770. }
  9771. void handleBootNotificationResponse(char *payload, int gun_index)
  9772. {
  9773. mtrace();
  9774. char statusStr[12]={0};
  9775. char currentTimeStr[30]={0};
  9776. int intervalInt = 0;
  9777. struct tm tp;
  9778. char buf[28]={0};
  9779. char timebuf[50]={0};
  9780. DEBUG_INFO("handleBootNotificationResponse...\n");
  9781. json_object *BootNotification;
  9782. BootNotification = json_tokener_parse(payload);
  9783. if(!is_error(BootNotification))
  9784. {
  9785. // Required data
  9786. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9787. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9788. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9789. }
  9790. json_object_put(BootNotification);
  9791. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9792. BootNotificationInterval = intervalInt;
  9793. HeartBeatWaitTime = intervalInt;
  9794. //write back to ShmOCPP16Data->BootNotification
  9795. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9796. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9797. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9798. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9799. {
  9800. server_sign = TRUE;
  9801. server_pending =FALSE;
  9802. }
  9803. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9804. {
  9805. server_pending = TRUE;
  9806. }
  9807. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9808. tp.tm_isdst = -1;
  9809. //time_t utc = mktime(&tp);
  9810. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9811. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9812. sprintf(timebuf,"date -s '%s'",buf);
  9813. system(timebuf);
  9814. srand(time(NULL));
  9815. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9816. //==============================================
  9817. // RTC sync
  9818. //==============================================
  9819. system("/sbin/hwclock -w --systohc");
  9820. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9821. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9822. }
  9823. void handleDataTransferResponse(char *payload, int gun_index)
  9824. {
  9825. char sstr[160]={0};//sstr[200]={ 0 };
  9826. int c = 0;
  9827. char *loc;
  9828. DEBUG_INFO("handleDataTransferResponse ...\n");
  9829. loc = strstr(payload, "status");
  9830. printf("loc=%s\n",loc);
  9831. c = 0;
  9832. while (loc[3+strlen("status")+c] != '\"')
  9833. {
  9834. sstr[c] = loc[3+strlen("status")+c];
  9835. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9836. c++;
  9837. }
  9838. sstr[c] = '\0';
  9839. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9840. }
  9841. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9842. {
  9843. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9844. //struct json_object *obj;
  9845. // obj = json_tokener_parse(payload);
  9846. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9847. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9848. //No fields are defined.
  9849. }
  9850. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9851. {
  9852. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9853. //struct json_object *obj;
  9854. // obj = json_tokener_parse(payload);
  9855. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9856. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9857. //No fields are defined.
  9858. }
  9859. void handleHeartbeatResponse(char *payload, int gun_index)
  9860. {
  9861. mtrace();
  9862. struct tm tp;
  9863. char buf[28]={0};
  9864. char timebuf[50]={0};
  9865. DEBUG_INFO("handleHeartbeatResponse...\n");
  9866. json_object *Heartbeat;
  9867. Heartbeat = json_tokener_parse(payload);
  9868. if(!is_error(Heartbeat))
  9869. {
  9870. // Required data
  9871. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9872. }
  9873. json_object_put(BootNotification);
  9874. if(FirstHeartBeat == 0)
  9875. {
  9876. FirstHeartBeat = 1;
  9877. DEBUG_INFO("FirstHeartBeat \n");
  9878. }
  9879. HeartBeatWithNOResponse = 0;
  9880. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9881. tp.tm_isdst = -1;
  9882. //time_t utc = mktime(&tp);
  9883. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9884. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9885. sprintf(timebuf,"date -s '%s'",buf);
  9886. system(timebuf);
  9887. //==============================================
  9888. // RTC sync
  9889. //==============================================
  9890. system("/sbin/hwclock -w --systohc");
  9891. //===============================================
  9892. //Print Out HeartBeat log
  9893. //===============================================
  9894. {
  9895. double diff_t;
  9896. struct tm tp,tp1;
  9897. // BootNotification Receive Time
  9898. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9899. tp.tm_isdst = -1;
  9900. time_t BootNotificationReceiveTime = mktime(&tp);
  9901. //HeartBeat Receive Time
  9902. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  9903. tp1.tm_isdst = -1;
  9904. time_t HeartBeatReceiveTime = mktime(&tp1);
  9905. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  9906. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  9907. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  9908. {
  9909. HeartBeatCountPerHour = (int)diff_t / 3600;
  9910. DEBUG_INFO("handleHeartbeatResponse ...\n");
  9911. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  9912. }
  9913. }
  9914. }
  9915. void handleMeterValuesResponse(char *payload, int gun_index)
  9916. {
  9917. mtrace();
  9918. DEBUG_INFO("handleMeterValuesResponse...\n");
  9919. }
  9920. void handleStartTransactionResponse(char *payload, int gun_index)
  9921. {
  9922. mtrace();
  9923. //int transactionIdInt = 0;
  9924. FILE *outfile;
  9925. char data[100]={0};
  9926. DEBUG_INFO("handleStartTransactionResponse...\n");
  9927. json_object *StartTransaction;
  9928. StartTransaction = json_tokener_parse(payload);
  9929. if(!is_error(StartTransaction))
  9930. {
  9931. // Required data
  9932. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  9933. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  9934. // Optional data
  9935. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  9936. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  9937. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9938. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  9939. }
  9940. json_object_put(StartTransaction);
  9941. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9942. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9943. //-----------Start : write to the Queue TransactionId file -----------------//
  9944. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9945. {}
  9946. else
  9947. {
  9948. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9949. if(log == NULL)
  9950. {
  9951. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9952. return ;
  9953. }
  9954. else
  9955. {
  9956. fclose(log);
  9957. }
  9958. }
  9959. // open file for writing
  9960. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  9961. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  9962. {
  9963. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9964. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9965. fputs(data, outfile);
  9966. fclose (outfile);
  9967. }
  9968. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9969. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9970. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9971. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9972. }
  9973. void handleStatusNotificationResponse(char *payload, int gun_index)
  9974. {
  9975. mtrace();
  9976. DEBUG_INFO("handleStatusNotificationResponse...\n");
  9977. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9978. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9979. }
  9980. void handleStopTransactionnResponse(char *payload, int gun_index)
  9981. {
  9982. mtrace();
  9983. DEBUG_INFO("handleStopTransactionnResponse...\n");
  9984. json_object *StopTransaction;
  9985. StopTransaction = json_tokener_parse(payload);
  9986. if(!is_error(StopTransaction))
  9987. {
  9988. // Optional data
  9989. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  9990. {
  9991. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  9992. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  9993. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  9994. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9995. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  9996. }
  9997. }
  9998. json_object_put(StopTransaction);
  9999. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10000. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10001. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10002. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10003. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10004. }
  10005. //==========================================
  10006. // Handle Error routine
  10007. //==========================================
  10008. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10009. {
  10010. mtrace();
  10011. #ifdef SystemLogMessage
  10012. DEBUG_INFO("errorCode: %s\n", errorCode);
  10013. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10014. DEBUG_INFO("errorDetails: %s\n", payload);
  10015. #endif
  10016. }
  10017. //===============================================
  10018. // Common routine
  10019. //===============================================
  10020. int initialConfigurationTable(void)
  10021. {
  10022. //clock_t start_t, end_t, total_t;
  10023. FILE *fp;
  10024. FILE *outfile;
  10025. char str[200]={0};
  10026. char sstr[100]={0};
  10027. int c = 0;
  10028. char *loc;
  10029. DEBUG_INFO("initialConfigurationTable...\n");
  10030. //start_t = clock();
  10031. //printf("Starting of the program, start_t = %ld\n", start_t);
  10032. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10033. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10034. {
  10035. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10036. if(outfile == NULL)
  10037. {
  10038. DEBUG_INFO("Error opening file\n");
  10039. return FALSE;
  10040. }
  10041. /*Core Profile*/
  10042. //AllowOfflineTxForUnknownId
  10043. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10046. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10047. //AuthorizationCacheEnabled
  10048. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10051. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10052. //AuthorizeRemoteTxRequests
  10053. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10056. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10057. //BlinkRepeat
  10058. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10061. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10062. //ClockAlignedDataInterval
  10063. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10066. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10067. //ConnectionTimeOut
  10068. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10071. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10072. //GetConfigurationMaxKeys
  10073. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "44" );
  10076. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10077. // HeartbeatInterval
  10078. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10081. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10082. // LightIntensity
  10083. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10086. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10087. // LocalAuthorizeOffline
  10088. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10091. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10092. // LocalPreAuthorize
  10093. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10097. // MaxEnergyOnInvalidId
  10098. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10101. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10102. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10103. // MeterValuesAlignedData
  10104. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10106. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10108. else
  10109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10110. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10111. // MeterValuesAlignedDataMaxLength
  10112. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10114. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10116. else
  10117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10119. // MeterValuesSampledData
  10120. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10122. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10124. else
  10125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10126. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10127. // MeterValuesSampledDataMaxLength
  10128. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10130. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10132. else
  10133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10134. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10135. // MeterValueSampleInterval
  10136. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10139. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10140. // MinimumStatusDuration
  10141. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10144. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10145. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10146. // NumberOfConnectors
  10147. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10149. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10150. {
  10151. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10152. }
  10153. else
  10154. {
  10155. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10156. }
  10157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10158. // ResetRetries
  10159. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10162. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10163. // ConnectorPhaseRotation
  10164. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10167. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10168. // ConnectorPhaseRotationMaxLength
  10169. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10172. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10173. // StopTransactionOnEVSideDisconnect
  10174. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10178. // StopTransactionOnInvalidId
  10179. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10182. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10183. // StopTxnAlignedData
  10184. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10188. // StopTxnAlignedDataMaxLength
  10189. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10193. // StopTxnSampledData
  10194. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10196. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10197. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10198. else
  10199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10200. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10201. // StopTxnSampledDataMaxLength
  10202. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10204. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10205. {
  10206. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10207. }
  10208. else
  10209. {
  10210. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10211. }
  10212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10213. // SupportedFeatureProfiles
  10214. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10217. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10218. // SupportedFeatureProfilesMaxLength
  10219. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10221. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10223. // TransactionMessageAttempts
  10224. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10227. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10228. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10229. // TransactionMessageRetryInterval
  10230. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10233. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10234. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10235. // UnlockConnectorOnEVSideDisconnect
  10236. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10239. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10240. // WebSocketPingInterval
  10241. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10245. // QueueOffLineStartTransactionMessage
  10246. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10249. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10250. //* Local Auth List Management Profile*/
  10251. #if 0
  10252. //For OCTT Test Case
  10253. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10256. #endif
  10257. #if 1
  10258. //LocalAuthListEnabled
  10259. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10263. #endif
  10264. //LocalAuthListMaxLength
  10265. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10268. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10269. //SendLocalListMaxLength
  10270. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10271. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10273. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10274. //ReserveConnectorZeroSupported
  10275. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10278. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10279. //* Smart Charging Profile */
  10280. //ChargeProfileMaxStackLevel
  10281. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10284. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10285. // ChargingScheduleAllowedChargingRateUnit
  10286. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10289. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10290. // ChargingScheduleMaxPeriods
  10291. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10294. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10295. // ConnectorSwitch3to1PhaseSupported
  10296. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10299. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10300. // MaxChargingProfilesInstalled
  10301. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10304. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10305. fclose(outfile);
  10306. }
  10307. else
  10308. {
  10309. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10310. char keystr[60]={0};
  10311. char readonlystr[10]={0};
  10312. char valuestr[100]={0};
  10313. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10314. if(fp == NULL) {
  10315. DEBUG_INFO("Error opening file");
  10316. return FALSE;
  10317. }
  10318. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10319. {
  10320. //DEBUG_INFO("Get Configuration \n");
  10321. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10322. //*************************key*********************************/
  10323. loc = strstr(str, "key");
  10324. c = 0;
  10325. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10326. while (loc[strlen("key")+3+c] != '\"')
  10327. {
  10328. sstr[c] = loc[strlen("key")+3+c];
  10329. c++;
  10330. }
  10331. sstr[c] = '\0';
  10332. strcpy(keystr,sstr);
  10333. //*************************readonly*********************************/
  10334. loc = strstr(str, "readonly");
  10335. c = 0;
  10336. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10337. while (loc[strlen("readonly")+2+c] != ',')
  10338. {
  10339. sstr[c] = loc[strlen("readonly")+2+c];
  10340. c++;
  10341. }
  10342. sstr[c] = '\0';
  10343. strcpy(readonlystr,sstr);
  10344. //*************************value*********************************/
  10345. loc = strstr(str, "value");
  10346. c = 0;
  10347. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10348. while (loc[strlen("value")+3+c] != '\"')
  10349. {
  10350. sstr[c] = loc[strlen("value")+3+c];
  10351. c++;
  10352. }
  10353. sstr[c] = '\0';
  10354. strcpy(valuestr,sstr);
  10355. // DEBUG_INFO("keystr=%s\n",keystr);
  10356. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10357. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10358. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10359. {
  10360. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10361. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10362. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10363. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10364. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10365. }
  10366. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10367. {
  10368. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10369. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10370. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10371. }
  10372. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10373. {
  10374. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10375. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10376. }
  10377. if(strcmp(keystr, "BlinkRepeat") == 0)
  10378. {
  10379. //Charger.BlinkRepeat = Integer.parseInt(value);
  10380. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10381. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10382. }
  10383. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10384. {
  10385. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10387. }
  10388. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10389. {
  10390. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10391. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10392. }
  10393. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10394. {
  10395. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10396. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10397. }
  10398. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10399. {
  10400. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10401. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10402. HeartBeatWaitTime = atoi(valuestr);
  10403. }
  10404. if(strcmp(keystr, "LightIntensity") == 0)
  10405. {
  10406. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10407. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10408. }
  10409. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10410. {
  10411. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10412. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10413. }
  10414. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10415. {
  10416. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10417. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10418. }
  10419. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10420. {
  10421. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10422. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10423. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10424. }
  10425. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10426. {
  10427. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10428. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10429. }
  10430. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10431. {
  10432. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10433. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10434. }
  10435. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10436. {
  10437. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10438. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10439. }
  10440. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10441. {
  10442. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10443. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10444. }
  10445. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10446. {
  10447. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10448. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10449. }
  10450. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10451. {
  10452. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10453. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10454. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10455. }
  10456. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10457. {
  10458. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10459. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10460. }
  10461. if(strcmp(keystr, "ResetRetries") == 0)
  10462. {
  10463. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10464. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10465. }
  10466. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10467. {
  10468. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10470. }
  10471. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10472. {
  10473. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10474. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10475. }
  10476. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10477. {
  10478. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10479. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10480. }
  10481. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10482. {
  10483. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10484. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10485. }
  10486. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10487. {
  10488. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10490. }
  10491. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10492. {
  10493. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10494. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10495. }
  10496. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10497. {
  10498. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10499. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10500. }
  10501. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10502. {
  10503. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10504. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10505. }
  10506. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10507. {
  10508. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10509. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10510. }
  10511. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10512. {
  10513. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10514. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10515. }
  10516. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10517. {
  10518. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10519. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10520. TransactionMessageAttemptsValue = atoi(valuestr);
  10521. }
  10522. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10523. {
  10524. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10525. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10526. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10527. }
  10528. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10529. {
  10530. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10531. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10532. }
  10533. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10534. {
  10535. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10537. }
  10538. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10539. {
  10540. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10541. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10542. }
  10543. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10544. {
  10545. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10546. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10547. }
  10548. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10549. {
  10550. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10551. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10552. }
  10553. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10554. {
  10555. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10556. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10557. }
  10558. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10559. {
  10560. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10561. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10562. }
  10563. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10564. {
  10565. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10566. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10567. }
  10568. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10569. {
  10570. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10571. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10572. }
  10573. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10574. {
  10575. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10576. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10577. }
  10578. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10579. {
  10580. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10581. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10582. }
  10583. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10584. {
  10585. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10586. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10587. }
  10588. }
  10589. fclose(fp);
  10590. }
  10591. return 0;
  10592. }
  10593. void StoreConfigurationTable(void)
  10594. {
  10595. FILE *outfile;
  10596. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10597. if(outfile == NULL)
  10598. {
  10599. DEBUG_INFO("Error opening file");
  10600. return ;
  10601. }
  10602. /*Core Profile*/
  10603. //AllowOfflineTxForUnknownId
  10604. /*
  10605. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10606. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10609. */
  10610. //DEBUG_INFO("data=%s\n",data);
  10611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10612. //AuthorizationCacheEnabled
  10613. /*
  10614. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10617. */
  10618. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10619. //AuthorizeRemoteTxRequests
  10620. /*
  10621. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10624. */
  10625. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10626. //BlinkRepeat
  10627. /*
  10628. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10629. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10631. */
  10632. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10633. //ClockAlignedDataInterval
  10634. /*
  10635. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10638. */
  10639. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10640. //ConnectionTimeOut
  10641. /*
  10642. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10645. */
  10646. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10647. //GetConfigurationMaxKeys
  10648. /*
  10649. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10652. */
  10653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10654. // HeartbeatInterval
  10655. /*
  10656. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10659. */
  10660. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10661. // LightIntensity
  10662. /*
  10663. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10664. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10666. */
  10667. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10668. // LocalAuthorizeOffline
  10669. /*
  10670. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10673. */
  10674. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10675. // LocalPreAuthorize
  10676. /*
  10677. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10680. */
  10681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10682. // MaxEnergyOnInvalidId
  10683. /*
  10684. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10687. */
  10688. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10689. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10690. // MeterValuesAlignedData
  10691. /*
  10692. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10693. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10695. */
  10696. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10697. // MeterValuesAlignedDataMaxLength
  10698. /*
  10699. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10702. */
  10703. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10704. // MeterValuesSampledData
  10705. /*
  10706. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10709. */
  10710. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10711. // MeterValuesSampledDataMaxLength
  10712. /*
  10713. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10715. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10716. */
  10717. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10718. // MeterValueSampleInterval
  10719. /*
  10720. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10721. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10722. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10723. */
  10724. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10725. // MinimumStatusDuration
  10726. /*
  10727. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10728. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10730. */
  10731. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10732. // NumberOfConnectors
  10733. /*
  10734. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10736. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10737. {
  10738. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10739. }
  10740. else
  10741. {
  10742. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10743. }
  10744. */
  10745. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10746. // ResetRetries
  10747. /*
  10748. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10751. */
  10752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10753. // ConnectorPhaseRotation
  10754. /*
  10755. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10758. */
  10759. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10760. // ConnectorPhaseRotationMaxLength
  10761. /*
  10762. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10765. */
  10766. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10767. // StopTransactionOnEVSideDisconnect
  10768. /*
  10769. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10772. */
  10773. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10774. // StopTransactionOnInvalidId
  10775. /*
  10776. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10779. */
  10780. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10781. // StopTxnAlignedData
  10782. /*
  10783. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10786. */
  10787. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10788. // StopTxnAlignedDataMaxLength
  10789. /*
  10790. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10793. */
  10794. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10795. // StopTxnSampledData
  10796. /*
  10797. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10800. */
  10801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10802. // StopTxnSampledDataMaxLength
  10803. /*
  10804. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10807. */
  10808. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10809. // SupportedFeatureProfiles
  10810. /*
  10811. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10814. */
  10815. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10816. // SupportedFeatureProfilesMaxLength
  10817. /*
  10818. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10821. */
  10822. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10823. // TransactionMessageAttempts
  10824. /*
  10825. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10826. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10828. */
  10829. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10830. // TransactionMessageRetryInterval
  10831. /*
  10832. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10835. */
  10836. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10837. // UnlockConnectorOnEVSideDisconnect
  10838. /*
  10839. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10842. */
  10843. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10844. // WebSocketPingInterval
  10845. /*
  10846. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10849. */
  10850. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10851. // QueueOffLineStartTransactionMessage
  10852. /*
  10853. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  10854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10856. */
  10857. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10858. //* Local Auth List Management Profile*/
  10859. //LocalAuthListEnabled
  10860. /*
  10861. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10864. */
  10865. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10866. //LocalAuthListMaxLength
  10867. /*
  10868. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10871. */
  10872. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10873. //SendLocalListMaxLength
  10874. /*
  10875. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10878. */
  10879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10880. //ReserveConnectorZeroSupported
  10881. /*
  10882. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10884. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10885. */
  10886. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10887. //* Smart Charging Profile */
  10888. //ChargeProfileMaxStackLevel
  10889. /*
  10890. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10893. */
  10894. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10895. // ChargingScheduleAllowedChargingRateUnit
  10896. /*
  10897. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10900. */
  10901. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10902. // ChargingScheduleMaxPeriods
  10903. /*
  10904. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10907. */
  10908. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10909. // ConnectorSwitch3to1PhaseSupported
  10910. /*
  10911. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10912. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10914. */
  10915. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10916. // MaxChargingProfilesInstalled
  10917. /*
  10918. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10919. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10921. */
  10922. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10923. fclose(outfile);
  10924. }
  10925. void getKeyValue(char *keyReq)
  10926. {
  10927. int isEmpty = FALSE;
  10928. int isKnowKey = FALSE;
  10929. DEBUG_INFO("keyReq = %s\n", keyReq);
  10930. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10931. isEmpty = TRUE;
  10932. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10933. {
  10934. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10936. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10937. {
  10938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10939. }
  10940. else
  10941. {
  10942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10943. }
  10944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10945. isKnowKey = TRUE;
  10946. }
  10947. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10948. {
  10949. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10951. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10952. {
  10953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10954. }
  10955. else
  10956. {
  10957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10958. }
  10959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10960. isKnowKey = TRUE;
  10961. }
  10962. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10963. {
  10964. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10966. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10967. {
  10968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10969. }
  10970. else
  10971. {
  10972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10973. }
  10974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10975. isKnowKey = TRUE;
  10976. }
  10977. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10978. {
  10979. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10981. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10982. {
  10983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10984. }
  10985. else
  10986. {
  10987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10988. }
  10989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10990. isKnowKey = TRUE;
  10991. }
  10992. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10993. {
  10994. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10996. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10997. {
  10998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  10999. }
  11000. else
  11001. {
  11002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11003. }
  11004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11005. isKnowKey = TRUE;
  11006. }
  11007. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11008. {
  11009. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11011. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11012. {
  11013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11014. }
  11015. else
  11016. {
  11017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11018. }
  11019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11020. isKnowKey = TRUE;
  11021. }
  11022. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11023. {
  11024. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11026. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11027. {
  11028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11029. }
  11030. else
  11031. {
  11032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11033. }
  11034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11035. isKnowKey = TRUE;
  11036. }
  11037. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11038. {
  11039. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11041. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11042. {
  11043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11044. }
  11045. else
  11046. {
  11047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11048. }
  11049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11050. isKnowKey = TRUE;
  11051. }
  11052. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11053. {
  11054. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11056. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11057. {
  11058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11059. }
  11060. else
  11061. {
  11062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11063. }
  11064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11065. isKnowKey = TRUE;
  11066. }
  11067. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11068. {
  11069. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11071. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11072. {
  11073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11074. }
  11075. else
  11076. {
  11077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11078. }
  11079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11080. isKnowKey = TRUE;
  11081. }
  11082. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11083. {
  11084. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11086. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11087. {
  11088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11089. }
  11090. else
  11091. {
  11092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11093. }
  11094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11095. isKnowKey = TRUE;
  11096. }
  11097. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11098. {
  11099. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11101. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11102. {
  11103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11104. }
  11105. else
  11106. {
  11107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11108. }
  11109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11110. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11111. isKnowKey = TRUE;
  11112. }
  11113. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11114. {
  11115. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11117. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11118. {
  11119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11120. }
  11121. else
  11122. {
  11123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11124. }
  11125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11126. isKnowKey = TRUE;
  11127. }
  11128. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11129. {
  11130. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11132. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11133. {
  11134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11135. }
  11136. else
  11137. {
  11138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11139. }
  11140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11141. isKnowKey = TRUE;
  11142. }
  11143. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11144. {
  11145. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11147. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11148. {
  11149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11150. }
  11151. else
  11152. {
  11153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11154. }
  11155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11156. isKnowKey = TRUE;
  11157. }
  11158. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11159. {
  11160. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11162. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11163. {
  11164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11165. }
  11166. else
  11167. {
  11168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11169. }
  11170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11171. isKnowKey = TRUE;
  11172. }
  11173. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11174. {
  11175. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11177. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11178. {
  11179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11180. }
  11181. else
  11182. {
  11183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11184. }
  11185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11186. isKnowKey = TRUE;
  11187. }
  11188. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11189. {
  11190. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11192. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11193. {
  11194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11195. }
  11196. else
  11197. {
  11198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11199. }
  11200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11201. isKnowKey = TRUE;
  11202. }
  11203. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11204. {
  11205. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11207. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11208. {
  11209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11210. }
  11211. else
  11212. {
  11213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11214. }
  11215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11216. isKnowKey = TRUE;
  11217. }
  11218. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11219. {
  11220. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11222. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11223. {
  11224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11225. }
  11226. else
  11227. {
  11228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11229. }
  11230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11231. isKnowKey = TRUE;
  11232. }
  11233. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11234. {
  11235. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11237. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11238. {
  11239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11240. }
  11241. else
  11242. {
  11243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11244. }
  11245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11246. isKnowKey = TRUE;
  11247. }
  11248. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11249. {
  11250. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11252. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11253. {
  11254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11255. }
  11256. else
  11257. {
  11258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11259. }
  11260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11261. isKnowKey = TRUE;
  11262. }
  11263. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11264. {
  11265. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11267. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11268. {
  11269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11270. }
  11271. else
  11272. {
  11273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11274. }
  11275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11276. isKnowKey = TRUE;
  11277. }
  11278. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11279. {
  11280. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11282. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11283. {
  11284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11285. }
  11286. else
  11287. {
  11288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11289. }
  11290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11291. isKnowKey = TRUE;
  11292. }
  11293. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11294. {
  11295. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11297. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11298. {
  11299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11300. }
  11301. else
  11302. {
  11303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11304. }
  11305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11306. isKnowKey = TRUE;
  11307. }
  11308. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11309. {
  11310. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11312. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11313. {
  11314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11315. }
  11316. else
  11317. {
  11318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11319. }
  11320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11321. isKnowKey = TRUE;
  11322. }
  11323. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11324. {
  11325. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11327. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11328. {
  11329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11330. }
  11331. else
  11332. {
  11333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11334. }
  11335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11336. isKnowKey = TRUE;
  11337. }
  11338. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11339. {
  11340. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11342. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11343. {
  11344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11345. }
  11346. else
  11347. {
  11348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11349. }
  11350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11351. isKnowKey = TRUE;
  11352. }
  11353. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11354. {
  11355. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11357. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11358. {
  11359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11360. }
  11361. else
  11362. {
  11363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11364. }
  11365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11366. isKnowKey = TRUE;
  11367. }
  11368. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11369. {
  11370. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11372. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11373. {
  11374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11375. }
  11376. else
  11377. {
  11378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11379. }
  11380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11381. isKnowKey = TRUE;
  11382. }
  11383. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11384. {
  11385. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11387. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11388. {
  11389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11390. }
  11391. else
  11392. {
  11393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11394. }
  11395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11396. isKnowKey = TRUE;
  11397. }
  11398. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11399. {
  11400. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11401. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11402. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11403. {
  11404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11405. }
  11406. else
  11407. {
  11408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11409. }
  11410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11411. isKnowKey = TRUE;
  11412. }
  11413. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11414. {
  11415. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11417. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11418. {
  11419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11420. }
  11421. else
  11422. {
  11423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11424. }
  11425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11426. isKnowKey = TRUE;
  11427. }
  11428. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11429. {
  11430. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11432. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11433. {
  11434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11435. }
  11436. else
  11437. {
  11438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11439. }
  11440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11441. isKnowKey = TRUE;
  11442. }
  11443. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11444. {
  11445. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11447. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11448. {
  11449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11450. }
  11451. else
  11452. {
  11453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11454. }
  11455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11456. isKnowKey = TRUE;
  11457. }
  11458. #if 1
  11459. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11460. {
  11461. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11463. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11464. {
  11465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11466. }
  11467. else
  11468. {
  11469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11470. }
  11471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11472. isKnowKey = TRUE;
  11473. }
  11474. #endif
  11475. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11476. {
  11477. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11479. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11480. {
  11481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11482. }
  11483. else
  11484. {
  11485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11486. }
  11487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11488. isKnowKey = TRUE;
  11489. }
  11490. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11491. {
  11492. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11494. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11495. {
  11496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11497. }
  11498. else
  11499. {
  11500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11501. }
  11502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11503. isKnowKey = TRUE;
  11504. }
  11505. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11506. {
  11507. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11509. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11510. {
  11511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11512. }
  11513. else
  11514. {
  11515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11516. }
  11517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11518. isKnowKey = TRUE;
  11519. }
  11520. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11521. {
  11522. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11524. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11525. {
  11526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11527. }
  11528. else
  11529. {
  11530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11531. }
  11532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11533. isKnowKey = TRUE;
  11534. }
  11535. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11536. {
  11537. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11539. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11540. {
  11541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11542. }
  11543. else
  11544. {
  11545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11546. }
  11547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11548. isKnowKey = TRUE;
  11549. }
  11550. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11551. {
  11552. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11554. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11555. {
  11556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11557. }
  11558. else
  11559. {
  11560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11561. }
  11562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11563. isKnowKey = TRUE;
  11564. }
  11565. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11566. {
  11567. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11569. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11570. {
  11571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11572. }
  11573. else
  11574. {
  11575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11576. }
  11577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11578. isKnowKey = TRUE;
  11579. }
  11580. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11581. {
  11582. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11584. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11585. {
  11586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11587. }
  11588. else
  11589. {
  11590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11591. }
  11592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11593. isKnowKey = TRUE;
  11594. }
  11595. //=========================================================
  11596. if(!isEmpty && !isKnowKey)
  11597. {
  11598. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11599. strcpy(unknownkey[UnknownKeynum], keyReq);
  11600. UnknownKeynum = UnknownKeynum + 1;
  11601. }
  11602. }
  11603. void processUnkownKey(void)
  11604. {
  11605. DEBUG_INFO("processUnkownKey...\n");
  11606. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11607. for(int index=0; index < UnknownKeynum; index++)
  11608. {
  11609. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11610. {
  11611. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11612. }
  11613. }
  11614. }
  11615. int setKeyValue(char *key, char *value)
  11616. {
  11617. int isSuccess = NotSupported;
  11618. int check_ascii=0;
  11619. char str[10]={0};
  11620. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11621. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11622. {
  11623. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11624. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11625. {
  11626. strcpy(str, (const char*)value);
  11627. for(int i = 0; str[i]; i++){
  11628. str[i] = tolower(str[i]);
  11629. }
  11630. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11631. isSuccess = ConfigurationStatus_Accepted;
  11632. }
  11633. else
  11634. {
  11635. isSuccess = ConfigurationStatus_Rejected;
  11636. }
  11637. }
  11638. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11639. {
  11640. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11641. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11642. {
  11643. strcpy(str, (const char*)value);
  11644. for(int i = 0; str[i]; i++){
  11645. str[i] = tolower(str[i]);
  11646. }
  11647. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11648. isSuccess = ConfigurationStatus_Accepted;
  11649. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11650. }
  11651. else
  11652. {
  11653. isSuccess = ConfigurationStatus_Rejected;
  11654. }
  11655. }
  11656. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11657. {
  11658. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11659. {
  11660. strcpy(str, (const char*)value);
  11661. for(int i = 0; str[i]; i++)
  11662. {
  11663. str[i] = tolower(str[i]);
  11664. }
  11665. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11666. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11667. isSuccess = ConfigurationStatus_Accepted;
  11668. }
  11669. else
  11670. {
  11671. isSuccess = ConfigurationStatus_Rejected;
  11672. }
  11673. }
  11674. if(strcmp(key, "BlinkRepeat") == 0)
  11675. {
  11676. //Charger.BlinkRepeat = Integer.parseInt(value);
  11677. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11678. {
  11679. check_ascii = value[0];
  11680. if( (check_ascii < 48) || (check_ascii > 57) )
  11681. {
  11682. isSuccess = ConfigurationStatus_Rejected;
  11683. }
  11684. else
  11685. {
  11686. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11687. isSuccess = ConfigurationStatus_Accepted;
  11688. }
  11689. }
  11690. else
  11691. {
  11692. isSuccess = ConfigurationStatus_Rejected;
  11693. }
  11694. }
  11695. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11696. {
  11697. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11698. {
  11699. check_ascii = value[0];
  11700. if( (check_ascii < 48) || (check_ascii > 57) )
  11701. {
  11702. isSuccess = ConfigurationStatus_Rejected;
  11703. }
  11704. else
  11705. {
  11706. if((atoi(value) == 0) || (atoi(value) >= 10))
  11707. {
  11708. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11709. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11710. isSuccess = ConfigurationStatus_Accepted;
  11711. }
  11712. else
  11713. isSuccess = ConfigurationStatus_Rejected;
  11714. }
  11715. }
  11716. else
  11717. {
  11718. isSuccess = ConfigurationStatus_Rejected;
  11719. }
  11720. }
  11721. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11722. {
  11723. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11724. {
  11725. check_ascii = value[0];
  11726. if( (check_ascii < 48) || (check_ascii > 57) )
  11727. {
  11728. isSuccess = ConfigurationStatus_Rejected;
  11729. }
  11730. else
  11731. {
  11732. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11733. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11734. isSuccess = ConfigurationStatus_Accepted;
  11735. }
  11736. }
  11737. else
  11738. {
  11739. isSuccess = ConfigurationStatus_Rejected;
  11740. }
  11741. }
  11742. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11743. {
  11744. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11745. {
  11746. check_ascii = value[0];
  11747. if( (check_ascii < 48) || (check_ascii > 57) )
  11748. {
  11749. isSuccess = ConfigurationStatus_Rejected;
  11750. }
  11751. else
  11752. {
  11753. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11754. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11755. isSuccess = ConfigurationStatus_Accepted;
  11756. }
  11757. }
  11758. else
  11759. {
  11760. isSuccess = ConfigurationStatus_Rejected;
  11761. }
  11762. }
  11763. if(strcmp(key, "HeartbeatInterval") == 0)
  11764. {
  11765. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11766. {
  11767. check_ascii = value[0];
  11768. if( (check_ascii < 48) || (check_ascii > 57) )
  11769. {
  11770. isSuccess = ConfigurationStatus_Rejected;
  11771. }
  11772. else
  11773. {
  11774. if((atoi(value) == 0) || (atoi(value) >= 10))
  11775. {
  11776. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11777. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11778. HeartBeatWaitTime = atoi(value);
  11779. isSuccess = ConfigurationStatus_Accepted;
  11780. }
  11781. else
  11782. {
  11783. isSuccess = ConfigurationStatus_Rejected;
  11784. }
  11785. }
  11786. }
  11787. else
  11788. {
  11789. isSuccess = ConfigurationStatus_Rejected;
  11790. }
  11791. }
  11792. if(strcmp(key, "LightIntensity") == 0)
  11793. {
  11794. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11795. {
  11796. check_ascii = value[0];
  11797. if( (check_ascii < 48) || (check_ascii > 57) )
  11798. {
  11799. isSuccess = ConfigurationStatus_Rejected;
  11800. }
  11801. else
  11802. {
  11803. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11804. isSuccess = ConfigurationStatus_Accepted;
  11805. }
  11806. }
  11807. else
  11808. {
  11809. isSuccess = ConfigurationStatus_Rejected;
  11810. }
  11811. }
  11812. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11813. {
  11814. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11815. {
  11816. strcpy(str, (const char*)value);
  11817. for(int i = 0; str[i]; i++)
  11818. {
  11819. str[i] = tolower(str[i]);
  11820. }
  11821. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11822. isSuccess = ConfigurationStatus_Accepted;
  11823. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11824. }
  11825. else
  11826. {
  11827. isSuccess = ConfigurationStatus_Rejected;
  11828. }
  11829. }
  11830. if(strcmp(key, "LocalPreAuthorize") == 0)
  11831. {
  11832. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11833. {
  11834. strcpy(str, (const char*)value);
  11835. for(int i = 0; str[i]; i++)
  11836. {
  11837. str[i] = tolower(str[i]);
  11838. }
  11839. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11840. isSuccess = ConfigurationStatus_Accepted;
  11841. }
  11842. else
  11843. {
  11844. isSuccess = ConfigurationStatus_Rejected;
  11845. }
  11846. }
  11847. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11848. {
  11849. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11850. {
  11851. check_ascii = value[0];
  11852. if( (check_ascii < 48) || (check_ascii > 57) )
  11853. {
  11854. isSuccess = ConfigurationStatus_Rejected;
  11855. }
  11856. else
  11857. {
  11858. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11859. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11860. isSuccess = ConfigurationStatus_Accepted;
  11861. }
  11862. }
  11863. else
  11864. {
  11865. isSuccess = ConfigurationStatus_Rejected;
  11866. }
  11867. }
  11868. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11869. {
  11870. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11871. {
  11872. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11873. isSuccess = ConfigurationStatus_Accepted;
  11874. }
  11875. else
  11876. {
  11877. isSuccess = ConfigurationStatus_Rejected;
  11878. }
  11879. }
  11880. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11881. {
  11882. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11883. {
  11884. check_ascii = value[0];
  11885. if( (check_ascii < 48) || (check_ascii > 57) )
  11886. {
  11887. isSuccess = ConfigurationStatus_Rejected;
  11888. }
  11889. else
  11890. {
  11891. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11892. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11893. isSuccess = ConfigurationStatus_Accepted;
  11894. }
  11895. }
  11896. else
  11897. {
  11898. isSuccess = ConfigurationStatus_Rejected;
  11899. }
  11900. }
  11901. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11902. {
  11903. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11904. {
  11905. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11906. isSuccess = ConfigurationStatus_Accepted;
  11907. }
  11908. else
  11909. {
  11910. isSuccess = ConfigurationStatus_Rejected;
  11911. }
  11912. }
  11913. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11914. {
  11915. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11916. {
  11917. check_ascii = value[0];
  11918. if( (check_ascii < 48) || (check_ascii > 57) )
  11919. {
  11920. isSuccess = ConfigurationStatus_Rejected;
  11921. }
  11922. else
  11923. {
  11924. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11925. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11926. isSuccess = ConfigurationStatus_Accepted;
  11927. }
  11928. }
  11929. else
  11930. {
  11931. isSuccess = ConfigurationStatus_Rejected;
  11932. }
  11933. }
  11934. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11935. {
  11936. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11937. {
  11938. check_ascii = value[0];
  11939. if( (check_ascii < 48) || (check_ascii > 57) )
  11940. {
  11941. isSuccess = ConfigurationStatus_Rejected;
  11942. }
  11943. else
  11944. {
  11945. if((atoi(value) == 0) || (atoi(value) >= 10))
  11946. {
  11947. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11948. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11949. isSuccess = ConfigurationStatus_Accepted;
  11950. }
  11951. else
  11952. {
  11953. isSuccess = ConfigurationStatus_Rejected;
  11954. }
  11955. }
  11956. }
  11957. else
  11958. {
  11959. isSuccess = ConfigurationStatus_Rejected;
  11960. }
  11961. }
  11962. if(strcmp(key, "MinimumStatusDuration") == 0)
  11963. {
  11964. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11965. {
  11966. check_ascii = value[0];
  11967. if( (check_ascii < 48) || (check_ascii > 57) )
  11968. {
  11969. isSuccess = ConfigurationStatus_Rejected;
  11970. }
  11971. else
  11972. {
  11973. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  11974. {
  11975. isSuccess = ConfigurationStatus_Rejected;
  11976. }
  11977. else
  11978. {
  11979. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  11980. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  11981. server_cycle_Status = atoi(value); //StatusNotification Cycle
  11982. isSuccess = ConfigurationStatus_Accepted;
  11983. }
  11984. }
  11985. }
  11986. else
  11987. {
  11988. isSuccess = ConfigurationStatus_Rejected;
  11989. }
  11990. }
  11991. if(strcmp(key, "NumberOfConnectors") == 0)
  11992. {
  11993. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11994. {
  11995. check_ascii = value[0];
  11996. if( (check_ascii < 48) || (check_ascii > 57) )
  11997. {
  11998. isSuccess = ConfigurationStatus_Rejected;
  11999. }
  12000. else
  12001. {
  12002. //Charger.ResetRetries = Integer.parseInt(value);
  12003. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12004. isSuccess = ConfigurationStatus_Accepted;
  12005. }
  12006. }
  12007. else
  12008. {
  12009. isSuccess = ConfigurationStatus_Rejected;
  12010. }
  12011. }
  12012. if(strcmp(key, "ResetRetries") == 0)
  12013. {
  12014. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12015. {
  12016. check_ascii = value[0];
  12017. if( (check_ascii < 48) || (check_ascii > 57) )
  12018. {
  12019. isSuccess = ConfigurationStatus_Rejected;
  12020. }
  12021. else
  12022. {
  12023. //Charger.ResetRetries = Integer.parseInt(value);
  12024. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12025. isSuccess = ConfigurationStatus_Accepted;
  12026. }
  12027. }
  12028. else
  12029. {
  12030. isSuccess = ConfigurationStatus_Rejected;
  12031. }
  12032. }
  12033. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12034. {
  12035. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12036. {
  12037. strcpy(str, (const char*)value);
  12038. for(int i = 0; str[i]; i++)
  12039. {
  12040. str[i] = tolower(str[i]);
  12041. }
  12042. if(strcmp(str, "notapplicable")== 0)
  12043. {
  12044. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12045. isSuccess = ConfigurationStatus_Accepted;
  12046. }
  12047. else if(strcmp(str, "unknown")== 0)
  12048. {
  12049. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12050. isSuccess = ConfigurationStatus_Accepted;
  12051. }
  12052. else if(strcmp(str, "rst")== 0)
  12053. {
  12054. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12055. isSuccess = ConfigurationStatus_Accepted;
  12056. }
  12057. else if(strcmp(str, "rts")== 0)
  12058. {
  12059. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12060. isSuccess = ConfigurationStatus_Accepted;
  12061. }
  12062. else if(strcmp(str, "srt")== 0)
  12063. {
  12064. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12065. isSuccess = ConfigurationStatus_Accepted;
  12066. }
  12067. else if(strcmp(str, "str")== 0)
  12068. {
  12069. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12070. isSuccess = ConfigurationStatus_Accepted;
  12071. }
  12072. else if(strcmp(str, "trs")== 0)
  12073. {
  12074. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12075. isSuccess = ConfigurationStatus_Accepted;
  12076. }
  12077. else if(strcmp(str, "tsr")== 0)
  12078. {
  12079. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12080. isSuccess = ConfigurationStatus_Accepted;
  12081. }
  12082. else
  12083. {
  12084. isSuccess = ConfigurationStatus_Rejected;
  12085. }
  12086. }
  12087. else
  12088. {
  12089. isSuccess = ConfigurationStatus_Rejected;
  12090. }
  12091. }
  12092. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12093. {
  12094. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12095. {
  12096. check_ascii = value[0];
  12097. if( (check_ascii < 48) || (check_ascii > 57) )
  12098. {
  12099. isSuccess = ConfigurationStatus_Rejected;
  12100. }
  12101. else
  12102. {
  12103. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12104. isSuccess = ConfigurationStatus_Accepted;
  12105. }
  12106. }
  12107. else
  12108. {
  12109. isSuccess = ConfigurationStatus_Rejected;
  12110. }
  12111. }
  12112. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12113. {
  12114. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12115. {
  12116. strcpy(str, (const char*)value);
  12117. for(int i = 0; str[i]; i++)
  12118. {
  12119. str[i] = tolower(str[i]);
  12120. }
  12121. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12122. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12123. isSuccess = ConfigurationStatus_Accepted;
  12124. }
  12125. else
  12126. {
  12127. isSuccess = ConfigurationStatus_Rejected;
  12128. }
  12129. }
  12130. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12131. {
  12132. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12133. {
  12134. strcpy(str, (const char*)value);
  12135. for(int i = 0; str[i]; i++)
  12136. {
  12137. str[i] = tolower(str[i]);
  12138. }
  12139. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12141. isSuccess = ConfigurationStatus_Accepted;
  12142. }
  12143. else
  12144. {
  12145. isSuccess = ConfigurationStatus_Rejected;
  12146. }
  12147. }
  12148. if(strcmp(key, "StopTxnAlignedData") == 0)
  12149. {
  12150. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12151. {
  12152. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12153. isSuccess = ConfigurationStatus_Accepted;
  12154. }
  12155. else
  12156. {
  12157. isSuccess = ConfigurationStatus_Rejected;
  12158. }
  12159. }
  12160. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12161. {
  12162. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12163. {
  12164. check_ascii = value[0];
  12165. if( (check_ascii < 48) || (check_ascii > 57) )
  12166. {
  12167. isSuccess = ConfigurationStatus_Rejected;
  12168. }
  12169. else
  12170. {
  12171. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12172. isSuccess = ConfigurationStatus_Accepted;
  12173. }
  12174. }
  12175. else
  12176. {
  12177. isSuccess = ConfigurationStatus_Rejected;
  12178. }
  12179. }
  12180. if(strcmp(key, "StopTxnSampledData") == 0)
  12181. {
  12182. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12183. {
  12184. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12185. isSuccess = ConfigurationStatus_Accepted;
  12186. }
  12187. else
  12188. {
  12189. isSuccess = ConfigurationStatus_Rejected;
  12190. }
  12191. }
  12192. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12193. {
  12194. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12195. {
  12196. check_ascii = value[0];
  12197. if( (check_ascii < 48) || (check_ascii > 57) )
  12198. {
  12199. isSuccess = ConfigurationStatus_Rejected;
  12200. }
  12201. else
  12202. {
  12203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12204. isSuccess = ConfigurationStatus_Accepted;
  12205. }
  12206. }
  12207. else
  12208. {
  12209. isSuccess = ConfigurationStatus_Rejected;
  12210. }
  12211. }
  12212. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12213. {
  12214. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12215. {
  12216. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12217. isSuccess = ConfigurationStatus_Accepted;
  12218. }
  12219. else
  12220. {
  12221. isSuccess = ConfigurationStatus_Rejected;
  12222. }
  12223. }
  12224. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12225. {
  12226. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12227. {
  12228. check_ascii = value[0];
  12229. if( (check_ascii < 48) || (check_ascii > 57) )
  12230. {
  12231. isSuccess = ConfigurationStatus_Rejected;
  12232. }
  12233. else
  12234. {
  12235. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12236. isSuccess = ConfigurationStatus_Accepted;
  12237. }
  12238. }
  12239. else
  12240. {
  12241. isSuccess = ConfigurationStatus_Rejected;
  12242. }
  12243. }
  12244. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12245. {
  12246. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12247. {
  12248. check_ascii = value[0];
  12249. if( (check_ascii < 48) || (check_ascii > 57) )
  12250. {
  12251. isSuccess = ConfigurationStatus_Rejected;
  12252. }
  12253. else
  12254. {
  12255. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12257. TransactionMessageAttemptsValue = atoi(value);
  12258. isSuccess = ConfigurationStatus_Accepted;
  12259. }
  12260. }
  12261. else
  12262. {
  12263. isSuccess = ConfigurationStatus_Rejected;
  12264. }
  12265. }
  12266. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12267. {
  12268. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12269. {
  12270. check_ascii = value[0];
  12271. if( (check_ascii < 48) || (check_ascii > 57) )
  12272. {
  12273. isSuccess = ConfigurationStatus_Rejected;
  12274. }
  12275. else
  12276. {
  12277. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12278. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12279. TransactionMessageRetryIntervalValue = atoi(value);
  12280. isSuccess = ConfigurationStatus_Accepted;
  12281. }
  12282. }
  12283. else
  12284. {
  12285. isSuccess = ConfigurationStatus_Rejected;
  12286. }
  12287. }
  12288. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12289. {
  12290. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12291. {
  12292. strcpy(str, (const char*)value);
  12293. for(int i = 0; str[i]; i++)
  12294. {
  12295. str[i] = tolower(str[i]);
  12296. }
  12297. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12298. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12299. isSuccess = ConfigurationStatus_Accepted;
  12300. }
  12301. else
  12302. {
  12303. isSuccess = ConfigurationStatus_Rejected;
  12304. }
  12305. }
  12306. if(strcmp(key, "WebSocketPingInterval") == 0)
  12307. {
  12308. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12309. {
  12310. check_ascii = value[0];
  12311. if( (check_ascii < 48) || (check_ascii > 57) )
  12312. {
  12313. isSuccess = ConfigurationStatus_Rejected;
  12314. }
  12315. else
  12316. {
  12317. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12318. isSuccess = ConfigurationStatus_Accepted;
  12319. }
  12320. }
  12321. else
  12322. {
  12323. isSuccess = ConfigurationStatus_Rejected;
  12324. }
  12325. }
  12326. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12327. {
  12328. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12329. {
  12330. strcpy(str, (const char*)value);
  12331. for(int i = 0; str[i]; i++)
  12332. {
  12333. str[i] = tolower(str[i]);
  12334. }
  12335. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12336. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12337. isSuccess = ConfigurationStatus_Accepted;
  12338. }
  12339. else
  12340. {
  12341. isSuccess = ConfigurationStatus_Rejected;
  12342. }
  12343. }
  12344. #if 0
  12345. //For OCPP Test Case
  12346. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12347. {
  12348. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12349. {
  12350. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12351. isSuccess = ConfigurationStatus_Accepted;
  12352. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12353. }
  12354. else
  12355. {
  12356. isSuccess = ConfigurationStatus_Rejected;
  12357. }
  12358. }
  12359. #endif
  12360. #if 1
  12361. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12362. {
  12363. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12364. {
  12365. strcpy(str, (const char*)value);
  12366. for(int i = 0; str[i]; i++)
  12367. {
  12368. str[i] = tolower(str[i]);
  12369. }
  12370. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12371. isSuccess = ConfigurationStatus_Accepted;
  12372. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12373. }
  12374. else
  12375. {
  12376. isSuccess = ConfigurationStatus_Rejected;
  12377. }
  12378. }
  12379. #endif
  12380. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12381. {
  12382. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12383. {
  12384. check_ascii = value[0];
  12385. if( (check_ascii < 48) || (check_ascii > 57) )
  12386. {
  12387. isSuccess = ConfigurationStatus_Rejected;
  12388. }
  12389. else
  12390. {
  12391. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12392. isSuccess = ConfigurationStatus_Accepted;
  12393. }
  12394. }
  12395. else
  12396. {
  12397. isSuccess = ConfigurationStatus_Rejected;
  12398. }
  12399. }
  12400. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12401. {
  12402. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12403. {
  12404. check_ascii = value[0];
  12405. if( (check_ascii < 48) || (check_ascii > 57) )
  12406. {
  12407. isSuccess = ConfigurationStatus_Rejected;
  12408. }
  12409. else
  12410. {
  12411. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12412. isSuccess = ConfigurationStatus_Accepted;
  12413. }
  12414. }
  12415. else
  12416. {
  12417. isSuccess = ConfigurationStatus_Rejected;
  12418. }
  12419. }
  12420. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12421. {
  12422. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12423. {
  12424. strcpy(str, (const char*)value);
  12425. for(int i = 0; str[i]; i++)
  12426. {
  12427. str[i] = tolower(str[i]);
  12428. }
  12429. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12430. isSuccess = ConfigurationStatus_Accepted;
  12431. }
  12432. else
  12433. {
  12434. isSuccess = ConfigurationStatus_Rejected;
  12435. }
  12436. }
  12437. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12438. {
  12439. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12440. {
  12441. check_ascii = value[0];
  12442. if( (check_ascii < 48) || (check_ascii > 57) )
  12443. {
  12444. isSuccess = ConfigurationStatus_Rejected;
  12445. }
  12446. else
  12447. {
  12448. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12449. isSuccess = ConfigurationStatus_Accepted;
  12450. }
  12451. }
  12452. else
  12453. {
  12454. isSuccess = ConfigurationStatus_Rejected;
  12455. }
  12456. }
  12457. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12458. {
  12459. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12460. {
  12461. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12462. isSuccess = ConfigurationStatus_Accepted;
  12463. }
  12464. else
  12465. {
  12466. isSuccess = ConfigurationStatus_Rejected;
  12467. }
  12468. }
  12469. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12470. {
  12471. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12472. {
  12473. check_ascii = value[0];
  12474. if( (check_ascii < 48) || (check_ascii > 57) )
  12475. {
  12476. isSuccess = ConfigurationStatus_Rejected;
  12477. }
  12478. else
  12479. {
  12480. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12481. isSuccess = ConfigurationStatus_Accepted;
  12482. }
  12483. }
  12484. else
  12485. {
  12486. isSuccess = ConfigurationStatus_Rejected;
  12487. }
  12488. }
  12489. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12490. {
  12491. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12492. {
  12493. strcpy(str, (const char*)value);
  12494. for(int i = 0; str[i]; i++)
  12495. {
  12496. str[i] = tolower(str[i]);
  12497. }
  12498. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12499. isSuccess = ConfigurationStatus_Accepted;
  12500. }
  12501. else
  12502. {
  12503. isSuccess = ConfigurationStatus_Rejected;
  12504. }
  12505. }
  12506. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12507. {
  12508. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12509. {
  12510. check_ascii = value[0];
  12511. if( (check_ascii < 48) || (check_ascii > 57) )
  12512. {
  12513. isSuccess = ConfigurationStatus_Rejected;
  12514. }
  12515. else
  12516. {
  12517. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12518. isSuccess = ConfigurationStatus_Accepted;
  12519. }
  12520. }
  12521. else
  12522. {
  12523. isSuccess = ConfigurationStatus_Rejected;
  12524. }
  12525. }
  12526. return isSuccess;
  12527. }
  12528. int TransactionMessageAttemptsGet(void)
  12529. {
  12530. return TransactionMessageAttemptsValue;
  12531. }
  12532. int FirstHeartBeatResponse(void)
  12533. {
  12534. return FirstHeartBeat;
  12535. }
  12536. int TransactionMessageRetryIntervalGet(void)
  12537. {
  12538. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12539. }
  12540. int ReadHttpStatus(int sock)
  12541. {
  12542. //char c;
  12543. char buff[1024]="",*ptr=buff+1;
  12544. int bytes_received, status;
  12545. DEBUG_INFO("Begin Response ..\n");
  12546. while((bytes_received = recv(sock, ptr, 1, 0))){
  12547. if(bytes_received==-1){
  12548. perror("ReadHttpStatus");
  12549. exit(1);
  12550. }
  12551. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12552. ptr++;
  12553. }
  12554. *ptr=0;
  12555. ptr=buff+1;
  12556. sscanf(ptr,"%*s %d ", &status);
  12557. DEBUG_INFO("%s\n",ptr);
  12558. DEBUG_INFO("status=%d\n",status);
  12559. DEBUG_INFO("End Response ..\n");
  12560. return (bytes_received>0)?status:0;
  12561. }
  12562. //the only filed that it parsed is 'Content-Length'
  12563. int ParseHeader(int sock)
  12564. {
  12565. //char c;
  12566. char buff[1024]="",*ptr=buff+4;
  12567. int bytes_received;
  12568. DEBUG_INFO("Begin HEADER ..\n");
  12569. while((bytes_received = recv(sock, ptr, 1, 0))){
  12570. if(bytes_received==-1){
  12571. perror("Parse Header");
  12572. exit(1);
  12573. }
  12574. if(
  12575. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12576. (ptr[-1]=='\r') && (*ptr=='\n' )
  12577. ) break;
  12578. ptr++;
  12579. }
  12580. *ptr=0;
  12581. ptr=buff+4;
  12582. //printf("%s",ptr);
  12583. if(bytes_received){
  12584. ptr=strstr(ptr,"Content-Length:");
  12585. if(ptr){
  12586. sscanf(ptr,"%*s %d",&bytes_received);
  12587. }else
  12588. bytes_received=-1; //unknown size
  12589. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12590. }
  12591. DEBUG_INFO("End HEADER ..\n");
  12592. return bytes_received ;
  12593. }
  12594. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12595. {
  12596. char rmFileCmd[100]={0};
  12597. char FilePath[100]={0};
  12598. char ftpbuf[200];
  12599. int systemresult;
  12600. //DEBUG_INFO("filename=%s\n",filename);
  12601. //DEBUG_INFO("url=%s\n",url);
  12602. sprintf(FilePath,"/mnt/%s",filename);
  12603. if((access(FilePath,F_OK))!=-1)
  12604. {
  12605. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12606. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12607. system(rmFileCmd);
  12608. }
  12609. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12610. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12611. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12612. systemresult = system(ftpbuf);
  12613. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12614. if(systemresult != 0)
  12615. {
  12616. DEBUG_INFO("http DownLoad error!\n");
  12617. return FALSE;
  12618. }
  12619. return TRUE;
  12620. }
  12621. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12622. {
  12623. char rmFileCmd[100]={0};
  12624. char FilePath[100]={0};
  12625. char ftpbuf[200];
  12626. int systemresult;
  12627. //char temp[100];
  12628. sprintf(FilePath,"/mnt/%s",filename);
  12629. if((access(FilePath,F_OK))!=-1)
  12630. {
  12631. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12632. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12633. system(rmFileCmd);
  12634. }
  12635. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12636. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12637. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12638. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12639. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12640. systemresult = system(ftpbuf);
  12641. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12642. if(systemresult != 0)
  12643. {
  12644. printf("wget error!\n");
  12645. return FALSE;
  12646. }
  12647. return TRUE;
  12648. }
  12649. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12650. {
  12651. char rmFileCmd[100]={0};
  12652. char FilePath[100]={0};
  12653. char ftpbuf[200];
  12654. int systemresult;
  12655. //DEBUG_INFO("filename=%s\n",filename);
  12656. //DEBUG_INFO("url=%s\n",url);
  12657. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12658. if((access(FilePath,F_OK))!=-1)
  12659. {
  12660. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12661. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12662. system(rmFileCmd);
  12663. }
  12664. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12665. if(fp == NULL)
  12666. {
  12667. DEBUG_INFO("log is NULL\n");
  12668. return FALSE;
  12669. }
  12670. else
  12671. {
  12672. fprintf(fp, "%s\n", url);
  12673. fprintf(fp, "%s\n", filename);
  12674. fclose(fp);
  12675. }
  12676. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12677. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12678. systemresult = system(ftpbuf);
  12679. DEBUG_INFO("systemresult = %d\n",systemresult);
  12680. if(systemresult != 0)
  12681. {
  12682. DEBUG_INFO("http upload error!\n");
  12683. return FALSE;
  12684. }
  12685. return TRUE;
  12686. }
  12687. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12688. {
  12689. struct hostent* server;
  12690. char *IPbuffer;
  12691. char ftpbuf[200];
  12692. int systemresult;
  12693. // To retrieve host information
  12694. server = gethostbyname(location);
  12695. // To convert an Internet network
  12696. // address into ASCII string
  12697. IPbuffer = inet_ntoa(*((struct in_addr*)
  12698. server->h_addr_list[0]));
  12699. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12700. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12701. /* format : ftpput -u username -p passwd IP target source*/
  12702. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12703. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12704. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12705. systemresult = system(ftpbuf);
  12706. DEBUG_INFO("systemresult=%d\n",systemresult);
  12707. if(systemresult != 0)
  12708. {
  12709. DEBUG_INFO("ftpput error!\n");
  12710. return FALSE;
  12711. }
  12712. return TRUE;
  12713. }
  12714. /**
  12715. * Place the contents of the specified file into a memory buffer
  12716. *
  12717. * @param[in] filename The path and name of the file to read
  12718. * @param[out] filebuffer A pointer to the contents in memory
  12719. * @return status 0 success, 1 on failure
  12720. */
  12721. int get_file_contents(const char* filename, char** outbuffer) {
  12722. FILE* file = NULL;
  12723. long filesize;
  12724. const int blocksize = 1;
  12725. size_t readsize;
  12726. char* filebuffer;
  12727. // Open the file
  12728. file = fopen(filename, "r");
  12729. if (NULL == file)
  12730. {
  12731. printf("'%s' not opened\n", filename);
  12732. exit(EXIT_FAILURE);
  12733. }
  12734. // Determine the file size
  12735. fseek(file, 0, SEEK_END);
  12736. filesize = ftell(file);
  12737. rewind (file);
  12738. // Allocate memory for the file contents
  12739. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12740. *outbuffer = filebuffer;
  12741. if (filebuffer == NULL)
  12742. {
  12743. fputs ("malloc out-of-memory", stderr);
  12744. exit(EXIT_FAILURE);
  12745. }
  12746. // Read in the file
  12747. readsize = fread(filebuffer, blocksize, filesize, file);
  12748. if (readsize != filesize)
  12749. {
  12750. fputs ("didn't read file completely",stderr);
  12751. exit(EXIT_FAILURE);
  12752. }
  12753. // Clean exit
  12754. fclose(file);
  12755. return EXIT_SUCCESS;
  12756. }
  12757. static int selectSqlCount = 0;
  12758. static int callback(void *data, int argc, char **argv, char **azColName){
  12759. int i;
  12760. //printf("%s: ", (const char*)data);
  12761. selectSqlCount = argc;
  12762. for(i = 0; i<argc; i++){
  12763. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12764. }
  12765. //printf("\n");
  12766. return 0;
  12767. }
  12768. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12769. //int i;
  12770. //printf("%s:\n", (const char*)data);
  12771. localversion = argv[5] ? atoi(argv[5]) : 0;
  12772. //printf("localversion=%d\n", localversion);
  12773. return 0;
  12774. }
  12775. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12776. //int i;
  12777. //printf("%s:\n", (const char*)data);
  12778. //idTag
  12779. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12780. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12781. //parentIdTag
  12782. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12783. //expir_date
  12784. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12785. //status
  12786. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12787. //version
  12788. idTagQuery.listVersionInt = atoi(argv[5]);
  12789. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12790. return 0;
  12791. }
  12792. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12793. {
  12794. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12795. // printf("localversion=%d\n", localversion);
  12796. return 0;
  12797. }
  12798. //=========================================
  12799. // Sqlite3 related function
  12800. //=========================================
  12801. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12802. {
  12803. for (int i = 0; i < n_columns; i++)
  12804. {
  12805. DEBUG_INFO("%s\t", col_values[i]);
  12806. }
  12807. DEBUG_INFO("\n");
  12808. return 0;
  12809. }
  12810. void OCPP_getListVerion()
  12811. {
  12812. int rc = 0;
  12813. // const char* data = "Callback function called";
  12814. char sql[100];
  12815. char zErrMsg[100];
  12816. memset(sql, 0, 100);
  12817. memset(zErrMsg, 0, 100);
  12818. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12819. /* Execute SQL statement */
  12820. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12821. if( rc != SQLITE_OK )
  12822. {
  12823. DEBUG_INFO("SQL error: %s", zErrMsg);
  12824. }
  12825. }
  12826. void OCPP_getIdTag(char idTag[])
  12827. {
  12828. int rc = 0;
  12829. // const char* data = "Callback function called";
  12830. char sql[100];
  12831. char zErrMsg[100];
  12832. memset(sql, 0, 100);
  12833. memset(zErrMsg, 0, 100);
  12834. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  12835. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12836. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12837. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12838. /* Execute SQL statement */
  12839. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12840. if( rc != SQLITE_OK )
  12841. {
  12842. DEBUG_INFO("SQL error: %s", zErrMsg);
  12843. }
  12844. //return ver;
  12845. }
  12846. void OCPP_get_TableAuthlocalAllData(void)
  12847. {
  12848. int rc = 0;
  12849. char sql[100];
  12850. char zErrMsg[100];
  12851. memset(sql, 0, 100);
  12852. memset(zErrMsg, 0, 100);
  12853. sprintf(sql,"select * from ocpp_auth_local ");
  12854. /* Execute SQL statement */
  12855. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12856. if( rc != SQLITE_OK )
  12857. {
  12858. DEBUG_INFO("SQL error: %s", zErrMsg);
  12859. }
  12860. //return ver;
  12861. }
  12862. int OCPP_cleanLocalList()
  12863. {
  12864. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12865. char *errMsg = 0;
  12866. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12867. if (SQLITE_OK != rc)
  12868. {
  12869. DEBUG_INFO("%s\n",errMsg);
  12870. return FALSE;
  12871. }
  12872. return TRUE;
  12873. }
  12874. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12875. {
  12876. int isSuccess = FALSE;
  12877. int ret = 0;
  12878. //const char* data = "Callback function called";
  12879. char sql[300];
  12880. char zErrMsg[200];
  12881. memset(sql, 0, 300);
  12882. memset(zErrMsg, 0, 200);
  12883. 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);
  12884. //* Execute SQL statement */
  12885. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12886. if( ret != SQLITE_OK )
  12887. {
  12888. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12889. return isSuccess;
  12890. }
  12891. memset(sql, 0, 300);
  12892. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  12893. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  12894. if( ret != SQLITE_OK )
  12895. {
  12896. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12897. return isSuccess;
  12898. }
  12899. isSuccess = TRUE;
  12900. return isSuccess;
  12901. }
  12902. void OCPP_deleteIdTag(char idTag[])
  12903. {
  12904. //int ver = 0;
  12905. //int isSuccess = FALSE;
  12906. int rc = 0;
  12907. char sql[100];
  12908. char zErrMsg[100];
  12909. memset(sql, 0, 100);
  12910. memset(zErrMsg, 0, 100);
  12911. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12912. //* Execute SQL statement */
  12913. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12914. if( rc != SQLITE_OK )
  12915. {
  12916. DEBUG_INFO("SQL error: %s", zErrMsg);
  12917. }
  12918. }
  12919. int GetOcppServerURL()
  12920. {
  12921. int result = FALSE;
  12922. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  12923. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  12924. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  12925. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12926. {
  12927. #if 1
  12928. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12929. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12930. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12931. #endif
  12932. result = TRUE;
  12933. goto End;
  12934. }
  12935. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12936. {
  12937. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12938. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12939. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12940. result = TRUE;
  12941. goto End;
  12942. }
  12943. else
  12944. {
  12945. strcpy(OcppHost,"");
  12946. }
  12947. End:
  12948. return result;
  12949. }
  12950. int GetOcppPath()
  12951. {
  12952. int result = FALSE;
  12953. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12954. {
  12955. if(OcppTempPath == NULL)
  12956. {
  12957. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12958. }
  12959. else
  12960. {
  12961. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12962. }
  12963. result = TRUE;
  12964. goto End;
  12965. }
  12966. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12967. {
  12968. if(OcppTempPath == NULL)
  12969. {
  12970. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12971. }
  12972. else
  12973. {
  12974. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12975. }
  12976. result = TRUE;
  12977. goto End;
  12978. }
  12979. else
  12980. {
  12981. strcpy(OcppPath,"");
  12982. }
  12983. End:
  12984. return result;
  12985. }
  12986. int GetOcppPort()
  12987. {
  12988. return OcppPort;
  12989. }
  12990. int GetOcppConnStatus(void)
  12991. {
  12992. return ShmOCPP16Data->OcppConnStatus;
  12993. }
  12994. void SetOcppConnStatus(uint8_t status)
  12995. {
  12996. ShmOCPP16Data->OcppConnStatus = status;
  12997. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12998. }
  12999. int GetHeartBeatWithNOResponse(void)
  13000. {
  13001. return HeartBeatWithNOResponse;
  13002. }
  13003. void SetHeartBeatWithNOResponse(void)
  13004. {
  13005. HeartBeatWithNOResponse = 0;
  13006. }
  13007. void GetStartTransactionIdTag(int gun_index)
  13008. {
  13009. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13010. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13011. }
  13012. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13013. {
  13014. char ch;
  13015. FILE *fptr1;
  13016. int temptransactionId;
  13017. char str[100]={0};
  13018. temptransactionId = 0;
  13019. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  13020. {
  13021. DEBUG_INFO("IdTag is empty.\n");
  13022. return temptransactionId;
  13023. }
  13024. /*------ Read the file ----------------*/
  13025. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13026. if (!fptr1)
  13027. {
  13028. DEBUG_INFO("QueueTransactionId file open error.\n");
  13029. //printf(" File not found or unable to open the input file!!\n");
  13030. return temptransactionId;
  13031. }
  13032. ch=fgetc(fptr1);
  13033. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13034. rewind(fptr1);
  13035. if(ch!=EOF)
  13036. {
  13037. // printf("%c",ch);
  13038. while (fgets(str, 100, fptr1) != NULL)
  13039. {
  13040. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13041. if(str[0]=='\0')
  13042. {
  13043. break;
  13044. }
  13045. char *revbuf[8] = {0}; //存放分割後的子字串
  13046. int num = 0;//分割後子字串的個數
  13047. DEBUG_INFO("str: %s\n", str);
  13048. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13049. DEBUG_INFO("revbuf[0]: %s\n", revbuf[0]);
  13050. DEBUG_INFO("revbuf[1]: %s\n", revbuf[1]);
  13051. DEBUG_INFO("revbuf[2]: %s\n", revbuf[2]);
  13052. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13053. {
  13054. if(isStopTransaction)
  13055. {
  13056. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13057. {
  13058. temptransactionId = atoi(revbuf[2]);
  13059. break;
  13060. }
  13061. }
  13062. else
  13063. {
  13064. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13065. {
  13066. temptransactionId = atoi(revbuf[2]);
  13067. break;
  13068. }
  13069. }
  13070. }
  13071. }
  13072. }
  13073. else
  13074. DEBUG_INFO("EOF\n");
  13075. fclose(fptr1);
  13076. /*------- End of reading ---------------*/
  13077. return temptransactionId;
  13078. }
  13079. void SetTransactionIdZero(int transactionId)
  13080. {
  13081. char ch;
  13082. FILE *fptr1, *fptr2;
  13083. int temptransactionId = 0;
  13084. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13085. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13086. if (!fptr1)
  13087. {
  13088. //printf(" File not found or unable to open the input file!!\n");
  13089. return ;
  13090. }
  13091. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13092. if (!fptr2)
  13093. {
  13094. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13095. fclose(fptr1);
  13096. return ;
  13097. }
  13098. ch=fgetc(fptr1);
  13099. rewind(fptr1);
  13100. if(ch!=EOF)
  13101. {
  13102. // copy all contents to the temporary file except the specific line
  13103. while (fgets(str, 100, fptr1) != NULL)
  13104. {
  13105. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13106. if(str[0]=='\0')
  13107. {
  13108. break;
  13109. }
  13110. char *revbuf[8] = {0};
  13111. int num = 0;
  13112. strcpy(strtemp, str);
  13113. splitstring(str,",",revbuf,&num);
  13114. if(revbuf[2][0] != '\0')
  13115. {
  13116. temptransactionId = atoi(revbuf[2]);
  13117. if(transactionId != temptransactionId)
  13118. {
  13119. fprintf(fptr2, "%s\n", strtemp);
  13120. }
  13121. }
  13122. }
  13123. }
  13124. fclose(fptr1);
  13125. fclose(fptr2);
  13126. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13127. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13128. /*------ Read the file ----------------*/
  13129. }
  13130. int InternetDisconnect(void)
  13131. {
  13132. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13133. }
  13134. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13135. void storeTempStopTransaction(int gun_index)
  13136. {
  13137. char guid[37]={0};
  13138. int tempIndex = 0;
  13139. char TempStopTransaction[256];
  13140. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13141. DEBUG_INFO("storeTempStopTransaction...\n");
  13142. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13143. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13144. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13145. if(gunType[gun_index] == 'J')
  13146. {
  13147. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13148. {
  13149. tempIndex = ((gun_index==2) ? 1: 0);
  13150. }
  13151. else
  13152. {
  13153. tempIndex = gun_index;
  13154. }
  13155. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13156. {
  13157. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13158. {
  13159. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13160. }
  13161. }// END OF CHAdeMO_QUANTITY
  13162. }
  13163. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13164. {
  13165. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13166. {
  13167. tempIndex = ((gun_index==2) ? 1: 0);
  13168. }
  13169. else
  13170. {
  13171. tempIndex = gun_index;
  13172. }
  13173. for (int index = 0; index < CCS_QUANTITY; index++)
  13174. {
  13175. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13176. {
  13177. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13178. }
  13179. }// END OF CCS_QUANTITY
  13180. }
  13181. else if(gunType[gun_index] == 'G')
  13182. {
  13183. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13184. {
  13185. tempIndex = ((gun_index==2) ? 1: 0);
  13186. }
  13187. else
  13188. {
  13189. tempIndex = gun_index;
  13190. }
  13191. for (int index = 0; index < GB_QUANTITY; index++)
  13192. {
  13193. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13194. {
  13195. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13196. }
  13197. }// END OF GB_QUANTITY
  13198. }
  13199. else
  13200. {
  13201. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13202. {
  13203. tempIndex = 2;
  13204. }
  13205. else
  13206. {
  13207. tempIndex = gun_index;
  13208. }
  13209. for (int index = 0; index < AC_QUANTITY; index++)
  13210. {
  13211. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13212. {
  13213. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13214. }
  13215. }// END OF AC_QUANTITY
  13216. }
  13217. //Stop Transaction Time
  13218. struct timeval tmnow;
  13219. struct tm *tm;
  13220. char buf[28];//, usec_buf[6];
  13221. gettimeofday(&tmnow, NULL);
  13222. time_t t;
  13223. t = time(NULL);
  13224. /*UTC time and date*/
  13225. tm = gmtime(&t);
  13226. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13227. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13228. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13229. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13230. random_uuid(guid);
  13231. /***********************************transactionData******************************************************/
  13232. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13233. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13234. //=================================
  13235. //1. Transaction_Begin
  13236. //=================================
  13237. //============================== Energy.Active.Import.Interval ===========================================
  13238. //idx_sample=0;
  13239. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  13240. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13241. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13242. 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*/]);
  13243. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13244. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13245. {
  13246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13247. }
  13248. else
  13249. {
  13250. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13251. }
  13252. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13253. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13254. //=================================
  13255. //2. Transaction_End
  13256. //=================================
  13257. //2.1====================================== Current.Import L1 ==============================================
  13258. //idx_sample=1;
  13259. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13260. if(gunType[gun_index] == 'J')
  13261. {
  13262. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13263. {
  13264. tempIndex = ((gun_index==2) ? 1: 0);
  13265. }
  13266. else
  13267. {
  13268. tempIndex = gun_index;
  13269. }
  13270. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13271. {
  13272. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13273. {
  13274. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13275. }
  13276. }// End of for CHAdeMO_QUANTITY
  13277. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13278. }
  13279. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13280. {
  13281. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13282. {
  13283. tempIndex = ((gun_index==2) ? 1: 0);
  13284. }
  13285. else
  13286. {
  13287. tempIndex = gun_index;
  13288. }
  13289. for (int index = 0; index < CCS_QUANTITY; index++)
  13290. {
  13291. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13292. {
  13293. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13294. }
  13295. }// End of for CCS_QUANTITY
  13296. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13297. }
  13298. else if(gunType[gun_index] == 'G')
  13299. {
  13300. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13301. {
  13302. tempIndex = ((gun_index==2) ? 1: 0);
  13303. }
  13304. else
  13305. {
  13306. tempIndex = gun_index;
  13307. }
  13308. for (int index = 0; index < GB_QUANTITY; index++)
  13309. {
  13310. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13311. {
  13312. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13313. }
  13314. }// End of for GB_QUANTITY
  13315. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13316. }
  13317. else
  13318. {
  13319. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13320. {
  13321. tempIndex = 2;
  13322. }
  13323. else
  13324. {
  13325. tempIndex = gun_index;
  13326. }
  13327. for (int index = 0; index < AC_QUANTITY; index++)
  13328. {
  13329. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13330. {
  13331. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13332. }
  13333. }// End of for AC_QUANTITY
  13334. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13335. }
  13336. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13337. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13338. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13339. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13340. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13341. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13342. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13343. //idx_sample=2;
  13344. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13345. if(gunType[gun_index] == 'J')
  13346. {
  13347. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13348. {
  13349. tempIndex = ((gun_index==2) ? 1: 0);
  13350. }
  13351. else
  13352. {
  13353. tempIndex = gun_index;
  13354. }
  13355. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13356. {
  13357. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13358. {
  13359. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13360. }
  13361. }// END OF CHAdeMO_QUANTITY
  13362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13363. }
  13364. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13365. {
  13366. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13367. {
  13368. tempIndex = ((gun_index==2) ? 1: 0);
  13369. }
  13370. else
  13371. {
  13372. tempIndex = gun_index;
  13373. }
  13374. for (int index = 0; index < CCS_QUANTITY; index++)
  13375. {
  13376. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13377. {
  13378. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13379. }
  13380. }// END OF CCS_QUANTITY
  13381. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13382. }
  13383. else if(gunType[gun_index] == 'G')
  13384. {
  13385. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13386. {
  13387. tempIndex = ((gun_index==2) ? 1: 0);
  13388. }
  13389. else
  13390. {
  13391. tempIndex = gun_index;
  13392. }
  13393. for (int index = 0; index < GB_QUANTITY; index++)
  13394. {
  13395. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13396. {
  13397. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13398. }
  13399. }// END OF GB_QUANTITY
  13400. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13401. }
  13402. else
  13403. {
  13404. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13405. {
  13406. tempIndex = 2;
  13407. }
  13408. else
  13409. {
  13410. tempIndex = gun_index;
  13411. }
  13412. for (int index = 0; index < AC_QUANTITY; index++)
  13413. {
  13414. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13415. {
  13416. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13417. }
  13418. }// END OF AC_QUANTITY
  13419. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13420. }
  13421. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13423. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13424. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13425. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13426. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13427. //2.3====================================== Power.Active.Import =========================================
  13428. //idx_sample=3;
  13429. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13430. if(gunType[gun_index] == 'J')
  13431. {
  13432. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13433. {
  13434. tempIndex = ((gun_index==2) ? 1: 0);
  13435. }
  13436. else
  13437. {
  13438. tempIndex = gun_index;
  13439. }
  13440. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13441. {
  13442. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13443. {
  13444. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13445. }
  13446. } // End for CHAdeMO_QUANTITY
  13447. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13448. }
  13449. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13450. {
  13451. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13452. {
  13453. tempIndex = ((gun_index==2) ? 1: 0);
  13454. }
  13455. else
  13456. {
  13457. tempIndex = gun_index;
  13458. }
  13459. for (int index = 0; index < CCS_QUANTITY; index++)
  13460. {
  13461. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13462. {
  13463. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13464. }
  13465. } // END for CCS_QUANTITY
  13466. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13467. }
  13468. else if(gunType[gun_index] == 'G')
  13469. {
  13470. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13471. {
  13472. tempIndex = ((gun_index==2) ? 1: 0);
  13473. }
  13474. else
  13475. {
  13476. tempIndex = gun_index;
  13477. }
  13478. for (int index = 0; index < GB_QUANTITY; index++)
  13479. {
  13480. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13481. {
  13482. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13483. }
  13484. }// END for GB_QUANTITY
  13485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13486. }
  13487. else
  13488. {
  13489. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13490. {
  13491. tempIndex = 2;
  13492. }
  13493. else
  13494. {
  13495. tempIndex = gun_index;
  13496. }
  13497. for (int index = 0; index < AC_QUANTITY; index++)
  13498. {
  13499. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13500. {
  13501. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13502. }
  13503. } // END for AC_QUANTITY
  13504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13505. }
  13506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13508. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13509. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13512. //2.4====================================== Voltage L1 ====================================================
  13513. //idx_sample=4;
  13514. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13515. if(gunType[gun_index] == 'J')
  13516. {
  13517. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13518. {
  13519. tempIndex = ((gun_index==2) ? 1: 0);
  13520. }
  13521. else
  13522. {
  13523. tempIndex = gun_index;
  13524. }
  13525. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13526. {
  13527. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13528. {
  13529. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13530. }
  13531. } // END OF FOR CHAdeMO_QUANTITY
  13532. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13533. }
  13534. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13535. {
  13536. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13537. {
  13538. tempIndex = ((gun_index==2) ? 1: 0);
  13539. }
  13540. else
  13541. {
  13542. tempIndex = gun_index;
  13543. }
  13544. for (int index = 0; index < CCS_QUANTITY; index++)
  13545. {
  13546. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13547. {
  13548. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13549. }
  13550. } // END OF FOR CCS_QUANTITY
  13551. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13552. }
  13553. else if(gunType[gun_index] == 'G')
  13554. {
  13555. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13556. {
  13557. tempIndex = ((gun_index==2) ? 1: 0);
  13558. }
  13559. else
  13560. {
  13561. tempIndex = gun_index;
  13562. }
  13563. for (int index = 0; index < GB_QUANTITY; index++)
  13564. {
  13565. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13566. {
  13567. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13568. }
  13569. } // END OF FOR GB_QUANTITY
  13570. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13571. }
  13572. else
  13573. {
  13574. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13575. {
  13576. tempIndex = 2;
  13577. }
  13578. else
  13579. {
  13580. tempIndex = gun_index;
  13581. }
  13582. for (int index = 0; index < AC_QUANTITY; index++)
  13583. {
  13584. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13585. {
  13586. 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
  13587. }
  13588. } // END OF FOR AC_QUANTITY
  13589. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13590. }
  13591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13592. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13593. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13594. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13596. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13597. //2.5============================================== SoC =========================================================
  13598. //idx_sample=5;
  13599. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13600. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13601. {
  13602. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13603. {
  13604. tempIndex = ((gun_index==2) ? 1: 0);
  13605. }
  13606. else
  13607. {
  13608. tempIndex = gun_index;
  13609. }
  13610. if(gunType[gun_index] == 'J')
  13611. {
  13612. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13613. {
  13614. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13615. {
  13616. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13617. }
  13618. }
  13619. }
  13620. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13621. {
  13622. for (int index = 0; index < CCS_QUANTITY; index++)
  13623. {
  13624. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13625. {
  13626. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13627. }
  13628. }
  13629. }
  13630. else if(gunType[gun_index] == 'G')
  13631. {
  13632. for (int index = 0; index < GB_QUANTITY; index++)
  13633. {
  13634. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13635. {
  13636. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13637. }
  13638. }
  13639. }
  13640. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13641. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13642. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13644. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  13645. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13646. } // END FOR DC CASE
  13647. //2.6====================================== Current.Import L2 ==============================================
  13648. // idx_sample=6;
  13649. // AC 3 phase L2 current
  13650. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13651. {
  13652. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13653. {
  13654. tempIndex = 2;
  13655. }
  13656. else
  13657. {
  13658. tempIndex = gun_index;
  13659. }
  13660. for (int index = 0; index < AC_QUANTITY; index++)
  13661. {
  13662. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13663. {
  13664. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  13665. }
  13666. }// End of for AC_QUANTITY
  13667. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  13668. }
  13669. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13670. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  13671. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  13672. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  13673. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13674. //2.7====================================== Current.Import L3 ==============================================
  13675. // idx_sample=7;
  13676. // AC 3 phase L3 current
  13677. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13678. {
  13679. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13680. {
  13681. tempIndex = 2;
  13682. }
  13683. else
  13684. {
  13685. tempIndex = gun_index;
  13686. }
  13687. for (int index = 0; index < AC_QUANTITY; index++)
  13688. {
  13689. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13690. {
  13691. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  13692. }
  13693. }// End of for AC_QUANTITY
  13694. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  13695. }
  13696. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13697. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  13698. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  13699. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  13700. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13701. //2.9====================================== Voltage L2 ====================================================
  13702. //idx_sample=8;
  13703. // AC 3 phase L2 volatge
  13704. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13705. {
  13706. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13707. {
  13708. tempIndex = 2;
  13709. }
  13710. else
  13711. {
  13712. tempIndex = gun_index;
  13713. }
  13714. for (int index = 0; index < AC_QUANTITY; index++)
  13715. {
  13716. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13717. {
  13718. 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
  13719. }
  13720. } // END OF FOR AC_QUANTITY
  13721. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  13722. }
  13723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13724. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  13725. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  13726. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  13727. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13728. //2.10====================================== Voltage L3 ====================================================
  13729. //idx_sample=9;
  13730. // AC 3 phase L3 volatge
  13731. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13732. {
  13733. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13734. {
  13735. tempIndex = 2;
  13736. }
  13737. else
  13738. {
  13739. tempIndex = gun_index;
  13740. }
  13741. for (int index = 0; index < AC_QUANTITY; index++)
  13742. {
  13743. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13744. {
  13745. 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
  13746. }
  13747. } // END OF FOR AC_QUANTITY
  13748. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  13749. }
  13750. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13751. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  13752. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  13753. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  13754. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13755. //======================================== Message create ==============================================
  13756. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13757. {
  13758. 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\"}]}]}]"
  13759. ,gun_index+1
  13760. ,MESSAGE_TYPE_CALL
  13761. ,guid
  13762. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13763. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13764. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13765. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13766. ,"PowerLoss"
  13767. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13768. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13769. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13770. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13771. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13772. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13773. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13774. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13775. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13776. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13777. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13778. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13779. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13780. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13781. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13782. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13783. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13784. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13785. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13786. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13787. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13788. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13789. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13790. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13791. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13792. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13793. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13794. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13795. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13796. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13797. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13798. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13799. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13800. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13801. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13802. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13803. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  13804. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  13805. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  13806. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  13807. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  13808. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  13809. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  13810. );
  13811. }
  13812. else
  13813. {
  13814. if(((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W')))
  13815. {
  13816. 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\"}]}]}]"
  13817. ,gun_index+1
  13818. ,MESSAGE_TYPE_CALL
  13819. ,guid
  13820. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13821. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13822. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13823. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13824. ,"PowerLoss"
  13825. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13826. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13827. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13828. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13829. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13830. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13831. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13832. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13833. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13834. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13835. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13836. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13837. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13838. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13839. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13840. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13841. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13842. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13843. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13844. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13845. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13846. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13847. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13848. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13849. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13850. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13851. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13852. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13853. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13854. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13855. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13856. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13857. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13858. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13859. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13860. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13861. );
  13862. }
  13863. else
  13864. {
  13865. 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\"}]}]}]"
  13866. ,gun_index+1
  13867. ,MESSAGE_TYPE_CALL
  13868. ,guid
  13869. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13870. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13871. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13873. ,"PowerLoss"
  13874. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13890. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13894. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13895. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13896. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13897. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13898. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13899. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13900. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13901. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13902. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13903. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13904. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13905. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13906. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13907. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13908. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13909. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13910. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  13911. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  13912. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  13913. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  13914. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  13915. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  13916. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  13917. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  13918. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  13919. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  13920. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  13921. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  13922. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  13923. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  13924. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  13925. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  13926. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  13927. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  13928. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  13929. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  13930. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  13931. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  13932. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  13933. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  13934. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  13935. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  13936. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  13937. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  13938. );
  13939. }
  13940. }
  13941. // Check File "TempStopTransaction" Exist
  13942. if((access(TempStopTransaction,F_OK))!=-1)
  13943. {
  13944. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  13945. fclose(fopen(TempStopTransaction, "w"));
  13946. }
  13947. else
  13948. {
  13949. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  13950. FILE *log = fopen(TempStopTransaction, "w+");
  13951. if(log == NULL)
  13952. {
  13953. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  13954. return ;
  13955. }
  13956. else
  13957. {
  13958. fclose(log);
  13959. }
  13960. }
  13961. //Add TempStopTransaction | Update TempStopTransaction
  13962. // open file for writing
  13963. FILE *outfile;
  13964. outfile = fopen (TempStopTransaction, "a");
  13965. //DEBUG_INFO("data = %s\n", queuedata);
  13966. fputs(queuedata, outfile);
  13967. fputs("\n", outfile);
  13968. fclose (outfile);
  13969. }
  13970. void checkTempStopTransaction(int gun_index)
  13971. {
  13972. FILE *fptr1;
  13973. char ch;
  13974. char str[QUEUE_MESSAGE_LENGTH]={0};
  13975. char guid[37]={0};
  13976. char tempdata[65]={0};
  13977. char connectorStr[2]={0};
  13978. char TempStopTransaction[256];
  13979. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13980. fptr1 = fopen(TempStopTransaction, "r");
  13981. //TempStopTransaction格式: 槍號,StopTransaction封包
  13982. if (!fptr1)
  13983. {
  13984. //printf(" File not found or unable to open the input file!!\n");
  13985. return ;
  13986. }
  13987. ch=fgetc(fptr1);
  13988. //printf(" Now the content of the file %s is : \n",fname);
  13989. rewind(fptr1);
  13990. if(ch!=EOF)
  13991. {
  13992. // copy all contents to the temporary file except the specific line
  13993. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  13994. {
  13995. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13996. if(str[0]=='\0')
  13997. {
  13998. break;
  13999. }
  14000. //TempStopTransaction格式: 槍號,StopTransaction封包
  14001. strncpy(connectorStr, str, 1);
  14002. if(atoi(connectorStr) != (gun_index+1))
  14003. {
  14004. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  14005. fclose(fptr1);
  14006. return ;
  14007. }
  14008. //random_uuid(guid);
  14009. strncpy(guid, str+6, 36); //copy guid
  14010. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14011. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14012. {
  14013. DEBUG_INFO("StopTransaction mapitem pass\n");
  14014. }
  14015. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14016. memset(str,0,ARRAY_SIZE(str));
  14017. }
  14018. }
  14019. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14020. fclose(fptr1);
  14021. remove(TempStopTransaction); // remove the original file
  14022. }
  14023. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14024. {
  14025. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14026. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14027. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14028. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14029. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14030. }
  14031. int GetWebSocketPingInterval(void)
  14032. {
  14033. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14034. }
  14035. int GetServerSign(void)
  14036. {
  14037. return server_sign;
  14038. }
  14039. void SetServerSign(int value)
  14040. {
  14041. server_sign = value;
  14042. }
  14043. int GetBootNotificationInterval(void)
  14044. {
  14045. return BootNotificationInterval;
  14046. }
  14047. int GetInternetConn(void)
  14048. {
  14049. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14050. }
  14051. void InitialSystemValue(void)
  14052. {
  14053. int connectorIndex = 0;
  14054. //int valueASCII = 0;
  14055. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14056. gunTotalNumber=0;
  14057. SystemInitial = 0;
  14058. localversion=0;
  14059. BootNotificationInterval = 0;
  14060. authorizeRetryTimes = 0;
  14061. GunStatusInterval = 10;
  14062. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14063. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14064. //Hear Beat
  14065. HeartBeatWithNOResponse = 0;
  14066. HeartBeatCountPerHour = 0;
  14067. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14068. FirstHeartBeat = 0;
  14069. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14070. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14071. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14072. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14073. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14074. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14075. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14076. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14077. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14078. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14079. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14080. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14081. memset(gunType, 0, ARRAY_SIZE(gunType));
  14082. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14083. {
  14084. //check connector / socket type (index: 8, 9, 10)
  14085. for(int index=7; index <10 ; index++)
  14086. {
  14087. if(index != 8)
  14088. {
  14089. // DC Connector
  14090. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  14091. {
  14092. SystemInitial = SystemInitial + 1;
  14093. gunTotalNumber = gunTotalNumber + 1;
  14094. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14095. connectorIndex = connectorIndex + 1;
  14096. }
  14097. }
  14098. else
  14099. {
  14100. // AC Connector
  14101. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14102. {
  14103. SystemInitial = SystemInitial + 1;
  14104. gunTotalNumber = gunTotalNumber + 1;
  14105. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14106. connectorIndex = connectorIndex + 1;
  14107. }
  14108. }
  14109. }
  14110. //DEBUG_INFO("DC ...\n");
  14111. }
  14112. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14113. {
  14114. //check connector / socket type (index: 8, 9, 10)
  14115. for(int index=7; index <10 ; index++)
  14116. {
  14117. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14118. {
  14119. SystemInitial = SystemInitial + 1;
  14120. gunTotalNumber = gunTotalNumber + 1;
  14121. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14122. connectorIndex = connectorIndex + 1;
  14123. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14124. }
  14125. }
  14126. }
  14127. //Status && ConnectorPlugIn Setting
  14128. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14129. {
  14130. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14131. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14132. }
  14133. for (int index = 0; index < CCS_QUANTITY; index++)
  14134. {
  14135. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14136. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14137. }
  14138. for (int index = 0; index < GB_QUANTITY; index++)
  14139. {
  14140. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14141. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14142. }
  14143. for (int index = 0; index < AC_QUANTITY; index++)
  14144. {
  14145. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14146. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14147. }
  14148. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14149. {
  14150. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14151. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14152. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14153. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14154. }
  14155. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14156. clientTime.Heartbeat=time((time_t*)NULL);
  14157. sleep(1);
  14158. }
  14159. void LWS_Send(char * str)
  14160. {
  14161. //=====================================================
  14162. // Check InternetConn 0: disconnected, 1: connected
  14163. //====================================================
  14164. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14165. {
  14166. DEBUG_INFO("offline now !!!\n");
  14167. return;
  14168. }
  14169. pthread_mutex_lock(&lock_send);
  14170. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14171. sprintf((char *)SendBuffer, "%s", str);
  14172. SendBufLen = strlen(str);
  14173. pthread_mutex_unlock(&lock_send);
  14174. lws_callback_on_writable(wsi_client);
  14175. //lws_service(context, 0);
  14176. //sleep(1);
  14177. }