MessageHandler.c 691 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729
  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 _GetConfiguration_CNT
  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[CONNECTOR_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 DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  73. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  74. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  75. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  76. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  77. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  78. static int TransactionMessageAttemptsValue = 0;
  79. static int TransactionMessageRetryIntervalValue = 0;
  80. static int TempMeterValueInterval = 0;
  81. static struct OCPPAuthLocalElemet
  82. {
  83. int listVersionInt;
  84. char idTagstr[20];
  85. char parentIdTag[20];
  86. char expiryDate[30];
  87. char idTagstatus[16];
  88. }idTagQuery;
  89. //=============================================
  90. // OCPP HeartBeat Response Not Receive Counts
  91. //============================================
  92. static int HeartBeatWithNOResponse = 0;
  93. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  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[CONNECTOR_QUANTITY];
  112. unsigned int StartTransaction;
  113. unsigned int StopTransaction;
  114. unsigned int MeterValues[CONNECTOR_QUANTITY];
  115. }clientTime;
  116. typedef union
  117. {
  118. //Operations Initiated by Central System
  119. unsigned char CsMsgValue[CONNECTOR_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[CONNECTOR_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. static time_t lastTime;
  381. time_t t;
  382. struct tm *tmStartToday;
  383. struct timeb tbStartToday;
  384. t=time(NULL);
  385. if(difftime(t, lastTime)>0)
  386. {
  387. tmStartToday=localtime(&t);
  388. tmStartToday->tm_hour = 0;
  389. tmStartToday->tm_min = 0;
  390. tmStartToday->tm_sec = 0;
  391. tbStartToday.time = mktime(tmStartToday);
  392. tbStartToday.millitm = 0;
  393. result = DiffTimebWithNow(tbStartToday)/1000;
  394. lastTime = t;
  395. }
  396. return result;
  397. }
  398. //==========================================
  399. // GetCompositeSchedule logic related function
  400. //==========================================
  401. int DiffTimebSec(struct timeb ST, struct timeb ET)
  402. {
  403. //return milli-second
  404. unsigned int StartTime,StopTime;
  405. StartTime=(unsigned int)ST.time;
  406. StopTime=(unsigned int)ET.time;
  407. return (StopTime-StartTime);
  408. }
  409. int DiffTimebWithNowSec(struct timeb ST)
  410. {
  411. //return milli-second
  412. struct timeb ET;
  413. unsigned int StartTime,StopTime;
  414. ftime(&ET);
  415. StartTime=(unsigned int)ST.time;
  416. StopTime=(unsigned int)ET.time;
  417. return (StopTime-StartTime);
  418. }
  419. int getStartStop(uint8_t *start, uint8_t *stop)
  420. {
  421. int result = -1;
  422. struct tm tmStart;
  423. struct timeb tbStart;
  424. struct tm tmStop;
  425. struct timeb tbStop;
  426. 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) &&
  427. (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))
  428. {
  429. //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);
  430. //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);
  431. tmStart.tm_year -= 1900;
  432. tmStart.tm_mon -= 1;
  433. tbStart.time = mktime(&tmStart);
  434. tbStart.millitm = 0;
  435. tmStop.tm_year -= 1900;
  436. tmStop.tm_mon -= 1;
  437. tbStop.time = mktime(&tmStop);
  438. tbStop.millitm = 0;
  439. result = DiffTimebSec(tbStart, tbStop);
  440. //DEBUG_INFO("getStartStop(): %d\n", result);
  441. }
  442. else
  443. {
  444. DEBUG_WARN("Start or stop date parsing error.\r\n");
  445. }
  446. return result;
  447. }
  448. int isOvertNow(uint8_t *start)
  449. {
  450. int result = YES;
  451. struct tm tmStart;
  452. struct timeb tbStart;
  453. 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))
  454. {
  455. //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);
  456. tmStart.tm_year -= 1900;
  457. tmStart.tm_mon -= 1;
  458. tbStart.time = mktime(&tmStart);
  459. tbStart.millitm = 0;
  460. if(DiffTimebWithNowSec(tbStart) <= 0)
  461. result = NO;
  462. }
  463. else
  464. {
  465. DEBUG_WARN("Start date parsing error.\r\n");
  466. }
  467. return result;
  468. }
  469. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  470. {
  471. int result = -1;
  472. struct tm tmStart;
  473. struct timeb tbStart;
  474. struct tm tmStop;
  475. struct timeb tbStop;
  476. 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) &&
  477. (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))
  478. {
  479. tmStart.tm_year -= 1900;
  480. tmStart.tm_mon -= 1;
  481. tbStart.time = mktime(&tmStart);
  482. tbStart.millitm = 0;
  483. tmStop.tm_year -= 1900;
  484. tmStop.tm_mon -= 1;
  485. tbStop.time = mktime(&tmStop);
  486. tbStop.millitm = 0;
  487. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  488. }
  489. return result;
  490. }
  491. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  492. {
  493. FILE *fp;
  494. char profileFileName[128];
  495. char *line = NULL;
  496. size_t len = 0;
  497. time_t CurrentTime;
  498. struct tm *tmComposite;
  499. struct StructChargingProfile maxProfile;
  500. struct StructChargingProfile defaultTxProfile;
  501. struct StructChargingProfile txProfile;
  502. struct StructChargingSchedulePeriod tmpPeriod;
  503. uint8_t limitMax=0;
  504. uint8_t limitDef=0;
  505. uint8_t limitTx=0;
  506. int compositePeriodIdx = 0;
  507. CurrentTime = time(NULL);
  508. tmComposite=localtime(&CurrentTime);
  509. 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);
  510. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  511. compositeProfile->ChargingSchedule.Duration = durationReq;
  512. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  513. {
  514. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  515. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  516. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  517. }
  518. compositeProfile->ChargingProfileId = 0;
  519. compositeProfile->StackLevel = 99 ;
  520. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  521. maxProfile.ChargingProfileId = -1;
  522. defaultTxProfile.ChargingProfileId = -1;
  523. txProfile.ChargingProfileId = -1;
  524. maxProfile.ChargingSchedule.Duration = -1;
  525. defaultTxProfile.ChargingSchedule.Duration = -1;
  526. txProfile.ChargingSchedule.Duration = -1;
  527. system("yes|rm /tmp/*.json");
  528. system("cp /Storage/OCPP/*.json /tmp");
  529. /*
  530. * Search valid charging profile
  531. */
  532. //DEBUG_INFO("====================================\n");
  533. // Search tx profile
  534. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  535. if((access(profileFileName, F_OK))!=-1)
  536. {
  537. fp = fopen(profileFileName, "r");
  538. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  539. {
  540. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  541. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  542. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  543. }
  544. txProfile.ChargingProfileId = -1;
  545. txProfile.StackLevel = -1;
  546. while(getline(&line, &len, fp) != -1)
  547. {
  548. json_object *obj = NULL;
  549. obj = json_tokener_parse(line);
  550. if(is_error(obj))
  551. {
  552. DEBUG_ERROR("Parse txProfile from file error.\n");
  553. }
  554. else
  555. {
  556. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  557. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  558. )
  559. {
  560. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  561. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  562. )
  563. {
  564. struct tm tmFrom, tmTo;
  565. struct timeb tbFrom, tbTo;
  566. 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) &&
  567. (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))
  568. {
  569. tmFrom.tm_year -= 1900;
  570. tmFrom.tm_mon -= 1;
  571. tbFrom.time = mktime(&tmFrom);
  572. tmTo.tm_year -= 1900;
  573. tmTo.tm_mon -= 1;
  574. tbTo.time = mktime(&tmTo);
  575. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  576. {
  577. if(txProfile.ChargingProfileId == -1)
  578. DEBUG_INFO("TxProfile found.\n");
  579. else
  580. DEBUG_INFO("TxProfile updated.\n");
  581. // Required item
  582. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  583. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  584. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  585. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  586. 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++)
  587. {
  588. 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"));
  589. 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")));
  590. 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?
  591. 3:
  592. 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")));
  593. }
  594. // Optional item
  595. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  596. {
  597. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  598. }
  599. else
  600. {
  601. sprintf((char*)txProfile.ValidFrom, " ");
  602. }
  603. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  604. {
  605. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  606. }
  607. else
  608. {
  609. sprintf((char*)txProfile.ValidTo, " ");
  610. }
  611. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  612. {
  613. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  614. }
  615. else
  616. {
  617. sprintf((char*)txProfile.RecurrencyKind, " ");
  618. }
  619. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  620. {
  621. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  622. }
  623. else
  624. {
  625. txProfile.TransactionId = -1;
  626. }
  627. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  628. {
  629. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  630. }
  631. else
  632. {
  633. txProfile.ChargingSchedule.Duration = 86400;
  634. }
  635. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  636. {
  637. 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")));
  638. }
  639. else
  640. {
  641. 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));
  642. }
  643. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  644. {
  645. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  646. }
  647. else
  648. {
  649. txProfile.ChargingSchedule.MinChargingRate = -1;
  650. }
  651. }
  652. }
  653. }
  654. else
  655. {
  656. if(txProfile.ChargingProfileId == -1)
  657. DEBUG_INFO("TxProfile found.\n");
  658. else
  659. DEBUG_INFO("TxProfile updated.\n");
  660. // Required item
  661. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  662. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  663. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  664. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  665. 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++)
  666. {
  667. 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"));
  668. 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")));
  669. 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?
  670. 3:
  671. 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")));
  672. }
  673. // Optional item
  674. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  675. {
  676. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  677. }
  678. else
  679. {
  680. sprintf((char*)txProfile.ValidFrom, " ");
  681. }
  682. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  683. {
  684. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  685. }
  686. else
  687. {
  688. sprintf((char*)txProfile.ValidTo, " ");
  689. }
  690. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  691. {
  692. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  693. }
  694. else
  695. {
  696. sprintf((char*)txProfile.RecurrencyKind, " ");
  697. }
  698. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  699. {
  700. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  701. }
  702. else
  703. {
  704. txProfile.TransactionId = -1;
  705. }
  706. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  707. {
  708. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  709. }
  710. else
  711. {
  712. txProfile.ChargingSchedule.Duration = 86400;
  713. }
  714. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  715. {
  716. 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")));
  717. }
  718. else
  719. {
  720. 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));
  721. }
  722. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  723. {
  724. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  725. }
  726. else
  727. {
  728. txProfile.ChargingSchedule.MinChargingRate = -1;
  729. }
  730. }
  731. }
  732. }
  733. json_object_put(obj);
  734. }
  735. fclose(fp);
  736. /*
  737. if(txProfile.ChargingProfileId != -1)
  738. {
  739. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  740. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  741. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  742. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  743. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  744. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  745. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  746. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  747. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  748. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  749. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  750. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  751. {
  752. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  753. {
  754. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  755. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  756. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  757. }
  758. }
  759. }
  760. else
  761. DEBUG_INFO("TxProfile not found.\n");*/
  762. }
  763. // Search default tx profile
  764. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  765. if((access(profileFileName, F_OK))==-1)
  766. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  767. if((access(profileFileName, F_OK))!=-1)
  768. {
  769. fp = fopen(profileFileName, "r");
  770. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  771. {
  772. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  773. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  774. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  775. }
  776. defaultTxProfile.ChargingProfileId = -1;
  777. defaultTxProfile.StackLevel = -1;
  778. while(getline(&line, &len, fp) != -1)
  779. {
  780. json_object *obj = NULL;
  781. obj = json_tokener_parse(line);
  782. if(is_error(obj))
  783. {
  784. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  785. }
  786. else
  787. {
  788. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  789. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  790. )
  791. {
  792. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  793. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  794. )
  795. {
  796. struct tm tmFrom, tmTo;
  797. struct timeb tbFrom, tbTo;
  798. 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) &&
  799. (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))
  800. {
  801. tmFrom.tm_year -= 1900;
  802. tmFrom.tm_mon -= 1;
  803. tbFrom.time = mktime(&tmFrom);
  804. tmTo.tm_year -= 1900;
  805. tmTo.tm_mon -= 1;
  806. tbTo.time = mktime(&tmTo);
  807. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  808. {
  809. if(defaultTxProfile.ChargingProfileId == -1)
  810. DEBUG_INFO("TxDefaultProfile found.\n");
  811. else
  812. DEBUG_INFO("TxDefaultProfile updated.\n");
  813. // Required item
  814. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  815. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  816. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  817. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  818. 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++)
  819. {
  820. 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"));
  821. 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")));
  822. 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?
  823. 3:
  824. 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")));
  825. }
  826. // Optional item
  827. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  828. {
  829. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  830. }
  831. else
  832. {
  833. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  834. }
  835. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  836. {
  837. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  838. }
  839. else
  840. {
  841. sprintf((char*)defaultTxProfile.ValidTo, " ");
  842. }
  843. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  844. {
  845. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  846. }
  847. else
  848. {
  849. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  850. }
  851. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  852. {
  853. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  854. }
  855. else
  856. {
  857. defaultTxProfile.TransactionId = -1;
  858. }
  859. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  860. {
  861. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  862. }
  863. else
  864. {
  865. defaultTxProfile.ChargingSchedule.Duration = 86400;
  866. }
  867. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  868. {
  869. 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")));
  870. }
  871. else
  872. {
  873. 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));
  874. }
  875. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  876. {
  877. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  878. }
  879. else
  880. {
  881. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  882. }
  883. }
  884. }
  885. }
  886. else
  887. {
  888. if(defaultTxProfile.ChargingProfileId == -1)
  889. DEBUG_INFO("TxDefaultProfile found.\n");
  890. else
  891. DEBUG_INFO("TxDefaultProfile updated.\n");
  892. // Required item
  893. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  894. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  895. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  896. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  897. 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++)
  898. {
  899. 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"));
  900. 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")));
  901. 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?
  902. 3:
  903. 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")));
  904. }
  905. // Optional item
  906. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  907. {
  908. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  909. }
  910. else
  911. {
  912. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  913. }
  914. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  915. {
  916. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  917. }
  918. else
  919. {
  920. sprintf((char*)defaultTxProfile.ValidTo, " ");
  921. }
  922. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  923. {
  924. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  925. }
  926. else
  927. {
  928. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  929. }
  930. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  931. {
  932. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  933. }
  934. else
  935. {
  936. defaultTxProfile.TransactionId = -1;
  937. }
  938. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  939. {
  940. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  941. }
  942. else
  943. {
  944. defaultTxProfile.ChargingSchedule.Duration = 86400;
  945. }
  946. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  947. {
  948. 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")));
  949. }
  950. else
  951. {
  952. 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));
  953. }
  954. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  955. {
  956. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  957. }
  958. else
  959. {
  960. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  961. }
  962. }
  963. }
  964. }
  965. json_object_put(obj);
  966. }
  967. fclose(fp);
  968. /*
  969. if(defaultTxProfile.ChargingProfileId != -1)
  970. {
  971. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  972. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  973. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  974. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  975. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  976. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  977. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  978. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  979. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  980. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  981. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  982. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  983. {
  984. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  985. {
  986. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  987. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  988. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  989. }
  990. }
  991. }
  992. else
  993. DEBUG_INFO("TxDefaultProfile not found.\n");
  994. DEBUG_INFO("------------------------------------\n");*/
  995. }
  996. // Search max profile
  997. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  998. if((access(profileFileName, F_OK))!=-1)
  999. {
  1000. fp = fopen(profileFileName, "r");
  1001. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1002. {
  1003. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1004. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1005. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1006. }
  1007. maxProfile.ChargingProfileId = -1;
  1008. maxProfile.StackLevel = -1;
  1009. while(getline(&line, &len, fp) != -1)
  1010. {
  1011. json_object *obj = NULL;
  1012. obj = json_tokener_parse(line);
  1013. if(is_error(obj))
  1014. {
  1015. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1016. }
  1017. else
  1018. {
  1019. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1020. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1021. )
  1022. {
  1023. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1024. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1025. )
  1026. {
  1027. struct tm tmFrom, tmTo;
  1028. struct timeb tbFrom, tbTo;
  1029. 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) &&
  1030. (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))
  1031. {
  1032. tmFrom.tm_year -= 1900;
  1033. tmFrom.tm_mon -= 1;
  1034. tbFrom.time = mktime(&tmFrom);
  1035. tmTo.tm_year -= 1900;
  1036. tmTo.tm_mon -= 1;
  1037. tbTo.time = mktime(&tmTo);
  1038. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1039. {
  1040. if(maxProfile.ChargingProfileId == -1)
  1041. DEBUG_INFO("MaxProfile found.\n");
  1042. else
  1043. DEBUG_INFO("MaxProfile updated.\n");
  1044. // Required item
  1045. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1046. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1047. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1048. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1049. 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++)
  1050. {
  1051. 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"));
  1052. 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")));
  1053. 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?
  1054. 3:
  1055. 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")));
  1056. }
  1057. // Optional item
  1058. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1059. {
  1060. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1061. }
  1062. else
  1063. {
  1064. sprintf((char*)maxProfile.ValidFrom, " ");
  1065. }
  1066. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1067. {
  1068. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1069. }
  1070. else
  1071. {
  1072. sprintf((char*)maxProfile.ValidTo, " ");
  1073. }
  1074. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1075. {
  1076. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1077. }
  1078. else
  1079. {
  1080. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1081. }
  1082. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1083. {
  1084. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1085. }
  1086. else
  1087. {
  1088. maxProfile.TransactionId = -1;
  1089. }
  1090. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1091. {
  1092. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1093. }
  1094. else
  1095. {
  1096. maxProfile.ChargingSchedule.Duration = 86400;
  1097. }
  1098. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1099. {
  1100. 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")));
  1101. }
  1102. else
  1103. {
  1104. 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));
  1105. }
  1106. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1107. {
  1108. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1109. }
  1110. else
  1111. {
  1112. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1113. }
  1114. }
  1115. }
  1116. }
  1117. else
  1118. {
  1119. if(maxProfile.ChargingProfileId == -1)
  1120. DEBUG_INFO("MaxProfile found.\n");
  1121. else
  1122. DEBUG_INFO("MaxProfile updated.\n");
  1123. // Required item
  1124. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1125. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1126. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1127. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1128. 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++)
  1129. {
  1130. 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"));
  1131. 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")));
  1132. 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?
  1133. 3:
  1134. 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")));
  1135. }
  1136. // Optional item
  1137. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1138. {
  1139. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1140. }
  1141. else
  1142. {
  1143. sprintf((char*)maxProfile.ValidFrom, " ");
  1144. }
  1145. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1146. {
  1147. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1148. }
  1149. else
  1150. {
  1151. sprintf((char*)maxProfile.ValidTo, " ");
  1152. }
  1153. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1154. {
  1155. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1156. }
  1157. else
  1158. {
  1159. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1160. }
  1161. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1162. {
  1163. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1164. }
  1165. else
  1166. {
  1167. maxProfile.TransactionId = -1;
  1168. }
  1169. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1170. {
  1171. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1172. }
  1173. else
  1174. {
  1175. maxProfile.ChargingSchedule.Duration = 86400;
  1176. }
  1177. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1178. {
  1179. 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")));
  1180. }
  1181. else
  1182. {
  1183. 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));
  1184. }
  1185. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1186. {
  1187. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1188. }
  1189. else
  1190. {
  1191. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1192. }
  1193. }
  1194. }
  1195. }
  1196. json_object_put(obj);
  1197. }
  1198. fclose(fp);
  1199. /*
  1200. if(maxProfile.ChargingProfileId !=-1)
  1201. {
  1202. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1203. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1204. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1205. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1206. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1207. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1208. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1209. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1210. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1211. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1212. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1213. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1214. {
  1215. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1216. {
  1217. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1218. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1219. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1220. }
  1221. }
  1222. }
  1223. else
  1224. DEBUG_INFO("MaxProfile not found.\n");
  1225. DEBUG_INFO("------------------------------------\n");*/
  1226. }
  1227. /*
  1228. * Align found profile start schedule & periods
  1229. */
  1230. //DEBUG_INFO("====================================\n");
  1231. /*
  1232. // For local test usage, force modify found profile start schedule info
  1233. 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);
  1234. 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);
  1235. 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);
  1236. */
  1237. if(txProfile.ChargingProfileId != -1)
  1238. {
  1239. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1240. {
  1241. if(txProfile.ChargingSchedule.Duration != -1)
  1242. {
  1243. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1244. 0:
  1245. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1246. }
  1247. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1248. {
  1249. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1250. {
  1251. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1252. 0:
  1253. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1254. if(idxPeriod > 0)
  1255. {
  1256. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1257. {
  1258. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1259. }
  1260. }
  1261. }
  1262. }
  1263. }
  1264. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1265. {
  1266. if(txProfile.ChargingSchedule.Duration != -1)
  1267. {
  1268. 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?
  1269. 0:
  1270. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1271. }
  1272. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1273. {
  1274. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1275. {
  1276. 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?
  1277. 0:
  1278. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1279. if(idxPeriod > 0)
  1280. {
  1281. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1282. {
  1283. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1284. }
  1285. }
  1286. }
  1287. }
  1288. }
  1289. else
  1290. {
  1291. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1292. {
  1293. if(txProfile.ChargingSchedule.Duration != -1)
  1294. {
  1295. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1296. 0:
  1297. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1298. }
  1299. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1300. {
  1301. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1302. {
  1303. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1304. 0:
  1305. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1306. if(idxPeriod > 0)
  1307. {
  1308. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1309. {
  1310. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1311. }
  1312. }
  1313. }
  1314. }
  1315. }
  1316. else
  1317. {
  1318. if(txProfile.ChargingSchedule.Duration != -1)
  1319. {
  1320. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1321. 0:
  1322. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1323. }
  1324. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1325. {
  1326. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1327. {
  1328. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1329. 0:
  1330. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1331. if(idxPeriod > 0)
  1332. {
  1333. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1334. {
  1335. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1336. }
  1337. }
  1338. }
  1339. }
  1340. }
  1341. }
  1342. /*
  1343. DEBUG_INFO("txProfile after align.\n");
  1344. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1345. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1346. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1347. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1348. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1349. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1350. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1351. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1352. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1353. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1354. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1355. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1356. {
  1357. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1358. {
  1359. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1360. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1361. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1362. }
  1363. }*/
  1364. }
  1365. if(defaultTxProfile.ChargingProfileId != -1)
  1366. {
  1367. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1368. {
  1369. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1370. {
  1371. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1372. 0:
  1373. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1374. }
  1375. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1376. {
  1377. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1378. {
  1379. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1380. 0:
  1381. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1382. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1383. {
  1384. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1385. }
  1386. if(idxPeriod > 0)
  1387. {
  1388. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1389. {
  1390. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1391. }
  1392. }
  1393. }
  1394. }
  1395. }
  1396. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1397. {
  1398. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1399. {
  1400. 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?
  1401. 0:
  1402. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1403. }
  1404. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1405. {
  1406. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1407. {
  1408. 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?
  1409. 0:
  1410. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1411. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1412. {
  1413. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1414. }
  1415. if(idxPeriod > 0)
  1416. {
  1417. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1418. {
  1419. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1420. }
  1421. }
  1422. }
  1423. }
  1424. }
  1425. else
  1426. {
  1427. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1428. {
  1429. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1430. {
  1431. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1432. 0:
  1433. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1434. }
  1435. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1436. {
  1437. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1438. {
  1439. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1440. 0:
  1441. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1442. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1443. {
  1444. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1445. }
  1446. if(idxPeriod > 0)
  1447. {
  1448. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1449. {
  1450. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1451. }
  1452. }
  1453. }
  1454. }
  1455. }
  1456. else
  1457. {
  1458. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1459. {
  1460. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1461. 0:
  1462. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1463. }
  1464. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1465. {
  1466. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1467. {
  1468. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1469. 0:
  1470. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1471. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1472. {
  1473. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1474. }
  1475. if(idxPeriod > 0)
  1476. {
  1477. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1478. {
  1479. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1480. }
  1481. }
  1482. }
  1483. }
  1484. }
  1485. }
  1486. /*
  1487. DEBUG_INFO("defaultTxProfile after align.\n");
  1488. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1489. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1490. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1491. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1492. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1493. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1494. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1495. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1496. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1497. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1498. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1499. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1500. {
  1501. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1502. {
  1503. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1504. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1505. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1506. }
  1507. }
  1508. DEBUG_INFO("------------------------------------\n");*/
  1509. }
  1510. if(maxProfile.ChargingProfileId != -1)
  1511. {
  1512. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1513. {
  1514. if(maxProfile.ChargingSchedule.Duration != -1)
  1515. {
  1516. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1517. 0:
  1518. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1519. }
  1520. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1521. {
  1522. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1523. {
  1524. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1525. 0:
  1526. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1527. if(idxPeriod > 0)
  1528. {
  1529. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1530. {
  1531. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1532. }
  1533. }
  1534. }
  1535. }
  1536. }
  1537. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1538. {
  1539. if(maxProfile.ChargingSchedule.Duration != -1)
  1540. {
  1541. 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?
  1542. 0:
  1543. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1544. }
  1545. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1546. {
  1547. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1548. {
  1549. 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?
  1550. 0:
  1551. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1552. if(idxPeriod > 0)
  1553. {
  1554. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1555. {
  1556. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1557. }
  1558. }
  1559. }
  1560. }
  1561. }
  1562. else
  1563. {
  1564. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1565. {
  1566. if(maxProfile.ChargingSchedule.Duration != -1)
  1567. {
  1568. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1569. 0:
  1570. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1571. }
  1572. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1573. {
  1574. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1575. {
  1576. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1577. 0:
  1578. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1579. if(idxPeriod > 0)
  1580. {
  1581. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1582. {
  1583. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1584. }
  1585. }
  1586. }
  1587. }
  1588. }
  1589. else
  1590. {
  1591. if(maxProfile.ChargingSchedule.Duration != -1)
  1592. {
  1593. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1594. 0:
  1595. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1596. }
  1597. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1598. {
  1599. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1600. {
  1601. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1602. 0:
  1603. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1604. if(idxPeriod > 0)
  1605. {
  1606. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1607. {
  1608. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1609. }
  1610. }
  1611. }
  1612. }
  1613. }
  1614. }
  1615. /*
  1616. DEBUG_INFO("MaxProfile after align.\n");
  1617. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1618. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1619. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1620. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1621. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1622. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1623. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1624. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1625. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1626. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1627. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1628. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1629. {
  1630. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1631. {
  1632. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1633. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1634. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1635. }
  1636. }
  1637. DEBUG_INFO("------------------------------------\n");*/
  1638. }
  1639. /*
  1640. * Merge to conposite schedule
  1641. */
  1642. //DEBUG_INFO("====================================\n");
  1643. // Find each profile period quantity
  1644. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1645. {
  1646. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1647. limitMax = idx+1;
  1648. }
  1649. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1650. {
  1651. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1652. limitDef = idx+1;
  1653. }
  1654. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1655. {
  1656. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1657. limitTx = idx+1;
  1658. }
  1659. // TxProfile found, composite schedule based on it
  1660. if(txProfile.ChargingProfileId != -1)
  1661. {
  1662. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1663. {
  1664. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1665. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  1666. (txProfile.ChargingSchedule.Duration > 0))
  1667. {
  1668. if(maxProfile.ChargingProfileId != -1)
  1669. {
  1670. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1671. {
  1672. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  1673. {
  1674. if((maxProfile.ChargingSchedule.Duration > 0))
  1675. {
  1676. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1677. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1678. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1679. }
  1680. else
  1681. {
  1682. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1683. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1684. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  1685. }
  1686. }
  1687. if(idxMaxPeriod == (limitMax-1))
  1688. {
  1689. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1690. {
  1691. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1692. {
  1693. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1694. compositePeriodIdx++;
  1695. }
  1696. else
  1697. {
  1698. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1699. }
  1700. }
  1701. }
  1702. }
  1703. }
  1704. else
  1705. {
  1706. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1707. {
  1708. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1709. compositePeriodIdx++;
  1710. }
  1711. else
  1712. {
  1713. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1714. }
  1715. }
  1716. }
  1717. if(idxTxPeriod == (limitTx-1))
  1718. {
  1719. if(defaultTxProfile.ChargingProfileId != -1)
  1720. {
  1721. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1722. {
  1723. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  1724. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1725. (defaultTxProfile.ChargingSchedule.Duration>0))
  1726. {
  1727. if(maxProfile.ChargingProfileId != -1)
  1728. {
  1729. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1730. {
  1731. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1732. {
  1733. if((maxProfile.ChargingSchedule.Duration > 0))
  1734. {
  1735. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1736. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1737. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1738. }
  1739. else
  1740. {
  1741. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1742. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1743. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1744. }
  1745. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1746. {
  1747. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1748. {
  1749. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1750. compositePeriodIdx++;
  1751. }
  1752. else
  1753. {
  1754. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1755. }
  1756. }
  1757. break;
  1758. }
  1759. }
  1760. }
  1761. else
  1762. {
  1763. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1764. {
  1765. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1766. compositePeriodIdx++;
  1767. }
  1768. else
  1769. {
  1770. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1771. }
  1772. }
  1773. }
  1774. }
  1775. }
  1776. }
  1777. }
  1778. }
  1779. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1780. else if(defaultTxProfile.ChargingProfileId != -1)
  1781. {
  1782. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1783. {
  1784. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1785. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1786. (defaultTxProfile.ChargingSchedule.Duration > 0))
  1787. {
  1788. if(maxProfile.ChargingProfileId != -1)
  1789. {
  1790. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1791. {
  1792. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1793. {
  1794. if((maxProfile.ChargingSchedule.Duration > 0))
  1795. {
  1796. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1797. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1798. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1799. }
  1800. else
  1801. {
  1802. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1803. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1804. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1805. }
  1806. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1807. {
  1808. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1809. {
  1810. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1811. compositePeriodIdx++;
  1812. }
  1813. else
  1814. {
  1815. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1816. }
  1817. }
  1818. break;
  1819. }
  1820. }
  1821. }
  1822. else
  1823. {
  1824. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1825. {
  1826. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1827. compositePeriodIdx++;
  1828. }
  1829. else
  1830. {
  1831. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1832. }
  1833. }
  1834. }
  1835. }
  1836. }
  1837. // Fill other period by MaxProfile
  1838. if(maxProfile.ChargingProfileId != -1)
  1839. {
  1840. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1841. {
  1842. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1843. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1844. (maxProfile.ChargingSchedule.Duration > 0))
  1845. {
  1846. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  1847. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1848. {
  1849. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  1850. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  1851. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1852. }
  1853. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1854. {
  1855. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  1856. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  1857. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1858. }
  1859. if(tmpPeriod.Limit != -1)
  1860. {
  1861. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1862. {
  1863. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1864. {
  1865. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1866. compositePeriodIdx++;
  1867. }
  1868. else
  1869. {
  1870. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1871. }
  1872. }
  1873. }
  1874. }
  1875. }
  1876. }
  1877. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  1878. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1879. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1880. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1881. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1882. {
  1883. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1884. {
  1885. compositeProfile->ChargingProfileId = 1;
  1886. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1887. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1888. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1889. }
  1890. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1891. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1892. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1893. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1894. }
  1895. if(line)
  1896. free(line);
  1897. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  1898. }
  1899. //==========================================
  1900. // Init all share memory
  1901. //==========================================
  1902. int InitShareMemory()
  1903. {
  1904. int result = PASS;
  1905. int MeterSMId;
  1906. //creat ShmSysConfigAndInfo
  1907. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1908. {
  1909. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1910. result = FAIL;
  1911. }
  1912. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1913. {
  1914. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  1915. result = FAIL;
  1916. }
  1917. else
  1918. {}
  1919. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1920. {
  1921. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1922. result = FAIL;
  1923. }
  1924. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1925. {
  1926. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1927. result = FAIL;
  1928. }
  1929. else
  1930. {}
  1931. //creat ShmPsuData
  1932. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  1933. {
  1934. DEBUG_ERROR("shmget ShmPsuData NG\n");
  1935. result = FAIL;
  1936. }
  1937. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1938. {
  1939. DEBUG_ERROR("shmat ShmPsuData NG\n");
  1940. result = FAIL;
  1941. }
  1942. else
  1943. {}
  1944. //creat ShmOCPP16Data
  1945. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1946. {
  1947. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  1948. result = FAIL;
  1949. }
  1950. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1951. {
  1952. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  1953. result = FAIL;
  1954. }
  1955. else
  1956. {}
  1957. /****************************** For Initial Settings************************************************/
  1958. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  1959. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  1960. // allocate Configuration memory address
  1961. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  1962. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  1963. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  1964. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  1965. //offline MeterValue Interval
  1966. TempMeterValueInterval = 0;
  1967. return result;
  1968. }
  1969. int ProcessShareMemory()
  1970. {
  1971. if(InitShareMemory() == FAIL)
  1972. {
  1973. DEBUG_ERROR("InitShareMemory NG\n");
  1974. if(ShmStatusCodeData!=NULL)
  1975. {
  1976. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1977. }
  1978. sleep(5);
  1979. return FAIL;
  1980. }
  1981. return PASS;
  1982. }
  1983. //---------------------common routine---------------------------//
  1984. int isOFFline(void)
  1985. {
  1986. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  1987. {
  1988. if(TempMeterValueInterval >= 2 )
  1989. {
  1990. TempMeterValueInterval = 0;
  1991. return TRUE;
  1992. }
  1993. else
  1994. {
  1995. TempMeterValueInterval = TempMeterValueInterval+ 1;
  1996. return FALSE;
  1997. }
  1998. }
  1999. else
  2000. {
  2001. return FALSE;
  2002. }
  2003. }
  2004. //---------------------------------------------
  2005. // new:
  2006. // enum SYSTEM_STATUS
  2007. // {
  2008. // SYS_MODE_BOOTING = 0,
  2009. // SYS_MODE_IDLE = 1,
  2010. // SYS_MODE_AUTHORIZING = 2,
  2011. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  2012. // SYS_MODE_REASSIGN = 4,
  2013. // SYS_MODE_PREPARING = 5,
  2014. // SYS_MODE_PREPARE_FOR_EV = 6,
  2015. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  2016. // SYS_MODE_CHARGING = 8,
  2017. // SYS_MODE_TERMINATING = 9,
  2018. // SYS_MODE_COMPLETE = 10,
  2019. // SYS_MODE_ALARM = 11,
  2020. // SYS_MODE_FAULT = 12,
  2021. // SYS_MODE_RESERVATION = 13,
  2022. // SYS_MODE_BOOKING = 14,
  2023. // SYS_MODE_MAINTAIN = 15,
  2024. // SYS_MODE_DEBUG = 16,
  2025. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  2026. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  2027. // SYS_MODE_UPDATE = 19
  2028. // };
  2029. //
  2030. //
  2031. //-----------------------------------------
  2032. void CheckSystemValue(void)
  2033. {
  2034. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2035. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2036. char filenmae[100]={0};
  2037. char str[100]={0};
  2038. int tempIndex = 0;
  2039. //===============================
  2040. // send Heartbeat
  2041. //===============================
  2042. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2043. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2044. {
  2045. clientTime.Heartbeat=time((time_t*)NULL);
  2046. if(server_sign == TRUE)
  2047. {
  2048. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2049. }
  2050. else
  2051. {
  2052. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2053. }
  2054. }
  2055. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2056. {
  2057. //parameter for test
  2058. sendHeartbeatRequest(0);
  2059. //==============================================
  2060. // Reset Waiting Time
  2061. //==============================================
  2062. HeartBeatWithNOResponse += 1;
  2063. }
  2064. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2065. {
  2066. //===============================
  2067. // CSU Trigger Reset Conf
  2068. //===============================
  2069. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2070. {
  2071. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2072. }
  2073. //===============================
  2074. // CSU Trigger Authorize Request
  2075. //===============================
  2076. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2077. {
  2078. sendAuthorizeRequest(0);
  2079. authorizeRetryTimes = authorizeRetryTimes + 1;
  2080. if(authorizeRetryTimes < 3)
  2081. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2082. }
  2083. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2084. {
  2085. authorizeRetryTimes = 0;
  2086. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  2087. server_sign = FALSE;
  2088. }
  2089. 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))
  2090. {
  2091. sendAuthorizeRequest(0);
  2092. }
  2093. //===============================
  2094. // CSU Trigger Smart Charging Profilw
  2095. //===============================
  2096. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2097. {
  2098. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  2099. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2100. }
  2101. //==============================================
  2102. // Charger start transaction
  2103. //==============================================
  2104. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2105. {
  2106. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2107. sendStartTransactionRequest(gun_index);
  2108. clientTime.StartTransaction = time((time_t*)NULL);
  2109. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2110. }
  2111. //==============================================
  2112. // Charger stop transaction
  2113. //==============================================
  2114. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2115. {
  2116. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2117. sendStopTransactionRequest(gun_index);
  2118. clientTime.StopTransaction = time((time_t*)NULL);
  2119. }
  2120. //==============================================
  2121. // Charger status report
  2122. //==============================================
  2123. //--- Check Mode Change ---//
  2124. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2125. if(gunType[gun_index] == 'J')
  2126. {
  2127. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2128. {
  2129. tempIndex = ((gun_index==2) ? 1: 0);
  2130. }
  2131. else
  2132. {
  2133. tempIndex = gun_index;
  2134. }
  2135. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2136. {
  2137. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2138. {
  2139. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2140. {
  2141. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2142. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2143. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2144. statusModeChage[gun_index] = TRUE;
  2145. }
  2146. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2147. {
  2148. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2149. if((access(filenmae,F_OK))!=-1)
  2150. {
  2151. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2152. sprintf(str,"rm -f %s",filenmae);
  2153. system(str);
  2154. }
  2155. }
  2156. #if 1 // for TempStopTransaction
  2157. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2158. {
  2159. checkTempStopTransaction(gun_index);
  2160. }
  2161. #endif
  2162. }
  2163. }
  2164. }
  2165. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2166. {
  2167. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2168. {
  2169. tempIndex = ((gun_index==2) ? 1: 0);
  2170. }
  2171. else
  2172. {
  2173. tempIndex = gun_index;
  2174. }
  2175. for (int index = 0; index < CCS_QUANTITY; index++)
  2176. {
  2177. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2178. {
  2179. 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]*/ )
  2180. {
  2181. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2182. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2183. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2184. statusModeChage[gun_index] = TRUE;
  2185. }
  2186. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2187. {
  2188. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2189. if((access(filenmae,F_OK))!=-1)
  2190. {
  2191. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2192. sprintf(str,"rm -f %s",filenmae);
  2193. system(str);
  2194. }
  2195. }
  2196. #if 1 // for TempStopTransaction
  2197. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2198. {
  2199. checkTempStopTransaction(gun_index);
  2200. }
  2201. #endif
  2202. }
  2203. }
  2204. }
  2205. else if(gunType[gun_index] == 'G')
  2206. {
  2207. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2208. {
  2209. tempIndex = ((gun_index==2) ? 1: 0);
  2210. }
  2211. else
  2212. {
  2213. tempIndex = gun_index;
  2214. }
  2215. for (int index = 0; index < GB_QUANTITY; index++)
  2216. {
  2217. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2218. {
  2219. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2220. {
  2221. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2222. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2223. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2224. statusModeChage[gun_index] = TRUE;
  2225. }
  2226. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2227. {
  2228. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2229. if((access(filenmae,F_OK))!=-1)
  2230. {
  2231. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2232. sprintf(str,"rm -f %s",filenmae);
  2233. system(str);
  2234. }
  2235. }
  2236. #if 1 // for TempStopTransaction
  2237. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2238. {
  2239. checkTempStopTransaction(gun_index);
  2240. }
  2241. #endif
  2242. }
  2243. }
  2244. }
  2245. else if(gunType[gun_index] == 'O')
  2246. {
  2247. tempIndex = gun_index;
  2248. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2249. {
  2250. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2251. {
  2252. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2253. {
  2254. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2255. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2256. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2257. statusModeChage[gun_index] = TRUE;
  2258. }
  2259. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // complete
  2260. {
  2261. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2262. if((access(filenmae,F_OK))!=-1)
  2263. {
  2264. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2265. sprintf(str,"rm -f %s",filenmae);
  2266. system(str);
  2267. }
  2268. }
  2269. #if 1 // for TempStopTransaction
  2270. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2271. {
  2272. checkTempStopTransaction(gun_index);
  2273. }
  2274. #endif
  2275. }
  2276. }
  2277. }
  2278. else
  2279. {
  2280. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2281. {
  2282. tempIndex = 2;
  2283. }
  2284. else
  2285. {
  2286. tempIndex = gun_index;
  2287. }
  2288. for (int index = 0; index < AC_QUANTITY; index++)
  2289. {
  2290. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2291. {
  2292. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2293. {
  2294. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2295. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2296. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2297. statusModeChage[gun_index] = TRUE;
  2298. }
  2299. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2300. {
  2301. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2302. if((access(filenmae,F_OK))!=-1)
  2303. {
  2304. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2305. sprintf(str,"rm -f %s",filenmae);
  2306. system(str);
  2307. }
  2308. }
  2309. #if 1 // for TempStopTransaction
  2310. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2311. {
  2312. checkTempStopTransaction(gun_index);
  2313. }
  2314. #endif
  2315. }
  2316. }// END
  2317. }
  2318. if(isWebsocketSendable &&
  2319. (((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)))) )
  2320. {
  2321. if(SystemInitial > 0)
  2322. SystemInitial -= 1;
  2323. sendStatusNotificationRequest(gun_index);
  2324. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2325. statusModeChage[gun_index] = FALSE;
  2326. }
  2327. //==============================================
  2328. // Meter report
  2329. //==============================================
  2330. // Trigger MeterValue
  2331. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2332. {
  2333. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2334. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2335. }
  2336. // ClockAlign MeterValue
  2337. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  2338. {
  2339. if(gunType[gun_index] == 'J')
  2340. {
  2341. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2342. {
  2343. tempIndex = ((gun_index==2) ? 1: 0);
  2344. }
  2345. else
  2346. {
  2347. tempIndex = gun_index;
  2348. }
  2349. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2350. {
  2351. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2352. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2353. {
  2354. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2355. {
  2356. reqClockAlignMeter[gun_index] = 1;
  2357. }
  2358. }
  2359. }// End for CHAdeMO
  2360. }
  2361. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2362. {
  2363. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2364. {
  2365. tempIndex = ((gun_index==2) ? 1: 0);
  2366. }
  2367. else
  2368. {
  2369. tempIndex = gun_index;
  2370. }
  2371. for (int index = 0; index < CCS_QUANTITY; index++)
  2372. {
  2373. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2374. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2375. {
  2376. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2377. {
  2378. reqClockAlignMeter[gun_index] = 1;
  2379. }
  2380. }
  2381. } // End for CCS
  2382. }
  2383. else if(gunType[gun_index] == 'G')
  2384. {
  2385. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2386. {
  2387. tempIndex = ((gun_index==2) ? 1: 0);
  2388. }
  2389. else
  2390. {
  2391. tempIndex = gun_index;
  2392. }
  2393. for (int index = 0; index < GB_QUANTITY; index++)
  2394. {
  2395. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2396. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2397. {
  2398. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2399. {
  2400. reqClockAlignMeter[gun_index] = 1;
  2401. }
  2402. }
  2403. }// End for GB
  2404. }
  2405. else if(gunType[gun_index] == 'O')
  2406. {
  2407. tempIndex = gun_index;
  2408. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2409. {
  2410. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2411. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2412. {
  2413. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_CHARGING)
  2414. {
  2415. reqClockAlignMeter[gun_index] = 1;
  2416. }
  2417. }
  2418. }
  2419. }
  2420. else
  2421. {
  2422. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2423. {
  2424. tempIndex = 2;
  2425. }
  2426. else
  2427. {
  2428. tempIndex = gun_index;
  2429. }
  2430. for (int index = 0; index < AC_QUANTITY; index++)
  2431. {
  2432. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2433. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2434. {
  2435. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2436. {
  2437. reqClockAlignMeter[gun_index] = 1;
  2438. }
  2439. }
  2440. }//End for AC
  2441. }
  2442. if(reqClockAlignMeter[gun_index] == 1)
  2443. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2444. }
  2445. // Sample period MeterValue
  2446. if(/*(server_sign == TRUE) &&(isOFFline() == TRUE) ||*/
  2447. (((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1))))
  2448. {
  2449. //check Transaction active
  2450. if(gunType[gun_index] == 'J')
  2451. {
  2452. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2453. {
  2454. tempIndex = ((gun_index==2) ? 1: 0);
  2455. }
  2456. else
  2457. {
  2458. tempIndex = gun_index;
  2459. }
  2460. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2461. {
  2462. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2463. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2464. {
  2465. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2466. {
  2467. reqSampleMeter[gun_index] = 1;
  2468. }
  2469. }
  2470. }// End for CHAdeMO
  2471. }
  2472. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2473. {
  2474. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2475. {
  2476. tempIndex = ((gun_index==2) ? 1: 0);
  2477. }
  2478. else
  2479. {
  2480. tempIndex = gun_index;
  2481. }
  2482. for (int index = 0; index < CCS_QUANTITY; index++)
  2483. {
  2484. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2485. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2486. {
  2487. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2488. {
  2489. reqSampleMeter[gun_index] = 1;
  2490. }
  2491. }
  2492. } // End for CCS
  2493. }
  2494. else if(gunType[gun_index] == 'G')
  2495. {
  2496. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2497. {
  2498. tempIndex = ((gun_index==2) ? 1: 0);
  2499. }
  2500. else
  2501. {
  2502. tempIndex = gun_index;
  2503. }
  2504. for (int index = 0; index < GB_QUANTITY; index++)
  2505. {
  2506. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2507. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2508. {
  2509. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2510. {
  2511. reqSampleMeter[gun_index] = 1;
  2512. }
  2513. }
  2514. }// End for GB
  2515. }
  2516. else if(gunType[gun_index] == 'O')
  2517. {
  2518. tempIndex = gun_index;
  2519. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2520. {
  2521. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2522. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2523. {
  2524. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  2525. {
  2526. reqSampleMeter[gun_index] = 1;
  2527. }
  2528. }
  2529. }
  2530. }
  2531. else
  2532. {
  2533. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2534. {
  2535. tempIndex = 2;
  2536. }
  2537. else
  2538. {
  2539. tempIndex = gun_index;
  2540. }
  2541. for (int index = 0; index < AC_QUANTITY; index++)
  2542. {
  2543. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2544. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2545. {
  2546. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2547. {
  2548. reqSampleMeter[gun_index] = 1;
  2549. }
  2550. }
  2551. }//End for AC
  2552. }
  2553. if(reqSampleMeter[gun_index] == 1)
  2554. {
  2555. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2556. storeTempStopTransaction(gun_index);
  2557. }
  2558. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2559. }
  2560. //==============================================
  2561. // Check Connector reserved
  2562. //==============================================
  2563. //===============================
  2564. // Check if Reserve is expired
  2565. //===============================
  2566. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2567. {
  2568. double diff_t;
  2569. struct tm tp;
  2570. // current time
  2571. time_t t = time(NULL);
  2572. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2573. tp.tm_isdst = -1;
  2574. time_t utc = mktime(&tp);
  2575. diff_t = difftime(utc, t);
  2576. if(diff_t <= 0)
  2577. {
  2578. DEBUG_INFO("reserve expired.\n");
  2579. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2580. }
  2581. }//END OF Check if Reserve is expired
  2582. //==========================================
  2583. // csu trigger FirmwareStatusNotificationReq
  2584. //==========================================
  2585. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2586. {
  2587. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2588. }
  2589. //==========================================
  2590. // csu trigger CancelReservationConf
  2591. //==========================================
  2592. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2593. {
  2594. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2595. }
  2596. //==========================================
  2597. // csu trigger ChangeAvailabilityConf
  2598. //==========================================
  2599. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2600. {
  2601. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2602. }
  2603. //==========================================
  2604. // csu trigger UnlockConnectorConf
  2605. //==========================================
  2606. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2607. {
  2608. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2609. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2610. }
  2611. //==========================================
  2612. // csu trigger ReserveNowConf
  2613. //==========================================
  2614. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2615. {
  2616. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2617. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2618. }
  2619. //==========================================
  2620. // csu trigger DataTransferReq
  2621. //==========================================
  2622. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2623. {
  2624. sendDataTransferRequest(gun_index);
  2625. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2626. }
  2627. }
  2628. }
  2629. //==========================================
  2630. // send request routine
  2631. //==========================================
  2632. int sendAuthorizeRequest(int gun_index)
  2633. {
  2634. mtrace();
  2635. int result = FAIL;
  2636. char message[100]={0};
  2637. char guid[37];
  2638. char tempdata[65]={0};
  2639. DEBUG_INFO("sendAuthorizeRequest...\n");
  2640. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2641. //Local Authorize
  2642. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2643. {
  2644. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2645. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2646. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2647. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2648. result = PASS;
  2649. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2650. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2651. authorizeRetryTimes = 0;
  2652. return result;
  2653. }
  2654. 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))||
  2655. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2656. {
  2657. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2658. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2659. {
  2660. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2661. {
  2662. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2663. }
  2664. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2665. {
  2666. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2667. }
  2668. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  2669. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2670. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2671. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2672. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2673. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2674. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2675. authorizeRetryTimes = 0;
  2676. return result;
  2677. }
  2678. else
  2679. {
  2680. DEBUG_INFO("offline Local Authorization get result !!!!\n");
  2681. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2682. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2683. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  2684. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  2685. else
  2686. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2687. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2688. result = PASS;
  2689. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2690. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2691. authorizeRetryTimes = 0;
  2692. return result;
  2693. }
  2694. }
  2695. //initailize struct Authorize
  2696. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2697. //get data from shared memory
  2698. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2699. random_uuid(guid);
  2700. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2701. LWS_Send(message);
  2702. sprintf(tempdata, "Authorize,%d", gun_index);
  2703. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2704. {
  2705. result = PASS;
  2706. DEBUG_INFO("Authorize mapItem pass\n");
  2707. }
  2708. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2709. return result;
  2710. }
  2711. int sendBootNotificationRequest(void)
  2712. {
  2713. mtrace();
  2714. int result = FAIL;
  2715. char message[500]={0}, payload[700]={0};
  2716. char guid[37]={0};
  2717. char tempdata[65]={0};
  2718. /*
  2719. int IsGunCharging = FALSE;
  2720. //check Transaction active
  2721. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2722. {
  2723. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2724. {
  2725. IsGunCharging = TRUE;
  2726. }
  2727. }
  2728. for (int index = 0; index < CCS_QUANTITY; index++)
  2729. {
  2730. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2731. {
  2732. IsGunCharging = TRUE;
  2733. }
  2734. }
  2735. for (int index = 0; index < GB_QUANTITY; index++)
  2736. {
  2737. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2738. {
  2739. IsGunCharging = TRUE;
  2740. }
  2741. }
  2742. for (int index = 0; index < AC_QUANTITY; index++)
  2743. {
  2744. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2745. {
  2746. IsGunCharging = TRUE;
  2747. }
  2748. }
  2749. if(IsGunCharging == TRUE)
  2750. {
  2751. server_sign = TRUE;
  2752. return result;
  2753. }
  2754. */
  2755. // Fill BootNotification fields
  2756. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2757. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2758. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2759. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2760. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2761. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2762. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2763. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2764. ShmOCPP16Data->ChargeBoxId
  2765. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2766. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2767. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2768. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2769. ,ShmOCPP16Data->BootNotification.CpIccid
  2770. ,ShmOCPP16Data->BootNotification.CpImsi);
  2771. random_uuid(guid);
  2772. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2773. LWS_Send(message);
  2774. sprintf(tempdata, "BootNotification,0");
  2775. 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*/)
  2776. {
  2777. result = PASS;
  2778. }
  2779. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2780. strcpy(queuedata,message);
  2781. return result;
  2782. }
  2783. int sendDataTransferRequest(int gun_index)
  2784. {
  2785. mtrace();
  2786. char message[1000]={0};
  2787. char guid[37]={0};
  2788. char tempdata[65]={0};
  2789. int result = FAIL;
  2790. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2791. random_uuid(guid);
  2792. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2793. MESSAGE_TYPE_CALL,
  2794. guid,
  2795. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2796. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2797. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2798. LWS_Send(message);
  2799. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2800. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2801. {
  2802. result = PASS;
  2803. DEBUG_INFO("DataTransfer mapItem pass\n");
  2804. }
  2805. return result;
  2806. }
  2807. int sendDiagnosticsStatusNotificationRequest(char *status)
  2808. {
  2809. mtrace();
  2810. int result = FAIL;
  2811. char message[110]={0};
  2812. char guid[37]={0};
  2813. char tempdata[65]={0};
  2814. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2815. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2816. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2817. random_uuid(guid);
  2818. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2819. LWS_SendNow(message);
  2820. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2821. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2822. {
  2823. result = PASS;
  2824. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2825. }
  2826. //#ifdef SystemLogMessage
  2827. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2828. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2829. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2830. //#endif
  2831. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2832. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2833. //record status
  2834. if(strcmp(status,"Idle")==0)
  2835. {
  2836. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2837. }
  2838. else if(strcmp(status,"Uploaded")==0)
  2839. {
  2840. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2841. }
  2842. else if(strcmp(status,"UploadFailed")==0)
  2843. {
  2844. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2845. }
  2846. else if(strcmp(status,"Uploading")==0)
  2847. {
  2848. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2849. }
  2850. return result;
  2851. }
  2852. int sendFirmwareStatusNotificationRequest(char *status)
  2853. {
  2854. mtrace();
  2855. int result = FAIL;
  2856. char message[110]={0};
  2857. char guid[37]={0};
  2858. char tempdata[65]={0};
  2859. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2860. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2861. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2862. random_uuid(guid);
  2863. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2864. LWS_SendNow(message);
  2865. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2866. 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*/)
  2867. {
  2868. result = PASS;
  2869. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2870. }
  2871. //#ifdef SystemLogMessage
  2872. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2873. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2874. //#endif
  2875. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2876. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2877. //record status
  2878. if(strcmp(status,"Downloaded")==0)
  2879. {
  2880. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2881. }
  2882. else if(strcmp(status,"DownloadFailed")==0)
  2883. {
  2884. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  2885. }
  2886. else if(strcmp(status,"Downloading")==0)
  2887. {
  2888. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2889. }
  2890. else if(strcmp(status,"Idle")==0)
  2891. {
  2892. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2893. }
  2894. else if(strcmp(status,"InstallationFailed")==0)
  2895. {
  2896. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2897. }
  2898. else if(strcmp(status,"Installing")==0)
  2899. {
  2900. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2901. }
  2902. else if(strcmp(status,"Installed")==0)
  2903. {
  2904. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2905. }
  2906. return result;
  2907. }
  2908. int sendHeartbeatRequest(int gun_index)
  2909. {
  2910. mtrace();
  2911. int result = FAIL;
  2912. char message[80]={0};
  2913. char guid[37]={0};
  2914. char tempdata[65]={0};
  2915. random_uuid(guid);
  2916. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2917. , MESSAGE_TYPE_CALL
  2918. , guid );
  2919. LWS_Send(message);
  2920. sprintf(tempdata, "Heartbeat,%d", 0);
  2921. 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*/)
  2922. {
  2923. result = PASS;
  2924. }
  2925. return result;
  2926. }
  2927. int sendStartTransactionRequest(int gun_index)
  2928. {
  2929. mtrace();
  2930. int result = FAIL;
  2931. char message[250]={0};
  2932. char guid[37]={0};
  2933. struct timeval tmnow;
  2934. struct tm *tm;
  2935. char buf[28];//, usec_buf[6];
  2936. char tempdata[65]={0};
  2937. int tempIndex = 0;
  2938. DEBUG_INFO("sendStartTransactionRequest...\n");
  2939. gettimeofday(&tmnow, NULL);
  2940. time_t t;
  2941. t = time(NULL);
  2942. /*UTC time and date*/
  2943. tm = gmtime(&t);
  2944. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2945. #if 0 // remove temporally
  2946. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2947. strcat(buf,".");
  2948. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2949. strcat(buf,usec_buf);
  2950. #endif
  2951. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2952. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2953. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2954. // clear StartTransaction Response
  2955. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2956. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2957. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2958. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2959. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2960. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2961. if(gunType[gun_index] == 'J')
  2962. {
  2963. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2964. {
  2965. tempIndex = ((gun_index==2) ? 1: 0);
  2966. }
  2967. else
  2968. {
  2969. tempIndex = gun_index;
  2970. }
  2971. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2972. {
  2973. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2974. {
  2975. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  2976. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2977. }
  2978. }
  2979. }
  2980. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2981. {
  2982. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2983. {
  2984. tempIndex = ((gun_index==2) ? 1: 0);
  2985. }
  2986. else
  2987. {
  2988. tempIndex = gun_index;
  2989. }
  2990. for (int index = 0; index < CCS_QUANTITY; index++)
  2991. {
  2992. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2993. {
  2994. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  2995. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  2996. }
  2997. }
  2998. }
  2999. else if(gunType[gun_index] == 'G')
  3000. {
  3001. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3002. {
  3003. tempIndex = ((gun_index==2) ? 1: 0);
  3004. }
  3005. else
  3006. {
  3007. tempIndex = gun_index;
  3008. }
  3009. for (int index = 0; index < GB_QUANTITY; index++)
  3010. {
  3011. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3012. {
  3013. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3014. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3015. }
  3016. }
  3017. }
  3018. else if(gunType[gun_index] == 'O')
  3019. {
  3020. tempIndex = gun_index;
  3021. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3022. {
  3023. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3024. {
  3025. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3026. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3027. }
  3028. }
  3029. }
  3030. else
  3031. {
  3032. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3033. {
  3034. tempIndex = 2;
  3035. }
  3036. else
  3037. {
  3038. tempIndex = gun_index;
  3039. }
  3040. for (int index = 0; index < AC_QUANTITY; index++)
  3041. {
  3042. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3043. {
  3044. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3045. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3046. }
  3047. }
  3048. }
  3049. random_uuid(guid);
  3050. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3051. {
  3052. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3053. , gun_index +1
  3054. , MESSAGE_TYPE_CALL
  3055. , guid
  3056. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3057. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3058. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3059. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3060. }
  3061. else
  3062. {
  3063. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3064. , gun_index +1
  3065. , MESSAGE_TYPE_CALL
  3066. , guid
  3067. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3068. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3069. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3070. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3071. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3072. }
  3073. #if 1
  3074. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3075. 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*/)
  3076. {
  3077. result = PASS;
  3078. }
  3079. #endif
  3080. strcpy(queuedata, message);
  3081. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3082. return result;
  3083. }
  3084. int sendStatusNotificationRequest(int gun_index)
  3085. {
  3086. mtrace();
  3087. int result = FAIL;
  3088. char message[600]={0};
  3089. char guid[37];
  3090. int currentStatus = 0;
  3091. struct timeval tmnow;
  3092. struct tm *tm;
  3093. char buf[28];//, usec_buf[6];
  3094. char tempdata[65]={0};
  3095. int tempIndex = 0;
  3096. gettimeofday(&tmnow, NULL);
  3097. time_t t;
  3098. t = time(NULL);
  3099. /*UTC time and date*/
  3100. tm = gmtime(&t);
  3101. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3102. #if 0 // remove temporally
  3103. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3104. strcat(buf,".");
  3105. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3106. strcat(buf,usec_buf);
  3107. #endif
  3108. printf("%s",buf);
  3109. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3110. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3111. // it's option
  3112. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3113. /*
  3114. enum _SYSTEM_STATUS
  3115. {
  3116. S_BOOTING = 0,
  3117. S_IDLE, = 1
  3118. S_AUTHORIZING, =2
  3119. S_REASSIGN_CHECK, =3
  3120. S_REASSIGN, =4
  3121. S_PRECHARGE, =5
  3122. S_PREPARING_FOR_EV, =6
  3123. S_PREPARING_FOR_EVSE, =7
  3124. S_CHARGING, =8
  3125. S_TERMINATING, =9
  3126. S_COMPLETE, =10
  3127. S_ALARM, =11
  3128. S_FAULT =12
  3129. }
  3130. */
  3131. //check Transaction active
  3132. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3133. if(gunType[gun_index] == 'J')
  3134. {
  3135. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3136. {
  3137. tempIndex = ((gun_index==2) ? 1: 0);
  3138. }
  3139. else
  3140. {
  3141. tempIndex = gun_index;
  3142. }
  3143. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3144. {
  3145. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3146. {
  3147. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3148. {
  3149. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3150. {
  3151. currentStatus = 1; //OCPP Status: Preparing
  3152. }
  3153. else
  3154. {
  3155. currentStatus = 0; //OCPP Status: Available
  3156. }
  3157. }
  3158. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3159. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3160. ) //S_PRECHARGE
  3161. {
  3162. currentStatus = 1; //OCPP Status: Preparing
  3163. }
  3164. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3165. {
  3166. currentStatus = 2; //OCPP Status: Charging
  3167. }
  3168. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3169. {
  3170. currentStatus = 5; //OCPP Status: Finishing
  3171. }
  3172. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3173. {
  3174. currentStatus = 4; //OCPP Status: SuspendedEV
  3175. }
  3176. 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
  3177. {
  3178. currentStatus = 7; //OCPP Status: Unavailable
  3179. }
  3180. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3181. {
  3182. currentStatus = 8; //OCPP Status: Faulted
  3183. }
  3184. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3185. {
  3186. currentStatus = 6; //OCPP Status: Reserved
  3187. }
  3188. } //end of the same index
  3189. }//end of for CHAdeMO_QUANTITY
  3190. }
  3191. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3192. {
  3193. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3194. {
  3195. tempIndex = ((gun_index==2) ? 1: 0);
  3196. }
  3197. else
  3198. {
  3199. tempIndex = gun_index;
  3200. }
  3201. for (int index = 0; index < CCS_QUANTITY; index++)
  3202. {
  3203. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3204. {
  3205. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3206. {
  3207. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3208. {
  3209. currentStatus = 1; //OCPP Status: Preparing
  3210. }
  3211. else
  3212. {
  3213. currentStatus = 0; //OCPP Status: Available
  3214. }
  3215. }
  3216. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3217. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3218. ) //S_PRECHARGE
  3219. {
  3220. currentStatus = 1; //OCPP Status: Preparing
  3221. }
  3222. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3223. {
  3224. currentStatus = 2; //OCPP Status: Charging
  3225. }
  3226. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3227. {
  3228. currentStatus = 5; //OCPP Status: Finishing
  3229. }
  3230. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3231. {
  3232. currentStatus = 4; //OCPP Status: SuspendedEV
  3233. }
  3234. 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
  3235. {
  3236. currentStatus = 7; //OCPP Status : Unavailable
  3237. }
  3238. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3239. {
  3240. currentStatus = 8; //OCPP Status: Faulted
  3241. }
  3242. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3243. {
  3244. currentStatus = 6; //OCPP Status: Reserved
  3245. }
  3246. } //end of the same index
  3247. } // end of for CCS_QUANTITY
  3248. }
  3249. else if(gunType[gun_index] == 'G')
  3250. {
  3251. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3252. {
  3253. tempIndex = ((gun_index==2) ? 1: 0);
  3254. }
  3255. else
  3256. {
  3257. tempIndex = gun_index;
  3258. }
  3259. for (int index = 0; index < GB_QUANTITY; index++)
  3260. {
  3261. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3262. {
  3263. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3264. {
  3265. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3266. {
  3267. currentStatus = 1; //OCPP Status: Preparing
  3268. }
  3269. else
  3270. {
  3271. currentStatus = 0; //OCPP Status: Available
  3272. }
  3273. }
  3274. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3275. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3276. ) //S_PRECHARGE
  3277. {
  3278. currentStatus = 1; //OCPP Status: Preparing
  3279. }
  3280. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3281. {
  3282. currentStatus = 2; //OCPP Status: Charging
  3283. }
  3284. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3285. {
  3286. currentStatus = 5; //OCPP Status: Finishing
  3287. }
  3288. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3289. {
  3290. currentStatus = 4; //OCPP Status: SuspendedEV
  3291. }
  3292. 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
  3293. {
  3294. currentStatus = 7; //OCPP Status: Unavailable
  3295. }
  3296. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3297. {
  3298. currentStatus = 8; //OCPP Status: Faulted
  3299. }
  3300. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3301. {
  3302. currentStatus = 6; //OCPP Status: Reserved
  3303. }
  3304. } //end of the same index
  3305. } // end of for GB_QUANTITY
  3306. }
  3307. else if(gunType[gun_index] == 'O')
  3308. {
  3309. tempIndex = gun_index;
  3310. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3311. {
  3312. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3313. {
  3314. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3315. {
  3316. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3317. {
  3318. currentStatus = 1; //OCPP Status: Preparing
  3319. }
  3320. else
  3321. {
  3322. currentStatus = 0; //OCPP Status: Available
  3323. }
  3324. }
  3325. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_PREPARING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3326. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3327. ) //S_PRECHARGE
  3328. {
  3329. currentStatus = 1; //OCPP Status: Preparing
  3330. }
  3331. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3332. {
  3333. currentStatus = 2; //OCPP Status: Charging
  3334. }
  3335. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3336. {
  3337. currentStatus = 5; //OCPP Status: Finishing
  3338. }
  3339. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3340. {
  3341. currentStatus = 4; //OCPP Status: SuspendedEV
  3342. }
  3343. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3344. {
  3345. currentStatus = 7; //OCPP Status: Unavailable
  3346. }
  3347. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3348. {
  3349. currentStatus = 8; //OCPP Status: Faulted
  3350. }
  3351. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3352. {
  3353. currentStatus = 6; //OCPP Status: Reserved
  3354. }
  3355. } //end of the same index
  3356. }
  3357. }
  3358. else
  3359. {
  3360. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3361. {
  3362. tempIndex = 2;
  3363. }
  3364. else
  3365. {
  3366. tempIndex = gun_index;
  3367. }
  3368. for (int index = 0; index < AC_QUANTITY; index++)
  3369. {
  3370. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3371. {
  3372. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3373. {
  3374. 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))
  3375. {
  3376. currentStatus = 1; //OCPP Status: Preparing
  3377. }
  3378. else
  3379. {
  3380. currentStatus = 0; //OCPP Status: Available
  3381. }
  3382. }
  3383. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3384. {
  3385. currentStatus = 1; //OCPP Status: Preparing
  3386. }
  3387. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3388. {
  3389. currentStatus = 2; //OCPP Status: Charging
  3390. }
  3391. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3392. {
  3393. currentStatus = 5; //OCPP Status: Finishing
  3394. }
  3395. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3396. {
  3397. currentStatus = 4; //OCPP Status: SuspendedEV
  3398. }
  3399. 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
  3400. {
  3401. currentStatus = 7; //OCPP Status: Unavailable
  3402. }
  3403. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3404. {
  3405. currentStatus = 8; //OCPP Status: Faulted
  3406. }
  3407. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3408. {
  3409. currentStatus = 6; //OCPP Status: Reserved
  3410. }
  3411. }//end of the same index
  3412. }//end of for AC_QUANTITY
  3413. }
  3414. //it's option
  3415. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3416. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3417. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3418. random_uuid(guid);
  3419. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3420. , MESSAGE_TYPE_CALL
  3421. , guid
  3422. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3423. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3424. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3425. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3426. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3427. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3428. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3429. if((server_sign == TRUE))
  3430. {
  3431. LWS_Send(message);
  3432. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3433. 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*/)
  3434. {
  3435. //DEBUG_ERROR("statusNotification mapitem pass");
  3436. result = PASS;
  3437. }
  3438. }
  3439. else
  3440. {
  3441. result = PASS;
  3442. }
  3443. return result;
  3444. }
  3445. int sendStopTransactionRequest(int gun_index)
  3446. {
  3447. mtrace();
  3448. int result = FAIL;
  3449. //char message[1500]={0};
  3450. char guid[37]={0};
  3451. char tempdata[65]={0};
  3452. int tempIndex = 0;
  3453. char TempStopTransaction[256];
  3454. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3455. //int idx_sample=0;
  3456. DEBUG_INFO("sendStopTransactionRequest \n");
  3457. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3458. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3459. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3460. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3461. if(gunType[gun_index] == 'J')
  3462. {
  3463. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3464. {
  3465. tempIndex = ((gun_index==2) ? 1: 0);
  3466. }
  3467. else
  3468. {
  3469. tempIndex = gun_index;
  3470. }
  3471. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3472. {
  3473. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3474. {
  3475. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3476. }
  3477. }// END OF CHAdeMO_QUANTITY
  3478. }
  3479. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3480. {
  3481. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3482. {
  3483. tempIndex = ((gun_index==2) ? 1: 0);
  3484. }
  3485. else
  3486. {
  3487. tempIndex = gun_index;
  3488. }
  3489. for (int index = 0; index < CCS_QUANTITY; index++)
  3490. {
  3491. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3492. {
  3493. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3494. }
  3495. }// END OF CCS_QUANTITY
  3496. }
  3497. else if(gunType[gun_index] == 'G')
  3498. {
  3499. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3500. {
  3501. tempIndex = ((gun_index==2) ? 1: 0);
  3502. }
  3503. else
  3504. {
  3505. tempIndex = gun_index;
  3506. }
  3507. for (int index = 0; index < GB_QUANTITY; index++)
  3508. {
  3509. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3510. {
  3511. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3512. }
  3513. }// END OF GB_QUANTITY
  3514. }
  3515. else if(gunType[gun_index] == 'O')
  3516. {
  3517. tempIndex = gun_index;
  3518. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3519. {
  3520. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3521. {
  3522. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3523. }
  3524. }// END OF GB_QUANTITY
  3525. }
  3526. else
  3527. {
  3528. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3529. {
  3530. tempIndex = 2;
  3531. }
  3532. else
  3533. {
  3534. tempIndex = gun_index;
  3535. }
  3536. for (int index = 0; index < AC_QUANTITY; index++)
  3537. {
  3538. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3539. {
  3540. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3541. }
  3542. }// END OF AC_QUANTITY
  3543. }
  3544. //====================================== Stop Transaction Time =====================================================
  3545. struct timeval tmnow;
  3546. struct tm *tm;
  3547. char buf[28];//, usec_buf[6];
  3548. gettimeofday(&tmnow, NULL);
  3549. time_t t;
  3550. t = time(NULL);
  3551. /*UTC time and date*/
  3552. tm = gmtime(&t);
  3553. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3554. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3555. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3556. random_uuid(guid);
  3557. /***********************************transactionData******************************************************/
  3558. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3559. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3560. //=================================
  3561. // Transaction_Begin
  3562. //=================================
  3563. //============================================ Energy.Active.Import.Interval ================================
  3564. //idx_sample=0;
  3565. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  3566. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3567. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3568. 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*/]);
  3569. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3570. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  3571. {
  3572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3573. }
  3574. else
  3575. {
  3576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3577. }
  3578. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3579. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3580. //=================================
  3581. // Transaction_End
  3582. //=================================
  3583. // ================================= Current.Import L1 ===============================================
  3584. //idx_sample=1;
  3585. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3586. if(gunType[gun_index] == 'J')
  3587. {
  3588. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3589. {
  3590. tempIndex = ((gun_index==2) ? 1: 0);
  3591. }
  3592. else
  3593. {
  3594. tempIndex = gun_index;
  3595. }
  3596. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3597. {
  3598. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3599. {
  3600. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3601. }
  3602. }// End of for CHAdeMO_QUANTITY
  3603. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3604. }
  3605. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3606. {
  3607. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3608. {
  3609. tempIndex = ((gun_index==2) ? 1: 0);
  3610. }
  3611. else
  3612. {
  3613. tempIndex = gun_index;
  3614. }
  3615. for (int index = 0; index < CCS_QUANTITY; index++)
  3616. {
  3617. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3618. {
  3619. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3620. }
  3621. }// End of for CCS_QUANTITY
  3622. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3623. }
  3624. else if(gunType[gun_index] == 'G')
  3625. {
  3626. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3627. {
  3628. tempIndex = ((gun_index==2) ? 1: 0);
  3629. }
  3630. else
  3631. {
  3632. tempIndex = gun_index;
  3633. }
  3634. for (int index = 0; index < GB_QUANTITY; index++)
  3635. {
  3636. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3637. {
  3638. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3639. }
  3640. }// End of for GB_QUANTITY
  3641. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3642. }
  3643. else if(gunType[gun_index] == 'O')
  3644. {
  3645. tempIndex = gun_index;
  3646. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3647. {
  3648. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3649. {
  3650. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3651. }
  3652. }
  3653. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3654. }
  3655. else
  3656. {
  3657. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3658. {
  3659. tempIndex = 2;
  3660. }
  3661. else
  3662. {
  3663. tempIndex = gun_index;
  3664. }
  3665. for (int index = 0; index < AC_QUANTITY; index++)
  3666. {
  3667. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3668. {
  3669. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3670. }
  3671. }// End of for AC_QUANTITY
  3672. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3673. }
  3674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3675. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3676. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3677. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3678. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3679. // ================================= Energy.Active.Import.Interval ==============================================
  3680. //idx_sample=2;
  3681. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3682. if(gunType[gun_index] == 'J')
  3683. {
  3684. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3685. {
  3686. tempIndex = ((gun_index==2) ? 1: 0);
  3687. }
  3688. else
  3689. {
  3690. tempIndex = gun_index;
  3691. }
  3692. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3693. {
  3694. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3695. {
  3696. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3697. }
  3698. }// END OF CHAdeMO_QUANTITY
  3699. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3700. }
  3701. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3702. {
  3703. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3704. {
  3705. tempIndex = ((gun_index==2) ? 1: 0);
  3706. }
  3707. else
  3708. {
  3709. tempIndex = gun_index;
  3710. }
  3711. for (int index = 0; index < CCS_QUANTITY; index++)
  3712. {
  3713. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3714. {
  3715. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3716. }
  3717. }// END OF CCS_QUANTITY
  3718. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3719. }
  3720. else if(gunType[gun_index] == 'G')
  3721. {
  3722. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3723. {
  3724. tempIndex = ((gun_index==2) ? 1: 0);
  3725. }
  3726. else
  3727. {
  3728. tempIndex = gun_index;
  3729. }
  3730. for (int index = 0; index < GB_QUANTITY; index++)
  3731. {
  3732. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3733. {
  3734. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3735. }
  3736. }// END OF GB_QUANTITY
  3737. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3738. }
  3739. else if(gunType[gun_index] == 'O')
  3740. {
  3741. tempIndex = gun_index;
  3742. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3743. {
  3744. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3745. {
  3746. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3747. }
  3748. }
  3749. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3750. }
  3751. else
  3752. {
  3753. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3754. {
  3755. tempIndex = 2;
  3756. }
  3757. else
  3758. {
  3759. tempIndex = gun_index;
  3760. }
  3761. for (int index = 0; index < AC_QUANTITY; index++)
  3762. {
  3763. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3764. {
  3765. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3766. }
  3767. }// END OF AC_QUANTITY
  3768. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3769. }
  3770. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3771. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3772. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3773. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3774. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3775. //=================================== Power.Active.Import ==================================================
  3776. //idx_sample=3;
  3777. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3778. if(gunType[gun_index] == 'J')
  3779. {
  3780. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3781. {
  3782. tempIndex = ((gun_index==2) ? 1: 0);
  3783. }
  3784. else
  3785. {
  3786. tempIndex = gun_index;
  3787. }
  3788. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3789. {
  3790. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3791. {
  3792. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3793. }
  3794. } // End for CHAdeMO_QUANTITY
  3795. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3796. }
  3797. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3798. {
  3799. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3800. {
  3801. tempIndex = ((gun_index==2) ? 1: 0);
  3802. }
  3803. else
  3804. {
  3805. tempIndex = gun_index;
  3806. }
  3807. for (int index = 0; index < CCS_QUANTITY; index++)
  3808. {
  3809. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3810. {
  3811. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3812. }
  3813. } // END for CCS_QUANTITY
  3814. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3815. }
  3816. else if(gunType[gun_index] == 'G')
  3817. {
  3818. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3819. {
  3820. tempIndex = ((gun_index==2) ? 1: 0);
  3821. }
  3822. else
  3823. {
  3824. tempIndex = gun_index;
  3825. }
  3826. for (int index = 0; index < GB_QUANTITY; index++)
  3827. {
  3828. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3829. {
  3830. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3831. }
  3832. }// END for GB_QUANTITY
  3833. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3834. }
  3835. else if(gunType[gun_index] == 'O')
  3836. {
  3837. tempIndex = gun_index;
  3838. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3839. {
  3840. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3841. {
  3842. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3843. }
  3844. }
  3845. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3846. }
  3847. else
  3848. {
  3849. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3850. {
  3851. tempIndex = 2;
  3852. }
  3853. else
  3854. {
  3855. tempIndex = gun_index;
  3856. }
  3857. for (int index = 0; index < AC_QUANTITY; index++)
  3858. {
  3859. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3860. {
  3861. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3862. }
  3863. } // END for AC_QUANTITY
  3864. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3865. }
  3866. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3867. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3868. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3869. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3870. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3871. //============================ Voltage L1 ====================================
  3872. //idx_sample=4;
  3873. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3874. if(gunType[gun_index] == 'J')
  3875. {
  3876. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3877. {
  3878. tempIndex = ((gun_index==2) ? 1: 0);
  3879. }
  3880. else
  3881. {
  3882. tempIndex = gun_index;
  3883. }
  3884. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3885. {
  3886. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3887. {
  3888. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3889. }
  3890. } // END OF FOR CHAdeMO_QUANTITY
  3891. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3892. }
  3893. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3894. {
  3895. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3896. {
  3897. tempIndex = ((gun_index==2) ? 1: 0);
  3898. }
  3899. else
  3900. {
  3901. tempIndex = gun_index;
  3902. }
  3903. for (int index = 0; index < CCS_QUANTITY; index++)
  3904. {
  3905. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3906. {
  3907. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3908. }
  3909. } // END OF FOR CCS_QUANTITY
  3910. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3911. }
  3912. else if(gunType[gun_index] == 'G')
  3913. {
  3914. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3915. {
  3916. tempIndex = ((gun_index==2) ? 1: 0);
  3917. }
  3918. else
  3919. {
  3920. tempIndex = gun_index;
  3921. }
  3922. for (int index = 0; index < GB_QUANTITY; index++)
  3923. {
  3924. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3925. {
  3926. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3927. }
  3928. } // END OF FOR GB_QUANTITY
  3929. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3930. }
  3931. else if(gunType[gun_index] == 'O')
  3932. {
  3933. tempIndex = gun_index;
  3934. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3935. {
  3936. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3937. {
  3938. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3939. }
  3940. }
  3941. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3942. }
  3943. else
  3944. {
  3945. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3946. {
  3947. tempIndex = 2;
  3948. }
  3949. else
  3950. {
  3951. tempIndex = gun_index;
  3952. }
  3953. for (int index = 0; index < AC_QUANTITY; index++)
  3954. {
  3955. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3956. {
  3957. 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
  3958. }
  3959. } // END OF FOR AC_QUANTITY
  3960. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3961. }
  3962. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3964. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3967. //====================== End SoC ================================
  3968. //idx_sample=5;
  3969. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3970. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  3971. {
  3972. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  3973. {
  3974. tempIndex = ((gun_index==2) ? 1: 0);
  3975. }
  3976. else
  3977. {
  3978. tempIndex = gun_index;
  3979. }
  3980. if(gunType[gun_index] == 'J')
  3981. {
  3982. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3983. {
  3984. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3985. {
  3986. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3987. }
  3988. }
  3989. }
  3990. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3991. {
  3992. for (int index = 0; index < CCS_QUANTITY; index++)
  3993. {
  3994. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3995. {
  3996. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3997. }
  3998. }
  3999. }
  4000. else if(gunType[gun_index] == 'G')
  4001. {
  4002. for (int index = 0; index < GB_QUANTITY; index++)
  4003. {
  4004. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4005. {
  4006. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4007. }
  4008. }
  4009. }
  4010. else if(gunType[gun_index] == 'O')
  4011. {
  4012. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4013. {
  4014. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4015. {
  4016. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4017. }
  4018. }
  4019. }
  4020. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4021. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4022. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4023. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4026. } // END FOR DC CASE
  4027. // ================================= Current.Import L2 ===============================================
  4028. //idx_sample=6;
  4029. // AC 3 phse L2 current
  4030. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  4031. {
  4032. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4033. {
  4034. tempIndex = 2;
  4035. }
  4036. else
  4037. {
  4038. tempIndex = gun_index;
  4039. }
  4040. for (int index = 0; index < AC_QUANTITY; index++)
  4041. {
  4042. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4043. {
  4044. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4045. }
  4046. }// End of for AC_QUANTITY
  4047. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4048. }
  4049. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4050. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4051. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4052. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4053. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4054. // ================================= Current.Import L3 ===============================================
  4055. //idx_sample=7;
  4056. // AC 3 phse L3 current
  4057. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  4058. {
  4059. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4060. {
  4061. tempIndex = 2;
  4062. }
  4063. else
  4064. {
  4065. tempIndex = gun_index;
  4066. }
  4067. for (int index = 0; index < AC_QUANTITY; index++)
  4068. {
  4069. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4070. {
  4071. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4072. }
  4073. }// End of for AC_QUANTITY
  4074. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4075. }
  4076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4077. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4078. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4081. //============================ Voltage L2 ====================================
  4082. //idx_sample=8;
  4083. // AC 3 phse L2 voltage
  4084. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  4085. {
  4086. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4087. {
  4088. tempIndex = 2;
  4089. }
  4090. else
  4091. {
  4092. tempIndex = gun_index;
  4093. }
  4094. for (int index = 0; index < AC_QUANTITY; index++)
  4095. {
  4096. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4097. {
  4098. 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
  4099. }
  4100. } // END OF FOR AC_QUANTITY
  4101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4102. }
  4103. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4104. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4106. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4107. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4108. //============================ Voltage L3 ====================================
  4109. //idx_sample=8;
  4110. // AC 3 phse L3 voltage
  4111. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  4112. {
  4113. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4114. {
  4115. tempIndex = 2;
  4116. }
  4117. else
  4118. {
  4119. tempIndex = gun_index;
  4120. }
  4121. for (int index = 0; index < AC_QUANTITY; index++)
  4122. {
  4123. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4124. {
  4125. 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
  4126. }
  4127. } // END OF FOR AC_QUANTITY
  4128. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4129. }
  4130. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4131. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4133. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4135. //====================== Start SoC ================================
  4136. //idx_sample=10;
  4137. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4138. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  4139. {
  4140. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  4141. {
  4142. tempIndex = ((gun_index==2) ? 1: 0);
  4143. }
  4144. else
  4145. {
  4146. tempIndex = gun_index;
  4147. }
  4148. if(gunType[gun_index] == 'J')
  4149. {
  4150. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4151. {
  4152. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4153. {
  4154. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4155. }
  4156. }
  4157. }
  4158. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4159. {
  4160. for (int index = 0; index < CCS_QUANTITY; index++)
  4161. {
  4162. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4163. {
  4164. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4165. }
  4166. }
  4167. }
  4168. else if(gunType[gun_index] == 'G')
  4169. {
  4170. for (int index = 0; index < GB_QUANTITY; index++)
  4171. {
  4172. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4173. {
  4174. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4175. }
  4176. }
  4177. }
  4178. else if(gunType[gun_index] == 'O')
  4179. {
  4180. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4181. {
  4182. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4183. {
  4184. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4185. }
  4186. }
  4187. }
  4188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4189. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4191. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4192. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4193. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4194. } // END FOR DC CASE
  4195. //================================================ Message create ====================================================
  4196. json_object *StopTransaction = json_object_new_object();
  4197. json_object *transactionDatas = json_object_new_array();
  4198. json_object *sampledValues = json_object_new_array();
  4199. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4200. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4201. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4202. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4203. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4204. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4205. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4206. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4207. {
  4208. json_object *transactionData = json_object_new_object();
  4209. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4210. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4211. {
  4212. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4213. {
  4214. json_object *sampledValue = json_object_new_object();
  4215. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4216. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4217. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4218. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4219. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4220. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4221. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4222. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4223. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4224. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4225. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4226. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4227. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4228. json_object_array_add(sampledValues, sampledValue);
  4229. }
  4230. }
  4231. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4232. json_object_array_add(transactionDatas, transactionData);
  4233. }
  4234. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4235. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4236. ,MESSAGE_TYPE_CALL
  4237. ,guid
  4238. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4239. json_object_put(StopTransaction);
  4240. #if 1 // for TempStopTransaction
  4241. //Delete TempStopTransaction
  4242. if((access(TempStopTransaction,F_OK))!=-1)
  4243. {
  4244. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4245. }
  4246. #endif
  4247. #if 1
  4248. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4249. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4250. {
  4251. result = PASS;
  4252. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4253. }
  4254. #endif
  4255. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4256. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4257. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4258. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4259. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4260. {
  4261. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4262. }
  4263. //for test
  4264. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4265. return result;
  4266. }
  4267. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4268. {
  4269. mtrace();
  4270. int result = FAIL;
  4271. char guid[37]={0};
  4272. char tempdata[65]={0};
  4273. int tempIndex = 0;
  4274. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4275. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4276. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4277. //set value
  4278. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4279. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) ? ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId : -1);
  4280. random_uuid(guid);
  4281. //UTC Date time
  4282. struct timeval tmnow;
  4283. struct tm *tm;
  4284. char buf[28];//, usec_buf[6];
  4285. gettimeofday(&tmnow, NULL);
  4286. time_t t;
  4287. t = time(NULL);
  4288. /*UTC time and date*/
  4289. tm = gmtime(&t);
  4290. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4291. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4292. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4293. //idx_sample=0;
  4294. //********************************(1)Current.Import L1************************************************/
  4295. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4296. if(gunType[gun_index] == 'J')
  4297. {
  4298. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4299. {
  4300. tempIndex = ((gun_index==2) ? 1: 0);
  4301. }
  4302. else
  4303. {
  4304. tempIndex = gun_index;
  4305. }
  4306. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4307. {
  4308. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4309. {
  4310. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4311. }
  4312. }
  4313. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4314. }
  4315. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4316. {
  4317. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4318. {
  4319. tempIndex = ((gun_index==2) ? 1: 0);
  4320. }
  4321. else
  4322. {
  4323. tempIndex = gun_index;
  4324. }
  4325. for (int index = 0; index < CCS_QUANTITY; index++)
  4326. {
  4327. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4328. {
  4329. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4330. }
  4331. }
  4332. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4333. }
  4334. else if(gunType[gun_index] == 'G')
  4335. {
  4336. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4337. {
  4338. tempIndex = ((gun_index==2) ? 1: 0);
  4339. }
  4340. else
  4341. {
  4342. tempIndex = gun_index;
  4343. }
  4344. for (int index = 0; index < GB_QUANTITY; index++)
  4345. {
  4346. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4347. {
  4348. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4349. }
  4350. }
  4351. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4352. }
  4353. else if(gunType[gun_index] == 'O')
  4354. {
  4355. tempIndex = gun_index;
  4356. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4357. {
  4358. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4359. {
  4360. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4361. }
  4362. }
  4363. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4364. }
  4365. else
  4366. {
  4367. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4368. {
  4369. tempIndex = 2;
  4370. }
  4371. else
  4372. {
  4373. tempIndex = gun_index;
  4374. }
  4375. for (int index = 0; index < AC_QUANTITY; index++)
  4376. {
  4377. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4378. {
  4379. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4380. }
  4381. }
  4382. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4383. }
  4384. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4385. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4386. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4387. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4388. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4389. //idx_sample=1;
  4390. //********************************(2)Energy.Active.Import.Register ************************************************/
  4391. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4392. if(gunType[gun_index] == 'J')
  4393. {
  4394. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4395. {
  4396. tempIndex = ((gun_index==2) ? 1: 0);
  4397. }
  4398. else
  4399. {
  4400. tempIndex = gun_index;
  4401. }
  4402. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4403. {
  4404. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4405. {
  4406. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4407. }
  4408. }
  4409. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4410. }
  4411. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4412. {
  4413. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4414. {
  4415. tempIndex = ((gun_index==2) ? 1: 0);
  4416. }
  4417. else
  4418. {
  4419. tempIndex = gun_index;
  4420. }
  4421. for (int index = 0; index < CCS_QUANTITY; index++)
  4422. {
  4423. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4424. {
  4425. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4426. }
  4427. }
  4428. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4429. }
  4430. else if(gunType[gun_index] == 'G')
  4431. {
  4432. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4433. {
  4434. tempIndex = ((gun_index==2) ? 1: 0);
  4435. }
  4436. else
  4437. {
  4438. tempIndex = gun_index;
  4439. }
  4440. for (int index = 0; index < GB_QUANTITY; index++)
  4441. {
  4442. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4443. {
  4444. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4445. }
  4446. }
  4447. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4448. }
  4449. else if(gunType[gun_index] == 'O')
  4450. {
  4451. tempIndex = gun_index;
  4452. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4453. {
  4454. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4455. {
  4456. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  4457. }
  4458. }
  4459. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4460. }
  4461. else
  4462. {
  4463. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4464. {
  4465. tempIndex = 2;
  4466. }
  4467. else
  4468. {
  4469. tempIndex = gun_index;
  4470. }
  4471. for (int index = 0; index < AC_QUANTITY; index++)
  4472. {
  4473. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4474. {
  4475. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4476. }
  4477. }
  4478. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4479. }
  4480. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4481. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4482. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4483. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4484. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4485. //idx_sample=2;
  4486. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4487. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4488. if(gunType[gun_index] == 'J')
  4489. {
  4490. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4491. {
  4492. tempIndex = ((gun_index==2) ? 1: 0);
  4493. }
  4494. else
  4495. {
  4496. tempIndex = gun_index;
  4497. }
  4498. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4499. {
  4500. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4501. {
  4502. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4503. }
  4504. } // END OF FOR CHAdeMO_QUANTITY
  4505. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4506. }
  4507. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4508. {
  4509. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4510. {
  4511. tempIndex = ((gun_index==2) ? 1: 0);
  4512. }
  4513. else
  4514. {
  4515. tempIndex = gun_index;
  4516. }
  4517. for (int index = 0; index < CCS_QUANTITY; index++)
  4518. {
  4519. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4520. {
  4521. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4522. }
  4523. } // END OF CCS_QUANTITY
  4524. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4525. }
  4526. else if(gunType[gun_index] == 'G')
  4527. {
  4528. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4529. {
  4530. tempIndex = ((gun_index==2) ? 1: 0);
  4531. }
  4532. else
  4533. {
  4534. tempIndex = gun_index;
  4535. }
  4536. for (int index = 0; index < GB_QUANTITY; index++)
  4537. {
  4538. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4539. {
  4540. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4541. }
  4542. } // END OF GB_QUANTITY
  4543. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4544. }
  4545. else if(gunType[gun_index] == 'O')
  4546. {
  4547. tempIndex = gun_index;
  4548. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4549. {
  4550. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4551. {
  4552. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  4553. }
  4554. }
  4555. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4556. }
  4557. else
  4558. {
  4559. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4560. {
  4561. tempIndex = 2;
  4562. }
  4563. else
  4564. {
  4565. tempIndex = gun_index;
  4566. }
  4567. for (int index = 0; index < AC_QUANTITY; index++)
  4568. {
  4569. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4570. {
  4571. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4572. }
  4573. }
  4574. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4575. }
  4576. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4577. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4579. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4580. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4581. //idx_sample=3;
  4582. //********************************(4)Power.Active.Import************************************************/
  4583. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4584. if(gunType[gun_index] == 'J')
  4585. {
  4586. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4587. {
  4588. tempIndex = ((gun_index==2) ? 1: 0);
  4589. }
  4590. else
  4591. {
  4592. tempIndex = gun_index;
  4593. }
  4594. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4595. {
  4596. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4597. {
  4598. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4599. }
  4600. } // END OF FOR
  4601. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4602. }
  4603. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4604. {
  4605. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4606. {
  4607. tempIndex = ((gun_index==2) ? 1: 0);
  4608. }
  4609. else
  4610. {
  4611. tempIndex = gun_index;
  4612. }
  4613. for (int index = 0; index < CCS_QUANTITY; index++)
  4614. {
  4615. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4616. {
  4617. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4618. }
  4619. }
  4620. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4621. }
  4622. else if(gunType[gun_index] == 'G')
  4623. {
  4624. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4625. {
  4626. tempIndex = ((gun_index==2) ? 1: 0);
  4627. }
  4628. else
  4629. {
  4630. tempIndex = gun_index;
  4631. }
  4632. for (int index = 0; index < GB_QUANTITY; index++)
  4633. {
  4634. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4635. {
  4636. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4637. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4638. }
  4639. }
  4640. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4641. }
  4642. else if(gunType[gun_index] == 'O')
  4643. {
  4644. tempIndex = gun_index;
  4645. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4646. {
  4647. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4648. {
  4649. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4650. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  4651. }
  4652. }
  4653. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4654. }
  4655. else
  4656. {
  4657. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4658. {
  4659. tempIndex = 2;
  4660. }
  4661. else
  4662. {
  4663. tempIndex = gun_index;
  4664. }
  4665. for (int index = 0; index < AC_QUANTITY; index++)
  4666. {
  4667. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4668. {
  4669. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4670. }
  4671. }
  4672. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4673. }
  4674. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4675. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4676. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4677. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4678. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4679. //idx_sample=4;
  4680. //***********************************************(5)VOLTAGE L1******************************************************/
  4681. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4682. if(gunType[gun_index] == 'J')
  4683. {
  4684. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4685. {
  4686. tempIndex = ((gun_index==2) ? 1: 0);
  4687. }
  4688. else
  4689. {
  4690. tempIndex = gun_index;
  4691. }
  4692. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4693. {
  4694. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4695. {
  4696. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4697. }
  4698. }
  4699. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4700. }
  4701. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4702. {
  4703. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4704. {
  4705. tempIndex = ((gun_index==2) ? 1: 0);
  4706. }
  4707. else
  4708. {
  4709. tempIndex = gun_index;
  4710. }
  4711. for (int index = 0; index < CCS_QUANTITY; index++)
  4712. {
  4713. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4714. {
  4715. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4716. }
  4717. }
  4718. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4719. }
  4720. else if(gunType[gun_index] == 'G')
  4721. {
  4722. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4723. {
  4724. tempIndex = ((gun_index==2) ? 1: 0);
  4725. }
  4726. else
  4727. {
  4728. tempIndex = gun_index;
  4729. }
  4730. for (int index = 0; index < GB_QUANTITY; index++)
  4731. {
  4732. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4733. {
  4734. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4735. }
  4736. }
  4737. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4738. }
  4739. else if(gunType[gun_index] == 'O')
  4740. {
  4741. tempIndex = gun_index;
  4742. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4743. {
  4744. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4745. {
  4746. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  4747. }
  4748. }
  4749. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4750. }
  4751. else
  4752. {
  4753. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4754. {
  4755. tempIndex = 2;
  4756. }
  4757. else
  4758. {
  4759. tempIndex = gun_index;
  4760. }
  4761. for (int index = 0; index < AC_QUANTITY; index++)
  4762. {
  4763. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4764. {
  4765. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4766. }
  4767. }
  4768. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4769. }
  4770. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4771. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4772. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4773. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4774. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4775. //***********************************************(6)SOC******************************************************/
  4776. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  4777. {
  4778. //idx_sample=5;
  4779. //sampledValue = NULL;
  4780. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  4781. {
  4782. tempIndex = ((gun_index==2) ? 1: 0);
  4783. }
  4784. else
  4785. {
  4786. tempIndex = gun_index;
  4787. }
  4788. if(gunType[gun_index] == 'J')
  4789. {
  4790. //tempIndex = ((gun_index==2) ? 1: 0);
  4791. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4792. {
  4793. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4794. {
  4795. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4796. }
  4797. }
  4798. }
  4799. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4800. {
  4801. //tempIndex = ((gun_index==2) ? 1: 0);
  4802. for (int index = 0; index < CCS_QUANTITY; index++)
  4803. {
  4804. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4805. {
  4806. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4807. }
  4808. }
  4809. }
  4810. else if(gunType[gun_index] == 'G')
  4811. {
  4812. //tempIndex = ((gun_index==2) ? 1: 0);
  4813. for (int index = 0; index < GB_QUANTITY; index++)
  4814. {
  4815. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4816. {
  4817. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4818. }
  4819. }
  4820. }
  4821. else if(gunType[gun_index] == 'O')
  4822. {
  4823. //tempIndex = ((gun_index==2) ? 1: 0);
  4824. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4825. {
  4826. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4827. {
  4828. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  4829. }
  4830. }
  4831. }
  4832. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  4833. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4834. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4835. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4836. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  4837. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4838. }
  4839. //********************************(7)Current.Import L2************************************************/
  4840. // Only for AC 3 phase
  4841. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4842. {
  4843. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4844. {
  4845. tempIndex = 2;
  4846. }
  4847. else
  4848. {
  4849. tempIndex = gun_index;
  4850. }
  4851. for (int index = 0; index < AC_QUANTITY; index++)
  4852. {
  4853. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4854. {
  4855. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  4856. }
  4857. }
  4858. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  4859. }
  4860. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  4861. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  4862. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  4863. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  4864. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4865. //********************************(8)Current.Import L3************************************************/
  4866. // Only for AC 3 phase
  4867. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4868. {
  4869. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4870. {
  4871. tempIndex = 2;
  4872. }
  4873. else
  4874. {
  4875. tempIndex = gun_index;
  4876. }
  4877. for (int index = 0; index < AC_QUANTITY; index++)
  4878. {
  4879. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4880. {
  4881. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  4882. }
  4883. }
  4884. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  4885. }
  4886. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  4887. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  4888. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  4889. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  4890. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4891. //***********************************************(9)VOLTAGE L2******************************************************/
  4892. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4893. {
  4894. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4895. {
  4896. tempIndex = 2;
  4897. }
  4898. else
  4899. {
  4900. tempIndex = gun_index;
  4901. }
  4902. for (int index = 0; index < AC_QUANTITY; index++)
  4903. {
  4904. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4905. {
  4906. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  4907. }
  4908. }
  4909. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  4910. }
  4911. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  4912. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  4913. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  4914. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  4915. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4916. //***********************************************(10)VOLTAGE L3******************************************************/
  4917. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4918. {
  4919. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4920. {
  4921. tempIndex = 2;
  4922. }
  4923. else
  4924. {
  4925. tempIndex = gun_index;
  4926. }
  4927. for (int index = 0; index < AC_QUANTITY; index++)
  4928. {
  4929. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4930. {
  4931. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  4932. }
  4933. }
  4934. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  4935. }
  4936. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  4937. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  4938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  4939. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  4940. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4941. // Message create ====================================================================================================
  4942. if(TRUE)
  4943. {
  4944. json_object *MeterValueReq = json_object_new_object();
  4945. json_object *MeterValues = json_object_new_array();
  4946. json_object *sampledValues = json_object_new_array();
  4947. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  4948. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  4949. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  4950. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  4951. {
  4952. json_object *MeterValue = json_object_new_object();
  4953. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  4954. {
  4955. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  4956. {
  4957. json_object *sampledValue = json_object_new_object();
  4958. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  4959. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  4960. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  4961. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  4962. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  4963. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  4964. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  4965. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  4966. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  4967. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  4968. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  4969. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  4970. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  4971. json_object_array_add(sampledValues, sampledValue);
  4972. }
  4973. }
  4974. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  4975. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  4976. json_object_array_add(MeterValues, MeterValue);
  4977. }
  4978. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  4979. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  4980. ,gun_index + 1
  4981. ,MESSAGE_TYPE_CALL
  4982. ,guid
  4983. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  4984. json_object_put(MeterValueReq);
  4985. }
  4986. // Put request guid to hash map
  4987. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4988. 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*/)
  4989. {
  4990. result = PASS;
  4991. //DEBUG_INFO("MeterValues mapitem pass\n");
  4992. }
  4993. if((dataType != ReadingContext_Trigger) &&
  4994. (dataType != ReadingContext_Sample_Clock) &&
  4995. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  4996. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  4997. else
  4998. {
  4999. if(FirstHeartBeat)
  5000. LWS_Send(queuedata +2);
  5001. }
  5002. return result;
  5003. }
  5004. //==========================================
  5005. // send confirm routine
  5006. //==========================================
  5007. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5008. {
  5009. mtrace();
  5010. int result = FAIL;
  5011. char message[100]={0};
  5012. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5013. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5014. LWS_Send(message);
  5015. result = TRUE;
  5016. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  5017. return result;
  5018. }
  5019. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5020. {
  5021. mtrace();
  5022. int result = FAIL;
  5023. char message[100]={0};
  5024. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5025. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5026. LWS_Send(message);
  5027. result = TRUE;
  5028. return result;
  5029. }
  5030. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5031. {
  5032. mtrace();
  5033. int result = FAIL;
  5034. char message[100]={0};
  5035. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5036. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5037. LWS_Send(message);
  5038. result = TRUE;
  5039. return result;
  5040. }
  5041. int sendClearCacheConfirmation(char *uuid,char *payload)
  5042. {
  5043. mtrace();
  5044. int result = FAIL;
  5045. char message[500]={0};
  5046. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5047. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5048. LWS_Send(message);
  5049. return result;
  5050. }
  5051. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5052. {
  5053. mtrace();
  5054. int result = FAIL;
  5055. char message[500]={0};
  5056. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5057. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5058. LWS_Send(message);
  5059. return result;
  5060. }
  5061. int sendDataTransferConfirmation(char *uuid,char *payload)
  5062. {
  5063. mtrace();
  5064. char statusStr[20]={0};
  5065. char dataStr[10]={0};
  5066. char sstr[20]={0};
  5067. int c = 0;
  5068. char *loc;
  5069. int result = FAIL;
  5070. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5071. /**********************status**************************/
  5072. loc = strstr(payload, "status");
  5073. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5074. c = 0;
  5075. while (loc[3+strlen("status")+c] != '\"')
  5076. {
  5077. sstr[c] = loc[3+strlen("status")+c];
  5078. c++;
  5079. }
  5080. sstr[c] = '\0';
  5081. strcpy(statusStr, sstr);
  5082. /**********************data**************************/
  5083. loc = strstr(payload, "data");
  5084. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5085. c = 0;
  5086. while (loc[3+strlen("data")+c] != '\"')
  5087. {
  5088. sstr[c] = loc[3+strlen("data")+c];
  5089. c++;
  5090. }
  5091. sstr[c] = '\0';
  5092. strcpy(dataStr, sstr);
  5093. return result;
  5094. }
  5095. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5096. {
  5097. mtrace();
  5098. int result = FAIL;
  5099. char message[1000]={0};
  5100. int CompositeScheduleIndex = 0;
  5101. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5102. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5103. if(nPeriod == 0)
  5104. {
  5105. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5106. {
  5107. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5108. ,MESSAGE_TYPE_CALLRESULT
  5109. ,uuid
  5110. ,payload
  5111. ,connectorIdInt);
  5112. }
  5113. else
  5114. {
  5115. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5116. ,MESSAGE_TYPE_CALLRESULT
  5117. ,uuid
  5118. ,payload
  5119. ,connectorIdInt
  5120. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5121. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5122. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5123. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5124. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5125. }
  5126. }
  5127. else
  5128. {
  5129. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5130. ,MESSAGE_TYPE_CALLRESULT
  5131. ,uuid
  5132. ,payload
  5133. ,connectorIdInt
  5134. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5135. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5136. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5137. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5138. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5139. {
  5140. if (idx_sample == 0)
  5141. {
  5142. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5143. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5144. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5145. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5146. }
  5147. else
  5148. {
  5149. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5150. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5151. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5152. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5153. }
  5154. }
  5155. sprintf(message + strlen(message), "]}}]");
  5156. }
  5157. LWS_Send(message);
  5158. result = TRUE;
  5159. return result;
  5160. }
  5161. int sendGetConfigurationConfirmation(char *uuid)
  5162. {
  5163. mtrace();
  5164. int result = FAIL;
  5165. int MaxKeySupported = 0;
  5166. int sentConfigurationNumber= 0;
  5167. int sentunConfigurationNumber= 0;
  5168. char message[4000]={0};
  5169. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5170. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5171. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5172. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5173. ,MESSAGE_TYPE_CALLRESULT
  5174. ,uuid );
  5175. //configuration key
  5176. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5177. {
  5178. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5179. {
  5180. if (sentConfigurationNumber == 0)
  5181. {
  5182. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5183. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5184. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5185. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5186. }
  5187. else
  5188. {
  5189. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5190. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5191. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5192. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5193. }
  5194. sentConfigurationNumber = sentConfigurationNumber + 1;
  5195. }
  5196. }
  5197. sprintf(message + strlen(message), "]");
  5198. if(UnknownKeynum != 0)
  5199. {
  5200. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5201. //unkown key
  5202. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5203. {
  5204. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5205. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5206. if(sentunConfigurationNumber == 0)
  5207. {
  5208. sprintf(message + strlen(message), "\"%s\""
  5209. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5210. }
  5211. else
  5212. {
  5213. sprintf(message + strlen(message), ",\"%s\""
  5214. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5215. }
  5216. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5217. }
  5218. sprintf(message + strlen(message), "]");
  5219. }
  5220. sprintf(message + strlen(message), "}]");
  5221. LWS_Send(message);
  5222. return result;
  5223. }
  5224. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5225. {
  5226. mtrace();
  5227. int result = FAIL;
  5228. char message[400]={0};
  5229. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5230. if(strcmp(payload,"")==0)
  5231. {
  5232. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5233. }
  5234. else
  5235. {
  5236. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5237. }
  5238. LWS_Send(message);
  5239. result = TRUE;
  5240. return result;
  5241. }
  5242. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5243. {
  5244. mtrace();
  5245. int result = FAIL;
  5246. char message[80]={0};
  5247. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5248. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5249. LWS_Send(message);
  5250. result = TRUE;
  5251. return result;
  5252. }
  5253. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5254. {
  5255. mtrace();
  5256. int result = FAIL;
  5257. char message[80]={0};
  5258. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5259. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5260. LWS_Send(message);
  5261. result = TRUE;
  5262. return result;
  5263. }
  5264. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5265. {
  5266. mtrace();
  5267. int result = FAIL;
  5268. char message[80]={0};
  5269. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5270. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5271. LWS_Send(message);
  5272. result = TRUE;
  5273. return result;
  5274. }
  5275. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5276. {
  5277. mtrace();
  5278. int result = FAIL;
  5279. char message[80]={0};
  5280. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5281. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5282. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5283. LWS_Send(message);
  5284. result = TRUE;
  5285. return result;
  5286. }
  5287. int sendResetConfirmation(char *uuid,char *payload)
  5288. {
  5289. mtrace();
  5290. int result = FAIL;
  5291. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5292. char message[80]={0};
  5293. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5294. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5295. LWS_Send(message);
  5296. result = TRUE;
  5297. return result;
  5298. }
  5299. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5300. {
  5301. mtrace();
  5302. int result = FAIL;
  5303. char message[500]={0};
  5304. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5305. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5306. LWS_Send(message);
  5307. result = TRUE;
  5308. return result;
  5309. }
  5310. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5311. {
  5312. mtrace();
  5313. int result = FAIL;
  5314. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5315. char message[80]={0};
  5316. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5317. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5318. LWS_Send(message);
  5319. result = TRUE;
  5320. return result;
  5321. }
  5322. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5323. {
  5324. mtrace();
  5325. int result = FAIL;
  5326. char message[80]={0};
  5327. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5328. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5329. LWS_Send(message);
  5330. result = TRUE;
  5331. return result;
  5332. }
  5333. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5334. {
  5335. mtrace();
  5336. int result = FAIL;
  5337. char message[80]={0};
  5338. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5339. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5340. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5341. LWS_Send(message);
  5342. result = TRUE;
  5343. return result;
  5344. }
  5345. int sendUpdateFirmwareConfirmation(char *uuid)
  5346. {
  5347. mtrace();
  5348. int result = FAIL;
  5349. char message[60]={0};
  5350. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5351. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5352. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5353. LWS_Send(message);
  5354. result = TRUE;
  5355. return result;
  5356. }
  5357. //==========================================
  5358. // send CallError routine
  5359. //==========================================
  5360. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5361. {
  5362. mtrace();
  5363. char message[220]={0};
  5364. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5365. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5366. LWS_Send(message);
  5367. }
  5368. //==========================================
  5369. // Handle server request routine Start
  5370. //==========================================
  5371. int handleCancelReservationRequest(char *uuid, char *payload)
  5372. {
  5373. mtrace();
  5374. int result = FAIL;
  5375. int gunNO = 0;
  5376. int reservationIdInt = -1;
  5377. char comfirmstr[20];
  5378. DEBUG_INFO("handleCancelReservationRequest...\n");
  5379. json_object *CancelReservation;
  5380. CancelReservation = json_tokener_parse(payload);
  5381. if(!is_error(CancelReservation))
  5382. {
  5383. // Required data
  5384. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  5385. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5386. }
  5387. json_object_put(CancelReservation);
  5388. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  5389. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5390. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5391. if(reservationIdInt != -1)
  5392. {
  5393. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5394. //check Transaction active
  5395. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5396. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5397. {
  5398. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5399. {
  5400. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5401. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5402. if(gunType[2] == 'J')
  5403. {
  5404. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5405. }
  5406. else
  5407. {
  5408. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5409. }
  5410. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5411. goto end;
  5412. }
  5413. }
  5414. for (int index = 0; index < CCS_QUANTITY; index++)
  5415. {
  5416. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5417. {
  5418. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5419. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5420. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5421. {
  5422. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5423. }
  5424. else
  5425. {
  5426. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5427. }
  5428. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5429. goto end;
  5430. }
  5431. }
  5432. for (int index = 0; index < GB_QUANTITY; index++)
  5433. {
  5434. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5435. {
  5436. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5437. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5438. if(gunType[2] == 'G')
  5439. {
  5440. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5441. }
  5442. else
  5443. {
  5444. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5445. }
  5446. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5447. goto end;
  5448. }
  5449. }
  5450. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5451. {
  5452. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  5453. {
  5454. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5455. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5456. if(gunType[2] == 'G')
  5457. {
  5458. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index + 1;
  5459. }
  5460. else
  5461. {
  5462. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  5463. }
  5464. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5465. goto end;
  5466. }
  5467. }
  5468. for (int index = 0; index < AC_QUANTITY; index++)
  5469. {
  5470. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5471. {
  5472. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5473. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5474. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5475. {
  5476. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5477. }
  5478. else
  5479. {
  5480. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5481. }
  5482. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5483. goto end;
  5484. }
  5485. }
  5486. }
  5487. //The reservationId does NOT match the reservationId
  5488. sendCancelReservationConfirmation(uuid, comfirmstr);
  5489. end:
  5490. // Fill in ocpp packet uuid
  5491. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5492. return result;
  5493. }
  5494. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5495. {
  5496. mtrace();
  5497. int result = FAIL;
  5498. int gunIndex = 0;
  5499. char typeStr[16]={0};
  5500. char comfirmstr[20];
  5501. int specificId = FALSE;
  5502. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5503. json_object *ChangeAvailability;
  5504. ChangeAvailability = json_tokener_parse(payload);
  5505. if(!is_error(ChangeAvailability))
  5506. {
  5507. // Required data
  5508. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  5509. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5510. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  5511. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5512. }
  5513. json_object_put(ChangeAvailability);
  5514. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5515. {
  5516. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5517. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5518. }
  5519. else if(gunIndex == 0)
  5520. {
  5521. for(int i=0; i < gunTotalNumber; i++)
  5522. {
  5523. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5524. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5525. }
  5526. }
  5527. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5528. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5529. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  5530. {
  5531. specificId = TRUE;
  5532. }
  5533. if(specificId == FALSE)
  5534. goto end;
  5535. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5536. {
  5537. //----------------------gunIndex is 0 ------------------------------------------------//
  5538. if(gunIndex == 0)
  5539. {
  5540. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5541. {
  5542. for(int i=0; i < gunTotalNumber; i++)
  5543. {
  5544. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5545. {
  5546. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5547. {
  5548. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5549. {
  5550. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5551. goto end;
  5552. }
  5553. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5554. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5555. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5556. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5557. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5558. {
  5559. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5560. goto end;
  5561. }
  5562. }
  5563. }//END FOR CHAdeMO_QUANTITY
  5564. for (int index = 0; index < CCS_QUANTITY; index++)
  5565. {
  5566. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5567. {
  5568. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5569. {
  5570. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5571. goto end;
  5572. }
  5573. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5574. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5575. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5576. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5577. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5578. {
  5579. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5580. goto end;
  5581. }
  5582. }
  5583. }//END FOR CCS_QUANTITY
  5584. for (int index = 0; index < GB_QUANTITY; index++)
  5585. {
  5586. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5587. {
  5588. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5589. {
  5590. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5591. goto end;
  5592. }
  5593. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5594. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5595. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5596. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5597. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5598. {
  5599. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5600. goto end;
  5601. }
  5602. }
  5603. }// END FOR GB_QUANTITY
  5604. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5605. {
  5606. if ((gunType[i] == 'O')&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  5607. {
  5608. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5609. {
  5610. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5611. goto end;
  5612. }
  5613. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5614. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5615. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5616. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5617. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5618. {
  5619. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5620. goto end;
  5621. }
  5622. }
  5623. }// END FOR GENERAL_GUN_QUANTITY
  5624. for (int index = 0; index < AC_QUANTITY; index++)
  5625. {
  5626. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5627. {
  5628. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5629. {
  5630. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5631. goto end;
  5632. }
  5633. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5634. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5635. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5636. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5637. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5638. {
  5639. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5640. goto end;
  5641. }
  5642. }
  5643. }//END FOR AC_QUANTITY
  5644. }// END FOR gunTotalNumber
  5645. }
  5646. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5647. {
  5648. for(int i=0; i < gunTotalNumber; i++)
  5649. {
  5650. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5651. {
  5652. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5653. goto end;
  5654. }
  5655. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5656. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5657. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5658. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5659. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5660. {
  5661. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5662. goto end;
  5663. }
  5664. }
  5665. }
  5666. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5667. goto end;
  5668. }
  5669. //----------------------gunIndex is not 0 ------------------------------------------------//
  5670. //check Transaction active
  5671. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5672. {
  5673. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5674. {
  5675. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5676. {
  5677. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5678. goto end;
  5679. }
  5680. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5681. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5682. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5683. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5684. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5685. {
  5686. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5687. goto end;
  5688. }
  5689. else
  5690. {
  5691. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5692. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5693. goto end;
  5694. }
  5695. }
  5696. }//END FOR CHAdeMO_QUANTITY
  5697. for (int index = 0; index < CCS_QUANTITY; index++)
  5698. {
  5699. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5700. {
  5701. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5702. {
  5703. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5704. goto end;
  5705. }
  5706. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5707. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5708. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5709. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5710. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5711. {
  5712. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5713. goto end;
  5714. }
  5715. else
  5716. {
  5717. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5718. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5719. goto end;
  5720. }
  5721. }
  5722. }//END FOR CCS_QUANTITY
  5723. for (int index = 0; index < GB_QUANTITY; index++)
  5724. {
  5725. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5726. {
  5727. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5728. {
  5729. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5730. goto end;
  5731. }
  5732. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5733. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5734. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5735. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5736. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5737. {
  5738. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5739. goto end;
  5740. }
  5741. else
  5742. {
  5743. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5744. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5745. goto end;
  5746. }
  5747. }
  5748. }// END FOR GB_QUANTITY
  5749. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5750. {
  5751. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'O'))
  5752. {
  5753. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5754. {
  5755. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5756. goto end;
  5757. }
  5758. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5759. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5760. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5761. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5762. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5763. {
  5764. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5765. goto end;
  5766. }
  5767. else
  5768. {
  5769. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  5770. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5771. goto end;
  5772. }
  5773. }
  5774. }// END FOR GENERAL_GUN_QUANTITY
  5775. for (int index = 0; index < AC_QUANTITY; index++)
  5776. {
  5777. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5778. {
  5779. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5780. {
  5781. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5782. goto end;
  5783. }
  5784. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5785. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5786. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5787. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5788. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5789. {
  5790. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5791. goto end;
  5792. }
  5793. else
  5794. {
  5795. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5796. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5797. goto end;
  5798. }
  5799. }
  5800. }//END FOR AC_QUANTITY
  5801. }//END FOR AvailabilityTypeStr[Inoperative]
  5802. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5803. {
  5804. //----------------------gunIndex is 0 ------------------------------------------------//
  5805. if(gunIndex == 0)
  5806. {
  5807. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5808. {
  5809. for(int i=0; i < gunTotalNumber; i++)
  5810. {
  5811. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5812. {
  5813. 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
  5814. {
  5815. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5816. goto end;
  5817. }
  5818. }//END FOR CHAdeMO_QUANTITY
  5819. for (int index = 0; index < CCS_QUANTITY; index++)
  5820. {
  5821. 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
  5822. {
  5823. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5824. goto end;
  5825. }
  5826. }//END FOR CCS_QUANTITY
  5827. for (int index = 0; index < GB_QUANTITY; index++)
  5828. {
  5829. 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
  5830. {
  5831. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5832. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5833. goto end;
  5834. }
  5835. }// END FOR GB_QUANTITY
  5836. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5837. {
  5838. if ((gunType[i] == 'O')&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'O')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5839. {
  5840. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5841. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5842. goto end;
  5843. }
  5844. }// END FOR GENERAL_GUN_QUANTITY
  5845. for (int index = 0; index < AC_QUANTITY; index++)
  5846. {
  5847. 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
  5848. {
  5849. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5850. goto end;
  5851. }
  5852. }//END FOR CHAdeMO_QUANTITY
  5853. }// END FOR gunTotalNumber
  5854. }
  5855. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5856. {
  5857. for(int i=0; i < gunTotalNumber; i++)
  5858. {
  5859. for (int index = 0; index < AC_QUANTITY; index++)
  5860. {
  5861. 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
  5862. {
  5863. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5864. goto end;
  5865. }
  5866. }//END FOR CHAdeMO_QUANTITY
  5867. } // END FOR gunTotalNumber
  5868. }
  5869. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5870. goto end;
  5871. }
  5872. //----------------------gunIndex is not 0 ------------------------------------------------//
  5873. //check Transaction active
  5874. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5875. {
  5876. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5877. {
  5878. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5879. goto end;
  5880. }
  5881. }//END FOR CHAdeMO_QUANTITY
  5882. for (int index = 0; index < CCS_QUANTITY; index++)
  5883. {
  5884. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5885. {
  5886. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5887. goto end;
  5888. }
  5889. }//END FOR CCS_QUANTITY
  5890. for (int index = 0; index < GB_QUANTITY; index++)
  5891. {
  5892. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5893. {
  5894. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5895. goto end;
  5896. }
  5897. }// END FOR GB_QUANTITY
  5898. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5899. {
  5900. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'O'))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5901. {
  5902. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5903. goto end;
  5904. }
  5905. }// END FOR GENERAL_GUN_QUANTITY
  5906. for (int index = 0; index < AC_QUANTITY; index++)
  5907. {
  5908. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5909. {
  5910. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5911. goto end;
  5912. }
  5913. }//END FOR AC_QUANTITY
  5914. }//END FOR AvailabilityTypeStr[Operative]
  5915. end:
  5916. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5917. {
  5918. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5919. }
  5920. else
  5921. {
  5922. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5923. }
  5924. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5925. {
  5926. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5927. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5928. }
  5929. else if(gunIndex == 0)
  5930. {
  5931. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5932. {
  5933. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5934. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5935. }
  5936. }
  5937. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5938. return result;
  5939. }
  5940. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5941. {
  5942. mtrace();
  5943. int result = FAIL;
  5944. char keystr[40]={0};
  5945. char valuestr[100]={0};
  5946. char comfirmstr[20]={0};
  5947. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5948. json_object *ChangeConfiguration;
  5949. ChangeConfiguration = json_tokener_parse(payload);
  5950. if(!is_error(ChangeConfiguration))
  5951. {
  5952. // Required data
  5953. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  5954. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5955. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  5956. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5957. }
  5958. json_object_put(ChangeConfiguration);
  5959. if((uuid==NULL) || (payload ==NULL) )
  5960. {
  5961. DEBUG_ERROR("Payload is null\n");
  5962. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5963. }
  5964. else
  5965. {
  5966. int status = setKeyValue(keystr, valuestr);
  5967. switch(status)
  5968. {
  5969. case ConfigurationStatus_Accepted:
  5970. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5971. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5972. StoreConfigurationTable();
  5973. break;
  5974. case RebootRequired:
  5975. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5976. StoreConfigurationTable();
  5977. break;
  5978. case NotSupported:
  5979. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5980. break;
  5981. case ConfigurationStatus_Rejected:
  5982. default:
  5983. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5984. break;
  5985. }
  5986. }
  5987. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5988. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5989. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5990. {
  5991. ChageWebSocketPingInterval(atoi(valuestr));
  5992. }
  5993. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5994. {
  5995. ShmSysConfigAndInfo->SysInfo.InternetConn = 0;
  5996. }
  5997. return result;
  5998. }
  5999. int handleClearCacheRequest(char *uuid, char *payload)
  6000. {
  6001. mtrace();
  6002. int result = FAIL;
  6003. char comfirmstr[20];
  6004. int fd;
  6005. char rmFileCmd[100]={0};
  6006. struct stat stats;
  6007. DEBUG_INFO("handleClearCacheRequest...\n");
  6008. stat("/Storage/OCPP", &stats);
  6009. // Check for directory existence
  6010. if (S_ISDIR(stats.st_mode) == 1)
  6011. {}
  6012. else
  6013. {
  6014. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6015. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6016. system(rmFileCmd);
  6017. }
  6018. memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
  6019. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  6020. {
  6021. DEBUG_INFO("AuthorizationCache file exist.\n");
  6022. }
  6023. else
  6024. {
  6025. DEBUG_INFO("AuthorizationCache file not exist\n");
  6026. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  6027. if(log == NULL)
  6028. {
  6029. DEBUG_INFO("AuthorizationCache file is NULL\n");
  6030. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6031. goto end;
  6032. }
  6033. else
  6034. {
  6035. fclose(log);
  6036. }
  6037. }
  6038. if((fd = open(AuthorizationCache_JSON,O_RDWR)) < 0)
  6039. {
  6040. DEBUG_INFO("open AuthorizationCache file failed\n");
  6041. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6042. }
  6043. else
  6044. {
  6045. DEBUG_INFO("open AuthorizationCache file successful\n");
  6046. ftruncate(fd,0);
  6047. lseek(fd,0,SEEK_SET);
  6048. close(fd);
  6049. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6050. }
  6051. end:
  6052. sendClearCacheConfirmation(uuid, comfirmstr);
  6053. return result;
  6054. }
  6055. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6056. {
  6057. mtrace();
  6058. int result = FAIL;
  6059. int resultRename;
  6060. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6061. char chargingProfilePurposeStr[26]={0};
  6062. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6063. char tempchargingProfilePurposeStr[26]={0};
  6064. char str[100]={0};
  6065. char fname[200]={0};
  6066. char comfirmstr[20]={0};
  6067. char word[1600]={0};
  6068. int clearflag = FALSE;
  6069. int chargingProfileIdIsNULL = FALSE;
  6070. int connectorIsNULL = FALSE;
  6071. int chargingProfilePurposeIsNULL = FALSE;
  6072. int stackLevelIsNULL = FALSE;
  6073. //int GotoEnd = FALSE;
  6074. FILE *fptr1, *fptr2;
  6075. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6076. int n_chargingProfile=0;
  6077. int isEmptyFile = FALSE;
  6078. char sLineWord[1600]={0};
  6079. char chargingProfiles[10][100]={0};
  6080. int ChargeProfileCount = 0;
  6081. int ch;
  6082. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6083. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6084. json_object *ClearChargingProfile;
  6085. ClearChargingProfile = json_tokener_parse(payload);
  6086. if(!is_error(ClearChargingProfile))
  6087. {
  6088. // Optional data
  6089. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6090. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6091. else
  6092. chargingProfileIdIsNULL = TRUE;
  6093. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6094. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6095. else
  6096. connectorIsNULL = TRUE;
  6097. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6098. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6099. else
  6100. chargingProfilePurposeIsNULL = TRUE;
  6101. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6102. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6103. else
  6104. stackLevelIsNULL = TRUE;
  6105. }
  6106. json_object_put(ClearChargingProfile);
  6107. if(connectorIsNULL == FALSE)
  6108. {
  6109. switch(connectorIdInt)
  6110. {
  6111. case 0:
  6112. if(chargingProfilePurposeIsNULL == TRUE)
  6113. {
  6114. int l = 0;
  6115. strcpy(fname, ChargePointMaxProfile_JSON);
  6116. if((access(fname,F_OK))!=-1)
  6117. {
  6118. strcpy(chargingProfiles[l], fname);
  6119. l = l + 1;
  6120. }
  6121. strcpy(fname, TxDefaultProfile_0_JSON);
  6122. if((access(fname,F_OK))!=-1)
  6123. {
  6124. strcpy(chargingProfiles[l], fname);
  6125. l = l + 1;
  6126. }
  6127. ChargeProfileCount = l;
  6128. }
  6129. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6130. {
  6131. strcpy(fname, ChargePointMaxProfile_JSON);
  6132. if((access(fname,F_OK))!=-1)
  6133. {
  6134. strcpy(chargingProfiles[0], fname);
  6135. ChargeProfileCount = 1;
  6136. }
  6137. }
  6138. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6139. {
  6140. strcpy(fname, TxDefaultProfile_0_JSON);
  6141. if((access(fname,F_OK))!=-1)
  6142. {
  6143. strcpy(chargingProfiles[0], fname);
  6144. ChargeProfileCount = 1;
  6145. }
  6146. }
  6147. break;
  6148. default:
  6149. if(chargingProfilePurposeIsNULL == TRUE)
  6150. {
  6151. int m = 0;
  6152. memset(fname, 0, ARRAY_SIZE(fname));
  6153. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6154. if((access(fname,F_OK))!=-1)
  6155. {
  6156. strcpy(chargingProfiles[m], fname);
  6157. m = m + 1;
  6158. }
  6159. memset(fname, 0, ARRAY_SIZE(fname));
  6160. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6161. if((access(fname,F_OK))!=-1)
  6162. {
  6163. strcpy(chargingProfiles[m], fname);
  6164. m = m + 1;
  6165. }
  6166. ChargeProfileCount = m;
  6167. }
  6168. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6169. {
  6170. //strcpy(fname, TxDefaultProfile_1_JSON);
  6171. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6172. if((access(fname,F_OK))!=-1)
  6173. {
  6174. strcpy(chargingProfiles[0], fname);
  6175. ChargeProfileCount = 1;
  6176. }
  6177. }
  6178. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6179. {
  6180. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6181. if((access(fname,F_OK))!=-1)
  6182. {
  6183. strcpy(chargingProfiles[0], fname);
  6184. ChargeProfileCount = 1;
  6185. }
  6186. //strcpy(fname, TxProfile_1_JSON);
  6187. }
  6188. //strcpy(fname, ChargePointMaxProfile_JSON );
  6189. break;
  6190. }
  6191. }
  6192. else // Check all Charging Profiles
  6193. {
  6194. int i = 0;
  6195. char fnametemp[200]={0};
  6196. ChargeProfileCount = 0;
  6197. //Check ChargePointMaxProfile.json exit
  6198. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6199. {
  6200. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6201. i = i + 1;
  6202. }
  6203. //Check TxDefaultProfile_0.json exit
  6204. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  6205. {
  6206. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  6207. i = i + 1;
  6208. }
  6209. //Check TxDefaultProfile_%d.json
  6210. for(int j=1; j <= gunTotalNumber; j++)
  6211. {
  6212. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6213. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  6214. if((access(fnametemp,F_OK))!=-1)
  6215. {
  6216. strcpy(chargingProfiles[i], fnametemp);
  6217. i = i + 1;
  6218. }
  6219. }
  6220. //Check TxProfile_%d.json
  6221. for(int j=1; j <= gunTotalNumber; j++)
  6222. {
  6223. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6224. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6225. if((access(fnametemp,F_OK))!=-1)
  6226. {
  6227. strcpy(chargingProfiles[i], fnametemp);
  6228. i = i + 1;
  6229. }
  6230. }
  6231. ChargeProfileCount = i;
  6232. }// End connectorIsNULL is TRUE
  6233. if(ChargeProfileCount == 0)
  6234. {
  6235. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6236. goto end;
  6237. }
  6238. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6239. {
  6240. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6241. goto end;
  6242. }
  6243. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6244. {
  6245. memset(str, 0, ARRAY_SIZE(str));
  6246. // clear temp file
  6247. sprintf(str,"rm -f %s",temp);
  6248. system(str);
  6249. for(int k=0; k < ChargeProfileCount; k++)
  6250. {
  6251. memset(str, 0, ARRAY_SIZE(str));
  6252. //clear file in C
  6253. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6254. system(str);
  6255. }
  6256. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6257. goto end;
  6258. }
  6259. else if(connectorIsNULL == TRUE)
  6260. {
  6261. for(int k=0; k < ChargeProfileCount; k++)
  6262. {
  6263. fptr1 = fopen(chargingProfiles[k], "r");
  6264. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6265. //Check Charging Profile Count
  6266. while(fscanf(fptr1, "%s", word) != EOF)
  6267. {
  6268. //DEBUG_INFO("word=%s\n",word);
  6269. if(strstr(word, "chargingProfileId")!= NULL)
  6270. {
  6271. //DEBUG_INFO("test chargingProfileId \n");
  6272. n_chargingProfile = n_chargingProfile + 1;
  6273. //DEBUG_INFO("chargingProfileId Found\n");
  6274. }
  6275. }
  6276. rewind(fptr1);
  6277. //search Charging Profile Element
  6278. //int i= 0;
  6279. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6280. {
  6281. json_object *tmpProfilee;
  6282. tmpProfilee = json_tokener_parse(sLineWord);
  6283. if(!is_error(tmpProfilee))
  6284. {
  6285. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6286. {
  6287. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6288. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6289. }
  6290. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6291. {
  6292. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6293. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6294. }
  6295. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6296. {
  6297. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6298. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6299. }
  6300. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6301. {
  6302. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6303. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6304. }
  6305. }
  6306. json_object_put(tmpProfilee);
  6307. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6308. {
  6309. //------- not write to fptr2-------//
  6310. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6311. //clearflag = TRUE;
  6312. }
  6313. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6314. {
  6315. //------- not write to fptr2-------//
  6316. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6317. }
  6318. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6319. {
  6320. //------- not write to fptr2-------//
  6321. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6322. }
  6323. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  6324. {
  6325. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6326. }
  6327. else
  6328. {
  6329. fprintf(fptr2, sLineWord);//writing data into file
  6330. }
  6331. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6332. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6333. if(clearflag == TRUE)
  6334. {
  6335. fclose(fptr1);
  6336. fclose(fptr2);
  6337. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6338. system(str);
  6339. // clear temp file
  6340. sprintf(str,"rm -f %s",temp);
  6341. system(str);
  6342. }
  6343. else
  6344. {
  6345. fclose(fptr1);
  6346. fclose(fptr2);
  6347. memset(str, 0, ARRAY_SIZE(str));
  6348. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6349. system(str);
  6350. resultRename = rename(temp, chargingProfiles[k]);
  6351. if(resultRename == 0)
  6352. {
  6353. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  6354. }
  6355. else
  6356. {
  6357. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  6358. }
  6359. if(comfirmstr[0]== 0)
  6360. {
  6361. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6362. }
  6363. //Check chargingProfile is empty file
  6364. /*------ Read the file ----------------*/
  6365. fptr1=fopen(chargingProfiles[k],"r");
  6366. ch=fgetc(fptr1);
  6367. rewind(fptr1);
  6368. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6369. if(ch!=EOF)
  6370. {
  6371. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6372. {
  6373. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6374. if(sLineWord[0]=='\0')
  6375. {
  6376. isEmptyFile = TRUE;
  6377. break;
  6378. }
  6379. else
  6380. {
  6381. isEmptyFile = FALSE;
  6382. break;
  6383. }
  6384. }
  6385. }
  6386. else
  6387. isEmptyFile = TRUE;
  6388. fclose(fptr1);
  6389. if(isEmptyFile == TRUE)
  6390. {
  6391. memset(str, 0, ARRAY_SIZE(str));
  6392. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6393. system(str);
  6394. }
  6395. }
  6396. }// End of while(int k=0; k < ChargePointCount; k++)
  6397. }
  6398. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6399. {
  6400. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6401. for(int k=0; k < ChargeProfileCount; k++)
  6402. {
  6403. fptr1 = fopen(chargingProfiles[k], "r");
  6404. fptr2 = fopen(temp, "w+");
  6405. //Check Charging Profile Count
  6406. while(fscanf(fptr1, "%s", word) != EOF)
  6407. {
  6408. //DEBUG_INFO("word=%s\n",word);
  6409. if(strstr(word, "chargingProfileId")!= NULL)
  6410. {
  6411. n_chargingProfile = n_chargingProfile + 1;
  6412. }
  6413. }
  6414. rewind(fptr1);
  6415. //search Charging Profile Element
  6416. //int i= 0;
  6417. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6418. {
  6419. json_object *tmpProfilee;
  6420. tmpProfilee = json_tokener_parse(sLineWord);
  6421. if(!is_error(tmpProfilee))
  6422. {
  6423. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6424. {
  6425. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6426. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6427. }
  6428. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6429. {
  6430. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6431. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6432. }
  6433. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6434. {
  6435. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6436. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6437. }
  6438. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6439. {
  6440. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6441. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6442. }
  6443. }
  6444. json_object_put(tmpProfilee);
  6445. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6446. {
  6447. //------- not write to fptr2-------//
  6448. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6449. //clearflag = TRUE;
  6450. }
  6451. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6452. {
  6453. //------- not write to fptr2-------//
  6454. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6455. }
  6456. else if(stackLevelIsNULL == TRUE)
  6457. {
  6458. //Clear Whole File
  6459. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6460. clearflag = TRUE;
  6461. break;
  6462. }
  6463. else
  6464. {
  6465. fprintf(fptr2, sLineWord);//writing data into file
  6466. }
  6467. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6468. }
  6469. if(clearflag == TRUE)
  6470. {
  6471. fclose(fptr1);
  6472. fclose(fptr2);
  6473. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6474. system(str);
  6475. // clear temp file
  6476. sprintf(str,"rm -f %s",temp);
  6477. system(str);
  6478. }
  6479. else
  6480. {
  6481. fclose(fptr1);
  6482. fclose(fptr2);
  6483. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6484. system(str);
  6485. resultRename = rename(temp, chargingProfiles[k]);
  6486. if(resultRename == 0)
  6487. {
  6488. DEBUG_INFO("File ChargingProfile renamed successfully");
  6489. }
  6490. else
  6491. {
  6492. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6493. }
  6494. if(comfirmstr[0]== 0)
  6495. {
  6496. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6497. }
  6498. //Check chargingProfile is empty file
  6499. /*------ Read the file ----------------*/
  6500. fptr1=fopen(chargingProfiles[k],"r");
  6501. ch=fgetc(fptr1);
  6502. rewind(fptr1);
  6503. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6504. if(ch!=EOF)
  6505. {
  6506. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6507. {
  6508. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6509. if(sLineWord[0]=='\0')
  6510. {
  6511. isEmptyFile = TRUE;
  6512. break;
  6513. }
  6514. else
  6515. {
  6516. isEmptyFile = FALSE;
  6517. break;
  6518. }
  6519. }
  6520. }
  6521. else
  6522. isEmptyFile = TRUE;
  6523. fclose(fptr1);
  6524. if(isEmptyFile == TRUE)
  6525. {
  6526. memset(str, 0, ARRAY_SIZE(str));
  6527. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6528. system(str);
  6529. }
  6530. /*------- End of reading ---------------*/
  6531. }
  6532. } // while(int k=0; k < ChargeProfileCount; k++)
  6533. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6534. end:
  6535. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  6536. {
  6537. if(connectorIdInt == 0)
  6538. {
  6539. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  6540. {
  6541. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx]);
  6542. }
  6543. }
  6544. else
  6545. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1]);
  6546. }
  6547. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6548. return result;
  6549. }
  6550. void createFirmwareVersionByDataTransfer(void)
  6551. {
  6552. json_object *FirmwareDataTransfer = json_object_new_object();
  6553. // AC & DC model
  6554. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6555. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6556. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6557. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6558. // DC model
  6559. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6560. {
  6561. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6562. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6563. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6564. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6565. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6566. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6567. }
  6568. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6569. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6570. {
  6571. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6572. }
  6573. // 4G model
  6574. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  6575. {
  6576. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6577. }
  6578. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6579. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6580. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  6581. json_object_put(FirmwareDataTransfer);
  6582. }
  6583. int handleDataTransferRequest(char *uuid, char *payload)
  6584. {
  6585. mtrace();
  6586. json_object *response = json_object_new_object();
  6587. int result = FAIL;
  6588. char tempvendorId[255]={0};
  6589. char tempmessageId[50]={0};
  6590. char tempdata[512]={0};
  6591. char message[2048]={0};
  6592. DEBUG_INFO("handleDataTransferRequest...\n");
  6593. if((uuid != NULL) && (payload != NULL))
  6594. {
  6595. json_object *DataTransfer;
  6596. DataTransfer = json_tokener_parse(payload);
  6597. if(!is_error(DataTransfer))
  6598. {
  6599. // Required data
  6600. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  6601. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6602. // Optional data
  6603. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6604. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6605. if(json_object_object_get(DataTransfer, "data") != NULL)
  6606. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6607. result = PASS;
  6608. }
  6609. json_object_put(DataTransfer);
  6610. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6611. {
  6612. // Send all moudle firmware version on EVSE
  6613. system("/usr/bin/run_tmate_restart.sh");
  6614. createFirmwareVersionByDataTransfer();
  6615. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6616. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6617. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6618. json_object_put(response);
  6619. }
  6620. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6621. {
  6622. json_object *data;
  6623. data = json_tokener_parse(tempdata);
  6624. if(!is_error(data))
  6625. {
  6626. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6627. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6628. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6629. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6630. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6631. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6632. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6633. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6634. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6635. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6636. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6637. }
  6638. else
  6639. {
  6640. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6641. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6642. }
  6643. json_object_put(data);
  6644. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6645. json_object_put(response);
  6646. }
  6647. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  6648. {
  6649. json_object *data;
  6650. data = json_tokener_parse(tempdata);
  6651. if(!is_error(data))
  6652. {
  6653. if(json_object_object_get(data, "idToken") != NULL)
  6654. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  6655. if(json_object_object_get(data, "price") != NULL)
  6656. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  6657. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6658. }
  6659. else
  6660. {
  6661. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6662. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6663. }
  6664. json_object_put(data);
  6665. json_object_put(response);
  6666. }
  6667. else if(strstr(tempmessageId, "RunningCost") != NULL)
  6668. {
  6669. json_object *data;
  6670. data = json_tokener_parse(tempdata);
  6671. if(!is_error(data))
  6672. {
  6673. if(json_object_object_get(data, "txId") != NULL)
  6674. if(json_object_object_get(data, "description") != NULL)
  6675. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6676. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6677. }
  6678. else
  6679. {
  6680. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6681. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6682. }
  6683. json_object_put(data);
  6684. json_object_put(response);
  6685. }
  6686. else if(strstr(tempmessageId, "FinalCost") != NULL)
  6687. {
  6688. json_object *data;
  6689. data = json_tokener_parse(tempdata);
  6690. if(!is_error(data))
  6691. {
  6692. if(json_object_object_get(data, "txId") != NULL)
  6693. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  6694. if(json_object_object_get(data, "description") != NULL)
  6695. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6696. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6697. }
  6698. else
  6699. {
  6700. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6701. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6702. }
  6703. json_object_put(data);
  6704. json_object_put(response);
  6705. }
  6706. else
  6707. {
  6708. // Can not find valid message id
  6709. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6710. }
  6711. }
  6712. else
  6713. {
  6714. // Payload is null
  6715. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6716. }
  6717. LWS_Send(message);
  6718. return result;
  6719. }
  6720. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6721. {
  6722. mtrace();
  6723. int result = FAIL;
  6724. int connectorIdInt, durationInt;
  6725. char chargingRateUnitStr[4]={0};
  6726. char comfirmstr[20];
  6727. int confirmPeriods = 0;
  6728. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6729. json_object *GetCompositeSchedule;
  6730. GetCompositeSchedule = json_tokener_parse(payload);
  6731. if(!is_error(GetCompositeSchedule))
  6732. {
  6733. // Required data
  6734. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  6735. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6736. else
  6737. connectorIdInt = -1;
  6738. if(json_object_object_get(GetCompositeSchedule, "duration"))
  6739. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6740. else
  6741. durationInt = 86400;
  6742. // Optional data
  6743. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6744. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6745. }
  6746. json_object_put(GetCompositeSchedule);
  6747. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6748. if((connectorIdInt == 0) ||
  6749. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6750. {
  6751. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6752. struct StructChargingProfile tmpProfile[1];
  6753. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6754. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6755. {
  6756. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6757. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6758. }
  6759. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6760. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6761. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6762. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6763. {
  6764. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6765. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6766. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6767. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6768. {
  6769. confirmPeriods = idx;
  6770. break;
  6771. }
  6772. }
  6773. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6774. }
  6775. else
  6776. {
  6777. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6778. }
  6779. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6780. return result;
  6781. }
  6782. int handleGetConfigurationRequest(char *uuid, char *payload)
  6783. {
  6784. mtrace();
  6785. int result = FAIL;
  6786. int MaxKeySupported = 0;
  6787. int n_keys = 0;
  6788. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  6789. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6790. json_object *GetConfiguration;
  6791. GetConfiguration = json_tokener_parse(payload);
  6792. if(!is_error(GetConfiguration))
  6793. {
  6794. // Optional data
  6795. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6796. {
  6797. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6798. {
  6799. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6800. n_keys = idx + 1;
  6801. }
  6802. }
  6803. }
  6804. json_object_put(GetConfiguration);
  6805. UnknownKeynum = 0;
  6806. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6807. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6808. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6809. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6810. if(n_keys != 0)
  6811. {
  6812. for(int i=0;i<n_keys;i++)
  6813. {
  6814. getKeyValue(requestKey[i]);
  6815. }
  6816. }
  6817. else
  6818. {
  6819. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6820. getKeyValue("");
  6821. }
  6822. processUnkownKey();
  6823. sendGetConfigurationConfirmation(uuid);
  6824. return result;
  6825. }
  6826. static char fnamePlusPath[100]={0};
  6827. static char fnamePWithNoPath[60]={0};
  6828. void checkUploadLog(void)
  6829. {
  6830. FILE *fp;
  6831. /* Open the command for reading. */
  6832. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6833. if (fp == NULL) {
  6834. printf("Failed to run command\n" );
  6835. exit(1);
  6836. }
  6837. int ftppathlen = 0;
  6838. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6839. int i = 0;
  6840. /* Read the output a line at a time - output it. */
  6841. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6842. if(i==0)
  6843. {
  6844. ftppathlen = strlen(fnamePlusPath);
  6845. printf("%s\n", fnamePlusPath);
  6846. fnamePlusPath[ftppathlen]='\0';
  6847. break;
  6848. }
  6849. i= i+1;
  6850. }
  6851. /* close */
  6852. pclose(fp);
  6853. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6854. {
  6855. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  6856. {
  6857. fnamePlusPath[k]='\0';
  6858. }
  6859. }
  6860. i=1;
  6861. //char fname[60]={0};
  6862. while(i < ftppathlen)
  6863. {
  6864. int len=ftppathlen-i;
  6865. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6866. {
  6867. printf("compare '/' all right\n");
  6868. break;
  6869. }
  6870. i=i+1;
  6871. }
  6872. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6873. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6874. fnamePWithNoPath[i+1] = '\0';
  6875. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6876. {
  6877. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6878. {
  6879. fnamePWithNoPath[j]='\0';
  6880. }
  6881. }
  6882. FILE* fp1 = fopen(fnamePlusPath, "r");
  6883. if (fp1)
  6884. {
  6885. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6886. // file exists
  6887. fclose(fp1);
  6888. }
  6889. else
  6890. {
  6891. // file doesn't exist
  6892. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6893. }
  6894. }
  6895. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6896. {
  6897. mtrace();
  6898. int result = FAIL;
  6899. time_t CurrentTime;
  6900. struct tm *tm;
  6901. system("/usr/bin/run_tmate_restart.sh");
  6902. pthread_t th_Status;
  6903. CurrentTime = time(NULL);
  6904. tm = localtime(&CurrentTime);
  6905. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  6906. sprintf((char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName, "%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);
  6907. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  6908. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6909. return result;
  6910. }
  6911. void* GetDiagnosticsProcess(void* data)
  6912. {
  6913. pthread_detach(pthread_self());
  6914. mtrace();
  6915. int retriesInt=0, retryIntervalInt=0;
  6916. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6917. 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};
  6918. int port=0;
  6919. int isSuccess = FALSE;
  6920. char ftpbuf[200]={0};
  6921. char cmdBuf[512];
  6922. json_object *GetDiagnostics;
  6923. DEBUG_INFO("GetDiagnosticsProcess...\n");
  6924. GetDiagnostics = json_tokener_parse(data);
  6925. if(!is_error(GetDiagnostics))
  6926. {
  6927. // Required data
  6928. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  6929. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  6930. // Optional data
  6931. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  6932. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  6933. else
  6934. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6935. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  6936. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  6937. else
  6938. retryIntervalInt = 30;
  6939. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  6940. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  6941. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  6942. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  6943. }
  6944. json_object_put(GetDiagnostics);
  6945. // Pack log to compress file
  6946. system("exec /root/logPackTools 'log' 6");
  6947. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  6948. system(cmdBuf);
  6949. checkUploadLog();
  6950. //****************location*******************/
  6951. if(strcmp(locationstr,"")==0)
  6952. {
  6953. DEBUG_INFO("location is <Empty>!\n");
  6954. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6955. goto end;
  6956. }
  6957. memset(protocol, 0, ARRAY_SIZE(protocol));
  6958. memset(user, 0, ARRAY_SIZE(user) );
  6959. memset(password, 0, ARRAY_SIZE(password));
  6960. memset(host, 0, ARRAY_SIZE(host));
  6961. memset(path, 0, ARRAY_SIZE(path));
  6962. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  6963. memset(host1, 0, ARRAY_SIZE(host1));
  6964. memset(path1, 0, ARRAY_SIZE(path1));
  6965. /*location: ftp://user:password@host:port/path*/
  6966. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6967. if((access(fnamePlusPath,F_OK))!=-1)
  6968. {
  6969. DEBUG_INFO("fnamePlusPath exist.\n");
  6970. }
  6971. else
  6972. {
  6973. DEBUG_INFO("fnamePlusPath not exist!\n");
  6974. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6975. goto end;
  6976. }
  6977. if(strchr(locationstr,'@')==NULL)
  6978. {
  6979. sscanf(locationstr,
  6980. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6981. protocol, host, &port, path);
  6982. strcpy(user,"anonymous");
  6983. strcpy(password,"");
  6984. }
  6985. else
  6986. {
  6987. //DEBUG_INFO("pch=%s\n", pch);
  6988. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6989. protocol, user, password, host, &port, path);
  6990. }
  6991. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6992. {
  6993. DEBUG_INFO("protocol is not ftp/http ! \n");
  6994. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6995. goto end;
  6996. }
  6997. if(strncmp(locationstr,"http", 4) == 0)
  6998. {
  6999. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  7000. sprintf(ftppath,"/%s", path);
  7001. do
  7002. {
  7003. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7004. sleep(3);
  7005. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  7006. if(!isSuccess)
  7007. {
  7008. DEBUG_INFO("Diagnostics fail.\n");
  7009. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7010. sleep(retryIntervalInt);
  7011. }
  7012. else
  7013. {
  7014. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7015. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7016. }
  7017. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  7018. }
  7019. else
  7020. {
  7021. sscanf(host,"%[^/]%s",host1, path1);
  7022. sprintf(ftppath,"%s", path1);
  7023. int ftppathlen=strlen(ftppath);
  7024. int i=1;
  7025. char filenametemp[50];
  7026. while(i < ftppathlen)
  7027. {
  7028. int len=ftppathlen-i;
  7029. if(ftppath[len]== 47) // '/' ascll code: 47
  7030. {
  7031. DEBUG_INFO("find '/' all right\n");
  7032. break;
  7033. }
  7034. i=i+1;
  7035. }
  7036. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  7037. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  7038. filenametemp[i+1] = 0;
  7039. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  7040. if(port == 0)
  7041. port = 21;
  7042. do
  7043. {
  7044. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7045. sleep(3);
  7046. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  7047. if(!isSuccess)
  7048. {
  7049. DEBUG_INFO("Diagnostics fail.\n");
  7050. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7051. sleep(retryIntervalInt);
  7052. }
  7053. else
  7054. {
  7055. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7056. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7057. }
  7058. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  7059. }
  7060. end:
  7061. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  7062. pthread_exit(NULL);
  7063. }
  7064. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  7065. {
  7066. mtrace();
  7067. int result = FAIL;
  7068. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  7069. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  7070. {
  7071. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  7072. localversion = -1;
  7073. }
  7074. else
  7075. {
  7076. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  7077. OCPP_getListVerion();
  7078. }
  7079. //from db.OCPP_getListVerion
  7080. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  7081. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  7082. sendGetLocalListVersionConfirmation(uuid,"");
  7083. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  7084. return result;
  7085. }
  7086. int handleRemoteStartRequest(char *uuid, char *payload)
  7087. {
  7088. mtrace();
  7089. int result = FAIL;
  7090. int connectorIdInt=0;
  7091. int tempIndex = 0;
  7092. int connectorIdIsNULL, chargingProfileIsNULL;
  7093. char comfirmstr[20]={0};
  7094. char cmdBuf[512];
  7095. json_object *RemoteStartTransaction;
  7096. FILE *fp;
  7097. DEBUG_INFO("handleRemoteStartRequest ...\n");
  7098. if(server_pending == TRUE)
  7099. {
  7100. return 0;
  7101. }
  7102. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  7103. RemoteStartTransaction = json_tokener_parse(payload);
  7104. if(!is_error(RemoteStartTransaction))
  7105. {
  7106. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  7107. {
  7108. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  7109. if(connectorIdInt <= gunTotalNumber)
  7110. {
  7111. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  7112. // Required data
  7113. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  7114. // Optional data
  7115. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  7116. {
  7117. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  7118. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  7119. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  7120. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  7121. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  7122. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  7123. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  7124. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  7125. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  7126. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  7127. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  7128. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  7129. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  7130. {
  7131. 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")));
  7132. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  7133. 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"));
  7134. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  7135. 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"));
  7136. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  7137. 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")));
  7138. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  7139. {
  7140. 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++)
  7141. {
  7142. 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"));
  7143. 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"));
  7144. 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)
  7145. 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"));
  7146. }
  7147. }
  7148. }
  7149. }
  7150. else
  7151. chargingProfileIsNULL = TRUE;
  7152. }
  7153. }
  7154. else
  7155. connectorIdIsNULL = TRUE;
  7156. }
  7157. else
  7158. connectorIdIsNULL = TRUE;
  7159. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  7160. {
  7161. DEBUG_WARN("Connector id is NULL\n.");
  7162. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7163. goto end;
  7164. }
  7165. /*
  7166. enum _SYSTEM_STATUS
  7167. {
  7168. S_BOOTING = 0,
  7169. S_IDLE, = 1
  7170. S_AUTHORIZING, = 2
  7171. S_REASSIGN_CHECK, = 3
  7172. S_REASSIGN, = 4
  7173. S_PRECHARGE, = 5
  7174. S_PREPARING_FOR_EV, = 6
  7175. S_PREPARING_FOR_EVSE, = 7
  7176. S_CHARGING, = 8
  7177. S_TERMINATING, = 9
  7178. S_COMPLETE, = 10
  7179. S_ALARM, = 11
  7180. S_FAULT = 12
  7181. }
  7182. */
  7183. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  7184. {
  7185. //check Transaction active
  7186. if(gunType[connectorIdInt -1] == 'J')
  7187. {
  7188. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7189. {
  7190. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7191. }
  7192. else
  7193. {
  7194. tempIndex = connectorIdInt -1;
  7195. }
  7196. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7197. {
  7198. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7199. {
  7200. 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))
  7201. {
  7202. //Reserved
  7203. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7204. }
  7205. 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))
  7206. {
  7207. //Reserved
  7208. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7209. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7210. goto end;
  7211. }
  7212. else
  7213. {
  7214. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7215. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7216. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7217. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7218. {
  7219. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  7220. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7221. goto end;
  7222. }
  7223. }//END FOR ELSE
  7224. }
  7225. }// END FOR CHAdeMO_QUANTITY
  7226. }
  7227. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7228. {
  7229. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7230. {
  7231. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7232. }
  7233. else
  7234. {
  7235. tempIndex = connectorIdInt -1;
  7236. }
  7237. for (int index = 0; index < CCS_QUANTITY; index++)
  7238. {
  7239. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7240. {
  7241. 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))
  7242. {
  7243. //Reserved
  7244. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7245. }
  7246. 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))
  7247. {
  7248. //Reserved
  7249. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7250. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7251. goto end;
  7252. }
  7253. else
  7254. {
  7255. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7256. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7257. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7258. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7259. {
  7260. DEBUG_WARN("CCS connector not allow start\n.");
  7261. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7262. goto end;
  7263. }
  7264. }// END FOR ELSE
  7265. }
  7266. }// END FOR CCS_QUANTITY
  7267. }
  7268. else if(gunType[connectorIdInt -1] == 'G')
  7269. {
  7270. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7271. {
  7272. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7273. }
  7274. else
  7275. {
  7276. tempIndex = connectorIdInt -1;
  7277. }
  7278. for (int index = 0; index < GB_QUANTITY; index++)
  7279. {
  7280. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7281. {
  7282. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7283. {
  7284. //Reserved
  7285. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7286. }
  7287. 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))
  7288. {
  7289. //Reserved
  7290. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7291. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7292. goto end;
  7293. }
  7294. else
  7295. {
  7296. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7297. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7298. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7299. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7300. {
  7301. DEBUG_WARN("GB connector not allow start\n.");
  7302. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7303. goto end;
  7304. }
  7305. }// END FOR ELSE
  7306. }
  7307. } // END FOR GB_QUANTITY
  7308. }
  7309. else if(gunType[connectorIdInt -1] == 'O')
  7310. {
  7311. tempIndex = connectorIdInt -1;
  7312. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7313. {
  7314. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  7315. {
  7316. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7317. {
  7318. //Reserved
  7319. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7320. }
  7321. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  7322. {
  7323. //Reserved
  7324. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7325. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7326. goto end;
  7327. }
  7328. else
  7329. {
  7330. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7331. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7332. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7333. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7334. {
  7335. DEBUG_WARN("GB connector not allow start\n.");
  7336. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7337. goto end;
  7338. }
  7339. }// END FOR ELSE
  7340. }
  7341. } // END FOR GB_QUANTITY
  7342. }
  7343. else
  7344. {
  7345. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7346. {
  7347. tempIndex = 2;
  7348. }
  7349. else
  7350. {
  7351. tempIndex = connectorIdInt -1;
  7352. }
  7353. for (int index = 0; index < AC_QUANTITY; index++)
  7354. {
  7355. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7356. {
  7357. 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))
  7358. {
  7359. //Reserved
  7360. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7361. }
  7362. 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))
  7363. {
  7364. //Reserved
  7365. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7366. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7367. goto end;
  7368. }
  7369. else
  7370. {
  7371. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7372. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7373. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7374. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7375. {
  7376. DEBUG_WARN("AC connector not allow start\n.");
  7377. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7378. goto end;
  7379. }
  7380. }//END FOR ELSE
  7381. }
  7382. }// END FOR AC_QUANTITY
  7383. }
  7384. if(chargingProfileIsNULL == FALSE)
  7385. {
  7386. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7387. {
  7388. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7389. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7390. //memset idTag
  7391. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7392. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7393. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7394. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7395. // Save profile to file
  7396. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7397. system(cmdBuf);
  7398. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7399. fp = fopen(cmdBuf, "w");
  7400. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  7401. fclose(fp);
  7402. }
  7403. else
  7404. {
  7405. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7406. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7407. }
  7408. }
  7409. else
  7410. {
  7411. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7412. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7413. //memset idTag
  7414. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7415. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7416. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7417. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7418. }
  7419. }
  7420. else
  7421. {
  7422. DEBUG_WARN("Connector id over\n.");
  7423. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7424. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7425. }
  7426. end:
  7427. json_object_put(RemoteStartTransaction);
  7428. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  7429. {
  7430. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7431. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7432. }
  7433. //OCPP send RemoteStartConfirmation by first.
  7434. sendRemoteStartConfirmation(uuid, comfirmstr);
  7435. return result;
  7436. }
  7437. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7438. {
  7439. mtrace();
  7440. int result = FAIL;
  7441. int match = FALSE;
  7442. int GunNO = 0;
  7443. int tempIndex = 0;
  7444. int transactionIdInt=0;
  7445. int transactionIdIsNULL= TRUE;
  7446. char comfirmstr[20];
  7447. json_object *RemoteStopTransaction;
  7448. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7449. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7450. if(server_pending == TRUE)
  7451. {
  7452. return 0;
  7453. }
  7454. RemoteStopTransaction = json_tokener_parse(payload);
  7455. if(!is_error(RemoteStopTransaction))
  7456. {
  7457. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  7458. {
  7459. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  7460. transactionIdIsNULL = FALSE;
  7461. }
  7462. }
  7463. json_object_put(RemoteStopTransaction);
  7464. if(transactionIdIsNULL == FALSE)
  7465. {
  7466. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7467. {
  7468. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7469. {
  7470. //check Transaction active
  7471. if(gunType[gun_index] == 'J')
  7472. {
  7473. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7474. {
  7475. tempIndex = ((gun_index==2) ? 1: 0);
  7476. }
  7477. else
  7478. {
  7479. tempIndex = gun_index;
  7480. }
  7481. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7482. {
  7483. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7484. {
  7485. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7486. {
  7487. match = TRUE;
  7488. GunNO = gun_index;
  7489. }
  7490. }
  7491. }// END FOR CHAdeMO_QUANTITY
  7492. }
  7493. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7494. {
  7495. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7496. {
  7497. tempIndex = ((gun_index==2) ? 1: 0);
  7498. }
  7499. else
  7500. {
  7501. tempIndex = gun_index;
  7502. }
  7503. for (int index = 0; index < CCS_QUANTITY; index++)
  7504. {
  7505. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7506. {
  7507. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7508. {
  7509. match = TRUE;
  7510. GunNO = gun_index;
  7511. }
  7512. }
  7513. }// END FOR CCS_QUANTITY
  7514. }
  7515. else if(gunType[gun_index] == 'G')
  7516. {
  7517. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7518. {
  7519. tempIndex = ((gun_index==2) ? 1: 0);
  7520. }
  7521. else
  7522. {
  7523. tempIndex = gun_index;
  7524. }
  7525. for (int index = 0; index < GB_QUANTITY; index++)
  7526. {
  7527. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7528. {
  7529. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7530. {
  7531. match = TRUE;
  7532. GunNO = gun_index;
  7533. }
  7534. }
  7535. }// END FOR GB_QUANTITY
  7536. }
  7537. else if(gunType[gun_index] == 'O')
  7538. {
  7539. tempIndex = gun_index;
  7540. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7541. {
  7542. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7543. {
  7544. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7545. {
  7546. match = TRUE;
  7547. GunNO = gun_index;
  7548. }
  7549. }
  7550. }// END FOR GB_QUANTITY
  7551. }
  7552. else
  7553. {
  7554. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7555. {
  7556. tempIndex = 2;
  7557. }
  7558. else
  7559. {
  7560. tempIndex = gun_index;
  7561. }
  7562. for (int index = 0; index < AC_QUANTITY; index++)
  7563. {
  7564. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7565. {
  7566. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7567. {
  7568. match = TRUE;
  7569. GunNO = gun_index;
  7570. }
  7571. }
  7572. }// END FOR CHAdeMO_QUANTITY
  7573. } // END FOR AC ELSE
  7574. }// CHECK IF ResponseTransactionId == transactionIdInt
  7575. }//END FOR
  7576. if( match == TRUE)
  7577. {
  7578. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7579. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7580. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7581. }
  7582. else
  7583. {
  7584. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7585. }
  7586. }
  7587. else
  7588. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7589. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7590. return result;
  7591. }
  7592. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7593. {
  7594. mtrace();
  7595. int result = FAIL;
  7596. int connectorIdInt=0, reservationIdInt=0;
  7597. int tempIndex = 0;
  7598. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7599. char comfirmstr[20]={0};
  7600. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7601. int c = 0;
  7602. char *loc;
  7603. //char *ptr;
  7604. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7605. strcpy(sstrtemp, stringtrimspace(payload));
  7606. //***(1)connectorId ****/
  7607. c=0;
  7608. loc = strstr(sstrtemp, "connectorId");
  7609. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7610. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7611. {
  7612. sstr[c] = loc[strlen("connectorId")+2+c];
  7613. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7614. c++;
  7615. }
  7616. sstr[c] = '\0';
  7617. connectorIdInt = atoi(sstr);
  7618. //***(2)expiryDate ****/
  7619. loc = strstr(sstrtemp, "expiryDate");
  7620. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7621. c = 0;
  7622. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7623. {
  7624. sstr[c] = loc[3+strlen("expiryDate")+c];
  7625. c++;
  7626. }
  7627. sstr[c] = '\0';
  7628. strcpy(expiryDatestr, sstr);
  7629. //***(3)idTag ****/
  7630. loc = strstr(sstrtemp, "idTag");
  7631. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7632. c = 0;
  7633. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7634. {
  7635. sstr[c] = loc[3+strlen("idTag")+c];
  7636. c++;
  7637. }
  7638. sstr[c] = '\0';
  7639. strcpy(idTagstr, sstr);
  7640. //***(4)parentIdTag ****/
  7641. loc = strstr(sstrtemp, "parentIdTag");
  7642. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7643. c = 0;
  7644. if(loc == NULL)
  7645. {
  7646. strcpy(parentIdTagstr, "");
  7647. }
  7648. else
  7649. {
  7650. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7651. {
  7652. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7653. c++;
  7654. }
  7655. sstr[c] = '\0';
  7656. strcpy(parentIdTagstr, sstr);
  7657. }
  7658. //***(5)reservationId ****/
  7659. c=0;
  7660. loc = strstr(sstrtemp, "reservationId");
  7661. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7662. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7663. {
  7664. sstr[c] = loc[strlen("reservationId")+2+c];
  7665. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7666. c++;
  7667. }
  7668. sstr[c] = '\0';
  7669. reservationIdInt = atoi(sstr);
  7670. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7671. /*
  7672. enum SYSTEM_STATUS
  7673. {
  7674. SYS_MODE_BOOTING = 0,
  7675. SYS_MODE_IDLE = 1,
  7676. SYS_MODE_AUTHORIZING = 2,
  7677. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7678. SYS_MODE_REASSIGN = 4,
  7679. SYS_MODE_PREPARING = 5,
  7680. SYS_MODE_PREPARE_FOR_EV = 6,
  7681. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7682. SYS_MODE_CHARGING = 8,
  7683. SYS_MODE_TERMINATING = 9,
  7684. SYS_MODE_COMPLETE = 10,
  7685. SYS_MODE_ALARM = 11,
  7686. SYS_MODE_FAULT = 12,
  7687. SYS_MODE_RESERVATION = 13,
  7688. SYS_MODE_BOOKING = 14,
  7689. SYS_MODE_MAINTAIN = 15,
  7690. SYS_MODE_DEBUG = 16,
  7691. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7692. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7693. SYS_MODE_UPDATE = 19
  7694. };
  7695. */
  7696. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7697. {
  7698. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7699. goto end;
  7700. }
  7701. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7702. {
  7703. //check Transaction active
  7704. if(gunType[connectorIdInt -1] == 'J')
  7705. {
  7706. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7707. {
  7708. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7709. }
  7710. else
  7711. {
  7712. tempIndex = connectorIdInt -1;
  7713. }
  7714. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7715. {
  7716. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7717. {
  7718. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7719. {
  7720. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7721. {
  7722. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7723. {
  7724. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7725. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7726. }
  7727. 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'))
  7728. {
  7729. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7730. }
  7731. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7732. {
  7733. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7734. }
  7735. else
  7736. {
  7737. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7738. }
  7739. }
  7740. 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
  7741. {
  7742. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7743. }
  7744. }
  7745. else
  7746. {
  7747. //replace reservation
  7748. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7749. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7750. }
  7751. }
  7752. } // END FOR CHAdeMO_QUANTITY
  7753. }
  7754. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7755. {
  7756. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7757. {
  7758. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7759. }
  7760. else
  7761. {
  7762. tempIndex = connectorIdInt -1;
  7763. }
  7764. for (int index = 0; index < CCS_QUANTITY; index++)
  7765. {
  7766. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7767. {
  7768. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7769. {
  7770. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7771. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7772. {
  7773. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7774. {
  7775. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7776. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7777. }
  7778. 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'))
  7779. {
  7780. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7781. }
  7782. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7783. {
  7784. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7785. }
  7786. else
  7787. {
  7788. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7789. }
  7790. }
  7791. 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
  7792. {
  7793. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7794. }
  7795. }
  7796. else
  7797. {
  7798. //replace reservation
  7799. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7800. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7801. }
  7802. }
  7803. } // END FOR CCS_QUANTITY
  7804. }
  7805. else if(gunType[connectorIdInt -1] == 'G')
  7806. {
  7807. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7808. {
  7809. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7810. }
  7811. else
  7812. {
  7813. tempIndex = connectorIdInt -1;
  7814. }
  7815. for (int index = 0; index < GB_QUANTITY; index++)
  7816. {
  7817. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7818. {
  7819. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7820. {
  7821. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7822. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7823. {
  7824. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7825. {
  7826. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7827. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7828. }
  7829. 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'))
  7830. {
  7831. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7832. }
  7833. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7834. {
  7835. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7836. }
  7837. else
  7838. {
  7839. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7840. }
  7841. }
  7842. 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
  7843. {
  7844. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7845. }
  7846. }
  7847. else
  7848. {
  7849. //replace reservation
  7850. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7851. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7852. }
  7853. }
  7854. }// END FOR GB_QUANTITY
  7855. }
  7856. else if(gunType[connectorIdInt -1] == 'O')
  7857. {
  7858. tempIndex = connectorIdInt -1;
  7859. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7860. {
  7861. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7862. {
  7863. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  7864. {
  7865. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7866. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7867. {
  7868. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7869. {
  7870. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7871. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7872. }
  7873. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  7874. {
  7875. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7876. }
  7877. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7878. {
  7879. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7880. }
  7881. else
  7882. {
  7883. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7884. }
  7885. }
  7886. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM ,SYS_MODE_TERMINATING ---> SuspendedEV
  7887. {
  7888. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7889. }
  7890. }
  7891. else
  7892. {
  7893. //replace reservation
  7894. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7895. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7896. }
  7897. }
  7898. }// END FOR GB_QUANTITY
  7899. }
  7900. else
  7901. {
  7902. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7903. {
  7904. tempIndex = 2;
  7905. }
  7906. else
  7907. {
  7908. tempIndex = (connectorIdInt -1);
  7909. }
  7910. for (int index = 0; index < AC_QUANTITY; index++)
  7911. {
  7912. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7913. {
  7914. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7915. {
  7916. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7917. {
  7918. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7919. {
  7920. 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))
  7921. {
  7922. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7923. }
  7924. else
  7925. {
  7926. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7927. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7928. }
  7929. }
  7930. 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'))
  7931. {
  7932. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7933. }
  7934. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7935. {
  7936. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7937. }
  7938. else
  7939. {
  7940. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7941. }
  7942. }
  7943. 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
  7944. {
  7945. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7946. }
  7947. }
  7948. else
  7949. {
  7950. //replace reservation
  7951. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7952. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7953. }
  7954. }
  7955. } // END FOR AC_QUANTITY
  7956. }
  7957. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7958. }
  7959. else if(connectorIdInt == 0)
  7960. {
  7961. //check Transaction active
  7962. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7963. {
  7964. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7965. {
  7966. 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'))
  7967. {
  7968. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7969. goto end;
  7970. }
  7971. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7972. {
  7973. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7974. goto end;
  7975. }
  7976. 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
  7977. {
  7978. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7979. goto end;
  7980. }
  7981. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7982. {
  7983. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7984. goto end;
  7985. }
  7986. }
  7987. }// END FOR CHAdeMO_QUANTITY
  7988. for (int index = 0; index < CCS_QUANTITY; index++)
  7989. {
  7990. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7991. {
  7992. 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'))
  7993. {
  7994. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7995. goto end;
  7996. }
  7997. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7998. {
  7999. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8000. goto end;
  8001. }
  8002. 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
  8003. {
  8004. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8005. goto end;
  8006. }
  8007. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8008. {
  8009. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8010. goto end;
  8011. }
  8012. }
  8013. } // END FOR CCS_QUANTITY
  8014. for (int index = 0; index < GB_QUANTITY; index++)
  8015. {
  8016. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8017. {
  8018. 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'))
  8019. {
  8020. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8021. goto end;
  8022. }
  8023. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8024. {
  8025. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8026. goto end;
  8027. }
  8028. 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
  8029. {
  8030. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8031. goto end;
  8032. }
  8033. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8034. {
  8035. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8036. goto end;
  8037. }
  8038. }
  8039. } // END FOR GB_QUANTITY
  8040. for (int index = 0; index < AC_QUANTITY; index++)
  8041. {
  8042. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8043. {
  8044. 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'))
  8045. {
  8046. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8047. goto end;
  8048. }
  8049. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8050. {
  8051. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8052. goto end;
  8053. }
  8054. 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
  8055. {
  8056. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8057. goto end;
  8058. }
  8059. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8060. {
  8061. 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))
  8062. {
  8063. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8064. goto end;
  8065. }
  8066. }
  8067. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8068. {
  8069. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8070. goto end;
  8071. }
  8072. }
  8073. }// END FOR AC_QUANTITY
  8074. //The connectorId is 0
  8075. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  8076. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8077. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  8078. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  8079. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  8080. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  8081. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  8082. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  8083. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  8084. result = TRUE;
  8085. return result;
  8086. }
  8087. else
  8088. {
  8089. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8090. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8091. }
  8092. if(strcmp(comfirmstr,"Accepted") == 0)
  8093. {
  8094. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  8095. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  8096. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  8097. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  8098. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  8099. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  8100. result = TRUE;
  8101. return result;
  8102. }
  8103. end:
  8104. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  8105. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  8106. return result;
  8107. }
  8108. int handleResetRequest(char *uuid, char *payload)
  8109. {
  8110. mtrace();
  8111. int result = FAIL;
  8112. char sstr[10]={0},sstrtemp[30]={ 0 };
  8113. char typestr[10]={0};
  8114. char comfirmstr[20]={0};
  8115. int c = 0;
  8116. char *loc;
  8117. DEBUG_INFO("handleResetRequest...\n");
  8118. strcpy(sstrtemp, stringtrimspace(payload));
  8119. loc = strstr(sstrtemp, "type");
  8120. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8121. c = 0;
  8122. while (loc[3+strlen("type")+c] != '\"')
  8123. {
  8124. sstr[c] = loc[3+strlen("type")+c];
  8125. c++;
  8126. }
  8127. sstr[c] = '\0';
  8128. strcpy(typestr,sstr);
  8129. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  8130. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  8131. {
  8132. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  8133. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  8134. result = TRUE;
  8135. return result;
  8136. }
  8137. else
  8138. {
  8139. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  8140. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  8141. goto errorend;
  8142. }
  8143. errorend:
  8144. sendResetConfirmation(uuid, comfirmstr);
  8145. return result;
  8146. }
  8147. int handleSendLocalListRequest(char *uuid, char *payload)
  8148. {
  8149. mtrace();
  8150. int result = FAIL;
  8151. int listVersionInt;
  8152. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  8153. char listsearch[]="listVersion";
  8154. char updateTypesearch[]="updateType";
  8155. char localAuthorizationListsearch[]="localAuthorizationList";
  8156. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  8157. char CardList[500][160]={0};
  8158. char updateTypestr[15]={0};
  8159. char idTagstr[20]={0};
  8160. char parentIdTag[20]={0};
  8161. char expiryDate[30]={0};
  8162. char idTagstatus[16]={0};
  8163. int c = 0;
  8164. int i = 0;
  8165. char *delim1 = "}";
  8166. char * pch;
  8167. char *loc;
  8168. //char *ptr;
  8169. char comfirmstr[20];
  8170. //int n_localAuthorizations = 0;
  8171. int checkState_Faulted = FALSE;
  8172. DEBUG_INFO("handleSendLocalListRequest...\n");
  8173. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  8174. {
  8175. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8176. goto end;
  8177. }
  8178. //check Charge Point state
  8179. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8180. {
  8181. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8182. {
  8183. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8184. }
  8185. }
  8186. for (int index = 0; index < CCS_QUANTITY; index++)
  8187. {
  8188. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8189. {
  8190. checkState_Faulted = TRUE; //OCPP Status
  8191. }
  8192. }
  8193. for (int index = 0; index < GB_QUANTITY; index++)
  8194. {
  8195. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8196. {
  8197. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8198. }
  8199. }
  8200. //check Charge Point state
  8201. for (int index = 0; index < AC_QUANTITY; index++)
  8202. {
  8203. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8204. {
  8205. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8206. }
  8207. }
  8208. if(checkState_Faulted == TRUE)
  8209. {
  8210. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8211. goto end;
  8212. }
  8213. //Filter payload space
  8214. strcpy(sstrtemp, stringtrimspace(payload));
  8215. //listVersion
  8216. c = 0;
  8217. loc = strstr(sstrtemp, listsearch);
  8218. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8219. {
  8220. sstr[c] = loc[strlen("listVersion")+2+c];
  8221. c++;
  8222. }
  8223. sstr[c] = '\0';
  8224. listVersionInt = atoi(sstr);
  8225. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8226. //updateType
  8227. loc = strstr(sstrtemp, updateTypesearch);
  8228. c = 0;
  8229. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8230. {
  8231. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8232. c++;
  8233. }
  8234. sstr[c] = '\0';
  8235. strcpy(updateTypestr, sstr);
  8236. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8237. //localAuthorizationList
  8238. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8239. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8240. if(loc != NULL) // localAuthorizationList is not NULL
  8241. {
  8242. //Check UpdateType
  8243. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8244. {
  8245. //Local list full update
  8246. printf("Local list full update.\n");
  8247. OCPP_getListVerion();
  8248. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8249. {
  8250. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8251. goto end;
  8252. }
  8253. OCPP_cleanLocalList();
  8254. }
  8255. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8256. {
  8257. //Local list different update
  8258. printf("Local list different update.\n");
  8259. OCPP_getListVerion();
  8260. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8261. {
  8262. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8263. goto end;
  8264. }
  8265. }
  8266. else
  8267. {
  8268. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8269. goto end;
  8270. }
  8271. c = 0;
  8272. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8273. {
  8274. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8275. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8276. c++;
  8277. }
  8278. sstr[c] = '\0';
  8279. //DEBUG_INFO("sstr=%s\n", sstr);
  8280. //parsing strings to words
  8281. i = 0;
  8282. pch = strtok(sstr,delim1);
  8283. while (pch != NULL)
  8284. {
  8285. strcpy(CardList[i], pch);
  8286. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8287. pch = strtok (NULL, delim1);
  8288. i = i + 1;
  8289. }
  8290. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8291. //local Authorizations List Numbers
  8292. //n_localAuthorizations = i;
  8293. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8294. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8295. c= 0;
  8296. while(c < i) // i is CardList Number
  8297. {
  8298. //Search "IdToken"
  8299. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8300. loc = strstr(CardList[c], "idTag");
  8301. int j = 0;
  8302. while (loc[3+strlen("idTag")+j] != '\"')
  8303. {
  8304. sstr[j] = loc[3+strlen("idTag")+j];
  8305. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8306. j++;
  8307. }
  8308. sstr[j] = '\0';
  8309. strcpy(idTagstr, sstr);
  8310. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8311. //Search "expiryDate"
  8312. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8313. loc = strstr(CardList[c], "expiryDate");
  8314. j = 0;
  8315. if(loc != NULL)
  8316. {
  8317. while (loc[3+strlen("expiryDate")+j] != '\"')
  8318. {
  8319. sstr[j] = loc[3+strlen("expiryDate")+j];
  8320. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8321. j++;
  8322. }
  8323. sstr[j] = '\0';
  8324. strcpy(expiryDate, sstr);
  8325. }
  8326. else
  8327. {
  8328. strcpy(expiryDate, "");
  8329. }
  8330. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8331. //Search "parentIdTag"
  8332. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8333. loc = strstr(CardList[c], "parentIdTag");
  8334. j = 0;
  8335. if(loc != NULL)
  8336. {
  8337. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8338. {
  8339. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8340. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8341. j++;
  8342. }
  8343. sstr[j] = '\0';
  8344. strcpy(parentIdTag, sstr);
  8345. }
  8346. else
  8347. {
  8348. strcpy(parentIdTag, "");
  8349. }
  8350. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8351. //Search "status"
  8352. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8353. loc = strstr(CardList[c], "status");
  8354. j = 0;
  8355. while (loc[3+strlen("status")+j] != '\"')
  8356. {
  8357. sstr[j] = loc[3+strlen("status")+j];
  8358. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8359. j++;
  8360. }
  8361. sstr[j] = '\0';
  8362. strcpy(idTagstatus, sstr);
  8363. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8364. OCPP_getIdTag(idTagstr);
  8365. //OCPP_getIdTag("test"); For Test
  8366. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8367. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8368. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8369. {
  8370. //Local list full update
  8371. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8372. // update list
  8373. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8374. //DEBUG_INFO("Local list full update. 1\n");
  8375. //OCPP_get_TableAuthlocalAllData();
  8376. //DEBUG_INFO("Local list full update. 2\n");
  8377. }
  8378. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8379. {
  8380. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8381. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8382. }
  8383. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8384. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8385. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8386. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8387. c++;
  8388. }
  8389. }
  8390. else
  8391. {
  8392. //Check UpdateType
  8393. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8394. {
  8395. //Local list full update
  8396. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8397. OCPP_cleanLocalList();
  8398. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8399. goto end;
  8400. }
  8401. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8402. {
  8403. //Local list different update
  8404. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8405. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8406. goto end;
  8407. }
  8408. }
  8409. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8410. end:
  8411. sendSendLocalListConfirmation(uuid, comfirmstr);
  8412. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8413. return result;
  8414. }
  8415. #define MAX 200
  8416. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8417. {
  8418. mtrace();
  8419. int result = FAIL;
  8420. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8421. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8422. char chargingProfilePurposeStr[30]={0};
  8423. char chargingProfileKindStr[16]={0};
  8424. char recurrencyKindStr[10]={0};
  8425. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8426. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8427. int chargingSchedulePeriodCount = 0;
  8428. char comfirmstr[20]={0};
  8429. int meet= FALSE;
  8430. FILE *fptr1;
  8431. char filename[MAX]={0};
  8432. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8433. char rmFileCmd[50]={0};
  8434. char tempchargingProfilePurposeStr[30]={0};
  8435. char word[1600]={0};
  8436. int n_chargingProfile = 0;
  8437. json_object *SetChargingProfile;
  8438. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8439. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8440. SetChargingProfile = json_tokener_parse(payload);
  8441. if(!is_error(SetChargingProfile))
  8442. {
  8443. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  8444. {
  8445. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  8446. if(connectorIdInt == 0)
  8447. {
  8448. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  8449. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8450. }
  8451. else
  8452. {
  8453. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  8454. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  8455. }
  8456. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  8457. }
  8458. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  8459. {
  8460. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  8461. {
  8462. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  8463. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8464. {
  8465. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8466. }
  8467. else
  8468. {
  8469. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8470. }
  8471. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  8472. }
  8473. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  8474. {
  8475. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  8476. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8477. {
  8478. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8479. }
  8480. else
  8481. {
  8482. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8483. }
  8484. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  8485. }
  8486. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8487. {
  8488. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  8489. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8490. {
  8491. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8492. }
  8493. else
  8494. {
  8495. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8496. }
  8497. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  8498. }
  8499. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  8500. {
  8501. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  8502. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8503. {
  8504. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8505. }
  8506. else
  8507. {
  8508. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8509. }
  8510. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  8511. }
  8512. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  8513. {
  8514. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  8515. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8516. {
  8517. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8518. }
  8519. else
  8520. {
  8521. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8522. }
  8523. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  8524. }
  8525. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  8526. {
  8527. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  8528. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8529. {
  8530. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8531. }
  8532. else
  8533. {
  8534. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8535. }
  8536. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  8537. }
  8538. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  8539. {
  8540. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  8541. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8542. {
  8543. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8544. }
  8545. else
  8546. {
  8547. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8548. }
  8549. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  8550. }
  8551. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  8552. {
  8553. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  8554. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8555. {
  8556. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8557. }
  8558. else
  8559. {
  8560. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8561. }
  8562. //DEBUG_INFO("validToStr: %s\n", validToStr);
  8563. }
  8564. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  8565. {
  8566. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  8567. {
  8568. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  8569. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8570. {
  8571. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8572. }
  8573. else
  8574. {
  8575. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8576. }
  8577. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  8578. }
  8579. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  8580. {
  8581. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  8582. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8583. {
  8584. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8585. }
  8586. else
  8587. {
  8588. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8589. }
  8590. //DEBUG_INFO("durationInt: %d\n", durationInt);
  8591. }
  8592. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  8593. {
  8594. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  8595. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8596. {
  8597. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8598. }
  8599. else
  8600. {
  8601. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8602. }
  8603. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  8604. }
  8605. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  8606. {
  8607. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  8608. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8609. {
  8610. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8611. }
  8612. else
  8613. {
  8614. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8615. }
  8616. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  8617. }
  8618. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8619. {
  8620. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  8621. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  8622. if(chargingSchedulePeriodCount <= 10)
  8623. {
  8624. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  8625. {
  8626. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod") != NULL)
  8627. {
  8628. startPeriodInt[idxPeriod] = 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(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  8629. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8630. {
  8631. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8632. }
  8633. else
  8634. {
  8635. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8636. }
  8637. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  8638. }
  8639. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit") != NULL)
  8640. {
  8641. limitflaot[idxPeriod] = 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(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  8642. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8643. {
  8644. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8645. }
  8646. else
  8647. {
  8648. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8649. }
  8650. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  8651. }
  8652. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  8653. {
  8654. numberPhasesInt[idxPeriod] = 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(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  8655. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8656. {
  8657. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8658. }
  8659. else
  8660. {
  8661. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8662. }
  8663. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  8664. }
  8665. }
  8666. }
  8667. }
  8668. }
  8669. }
  8670. }
  8671. json_object_put(SetChargingProfile);
  8672. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8673. {
  8674. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8675. goto end;
  8676. }
  8677. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8678. {
  8679. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8680. if(connectorIdInt != 0)
  8681. {
  8682. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8683. goto end;
  8684. }
  8685. strcpy(filename, ChargePointMaxProfile_JSON );
  8686. fptr1 = fopen(filename, "r");
  8687. if (!fptr1)
  8688. {
  8689. //file not exist
  8690. DEBUG_INFO("Unable to open the input file!!\n");
  8691. fptr1 = fopen(filename, "w+");
  8692. }
  8693. else
  8694. {
  8695. //Check Charging Profile Count
  8696. while(fscanf(fptr1, "%s", word) != EOF)
  8697. {
  8698. //DEBUG_INFO("word=%s\n",word);
  8699. if(strstr(word, "chargingProfileId")!= NULL)
  8700. {
  8701. //DEBUG_INFO("test chargingProfileId \n");
  8702. n_chargingProfile = n_chargingProfile + 1;
  8703. //DEBUG_INFO("chargingProfileId Found\n");
  8704. }
  8705. }
  8706. }
  8707. fclose(fptr1);
  8708. }
  8709. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8710. {
  8711. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8712. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8713. {
  8714. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8715. goto end;
  8716. }
  8717. memset(filename, 0, ARRAY_SIZE(filename));
  8718. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8719. fptr1 = fopen(filename, "r");
  8720. if (!fptr1)
  8721. {
  8722. //file not exist
  8723. //DEBUG_INFO("Unable to open the input file!!\n");
  8724. fptr1 = fopen(filename, "w+");
  8725. }
  8726. else
  8727. {
  8728. //Check Charging Profile Count
  8729. while(fscanf(fptr1, "%s", word) != EOF)
  8730. {
  8731. //DEBUG_INFO("word=%s\n",word);
  8732. if(strstr(word, "chargingProfileId")!= NULL)
  8733. {
  8734. //DEBUG_INFO("test chargingProfileId \n");
  8735. n_chargingProfile = n_chargingProfile + 1;
  8736. //DEBUG_INFO("chargingProfileId Found\n");
  8737. }
  8738. }
  8739. }
  8740. fclose(fptr1);
  8741. }
  8742. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8743. {
  8744. //printf("set chargingProfile 1-4\n");
  8745. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8746. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8747. if(connectorIdInt == 0)
  8748. {
  8749. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8750. goto end;
  8751. }
  8752. int tempIndex = 0;
  8753. //check Transaction active
  8754. if(gunType[connectorIdInt -1] == 'J')
  8755. {
  8756. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8757. {
  8758. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8759. }
  8760. else
  8761. {
  8762. tempIndex = connectorIdInt -1;
  8763. }
  8764. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8765. {
  8766. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8767. {
  8768. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8769. {
  8770. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8771. {
  8772. meet = TRUE;
  8773. break;
  8774. }
  8775. }
  8776. }
  8777. }
  8778. }
  8779. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8780. {
  8781. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8782. {
  8783. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8784. }
  8785. else
  8786. {
  8787. tempIndex = connectorIdInt -1;
  8788. }
  8789. for (int index = 0; index < CCS_QUANTITY; index++)
  8790. {
  8791. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8792. {
  8793. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8794. {
  8795. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8796. {
  8797. meet = TRUE;
  8798. break;
  8799. }
  8800. }
  8801. }
  8802. }
  8803. }
  8804. else if(gunType[connectorIdInt -1] == 'G')
  8805. {
  8806. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8807. {
  8808. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8809. }
  8810. else
  8811. {
  8812. tempIndex = connectorIdInt -1;
  8813. }
  8814. for (int index = 0; index < GB_QUANTITY; index++)
  8815. {
  8816. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8817. {
  8818. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8819. {
  8820. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8821. {
  8822. meet = TRUE;
  8823. break;
  8824. }
  8825. }
  8826. }
  8827. }
  8828. }
  8829. else if(gunType[connectorIdInt -1] == 'O')
  8830. {
  8831. tempIndex = connectorIdInt -1;
  8832. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8833. {
  8834. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8835. {
  8836. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8837. {
  8838. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8839. {
  8840. meet = TRUE;
  8841. break;
  8842. }
  8843. }
  8844. }
  8845. }
  8846. }
  8847. else
  8848. {
  8849. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8850. {
  8851. tempIndex = 2;
  8852. }
  8853. else
  8854. {
  8855. tempIndex = (connectorIdInt -1);
  8856. }
  8857. for (int index = 0; index < AC_QUANTITY; index++)
  8858. {
  8859. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8860. {
  8861. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8862. {
  8863. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8864. {
  8865. meet = TRUE;
  8866. break;
  8867. }
  8868. }
  8869. }
  8870. }
  8871. }
  8872. //check Transaction active
  8873. if(meet == FALSE)
  8874. {
  8875. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8876. goto end;
  8877. }
  8878. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8879. {
  8880. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8881. goto end;
  8882. }
  8883. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8884. fptr1 = fopen(filename, "r");
  8885. if (!fptr1)
  8886. {
  8887. //file not exist
  8888. DEBUG_INFO("Unable to open the input file!!\n");
  8889. fptr1 = fopen(filename, "w+");
  8890. }
  8891. else
  8892. {
  8893. //Check Charging Profile Count
  8894. while(fscanf(fptr1, "%s", word) != EOF)
  8895. {
  8896. //DEBUG_INFO("word=%s\n",word);
  8897. if(strstr(word, "chargingProfileId")!= NULL)
  8898. {
  8899. //DEBUG_INFO("test chargingProfileId \n");
  8900. n_chargingProfile = n_chargingProfile + 1;
  8901. //DEBUG_INFO("chargingProfileId Found\n");
  8902. }
  8903. }
  8904. }
  8905. fclose(fptr1);
  8906. }
  8907. // Check ChargeProfileMaxStackLevel
  8908. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8909. {
  8910. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8911. goto end;
  8912. }
  8913. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8914. {
  8915. int i = 0;
  8916. char fnametemp[200]={0};
  8917. n_chargingProfile = 0;
  8918. //Check ChargePointMaxProfile.json exit
  8919. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8920. {
  8921. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8922. //Check Charging Profile Count
  8923. while(fscanf(fptr1, "%s", word) != EOF)
  8924. {
  8925. //DEBUG_INFO("word=%s\n",word);
  8926. if(strstr(word, "chargingProfileId")!= NULL)
  8927. {
  8928. //DEBUG_INFO("test chargingProfileId \n");
  8929. n_chargingProfile = n_chargingProfile + 1;
  8930. i = i + 1;
  8931. //DEBUG_INFO("chargingProfileId Found\n");
  8932. }
  8933. memset(word, 0, ARRAY_SIZE(word));
  8934. }
  8935. fclose(fptr1);
  8936. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8937. }
  8938. //Check TxDefaultProfile_0.json exit
  8939. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8940. {
  8941. i = 0;
  8942. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8943. //Check Charging Profile Count
  8944. while(fscanf(fptr1, "%s", word) != EOF)
  8945. {
  8946. //DEBUG_INFO("word=%s\n",word);
  8947. if(strstr(word, "chargingProfileId")!= NULL)
  8948. {
  8949. //DEBUG_INFO("test chargingProfileId \n");
  8950. n_chargingProfile = n_chargingProfile + 1;
  8951. i = i + 1;
  8952. //DEBUG_INFO("chargingProfileId Found\n");
  8953. }
  8954. memset(word, 0, ARRAY_SIZE(word));
  8955. }
  8956. fclose(fptr1);
  8957. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8958. }
  8959. //Check TxDefaultProfile_%d.json
  8960. for(int j=1; j <= gunTotalNumber; j++)
  8961. {
  8962. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8963. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8964. if((access(fnametemp,F_OK))!=-1)
  8965. {
  8966. i = 0;
  8967. fptr1 = fopen(fnametemp, "r");
  8968. //Check Charging Profile Count
  8969. while(fscanf(fptr1, "%s", word) != EOF)
  8970. {
  8971. //DEBUG_INFO("word=%s\n",word);
  8972. if(strstr(word, "chargingProfileId")!= NULL)
  8973. {
  8974. //DEBUG_INFO("test chargingProfileId \n");
  8975. n_chargingProfile = n_chargingProfile + 1;
  8976. i = i + 1;
  8977. //DEBUG_INFO("chargingProfileId Found\n");
  8978. }
  8979. memset(word, 0, ARRAY_SIZE(word));
  8980. }
  8981. fclose(fptr1);
  8982. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8983. }
  8984. }
  8985. //Check TxProfile_%d.json
  8986. for(int j=1; j <= gunTotalNumber; j++)
  8987. {
  8988. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8989. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8990. if((access(fnametemp,F_OK))!=-1)
  8991. {
  8992. i = 0;
  8993. fptr1 = fopen(fnametemp, "r");
  8994. //Check Charging Profile Count
  8995. while(fscanf(fptr1, "%s", word) != EOF)
  8996. {
  8997. //DEBUG_INFO("word=%s\n",word);
  8998. if(strstr(word, "chargingProfileId")!= NULL)
  8999. {
  9000. //DEBUG_INFO("test chargingProfileId \n");
  9001. n_chargingProfile = n_chargingProfile + 1;
  9002. i = i + 1;
  9003. //DEBUG_INFO("chargingProfileId Found\n");
  9004. }
  9005. memset(word, 0, ARRAY_SIZE(word));
  9006. }
  9007. fclose(fptr1);
  9008. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9009. }
  9010. }
  9011. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9012. {
  9013. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9014. goto end;
  9015. }
  9016. }
  9017. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9018. //**********************************Write to File********************************************************/
  9019. FILE *infile;
  9020. FILE *outfile;
  9021. infile = fopen (filename, "r");
  9022. outfile = fopen (tempfile, "w");
  9023. int d =0;
  9024. d = fgetc(infile);
  9025. rewind(infile);
  9026. if(d == EOF)
  9027. {
  9028. // Profile is empty
  9029. fprintf(outfile,"%s\n",payload);
  9030. fclose(infile);
  9031. fclose(outfile);
  9032. sprintf(rmFileCmd,"rm -f %s",filename);
  9033. system(rmFileCmd);
  9034. rename(tempfile, filename);
  9035. }
  9036. else
  9037. {
  9038. // Profile is not empty
  9039. char buf[2048]={0};
  9040. int ChargingProfileAdded = FALSE;
  9041. while (fgets(buf, sizeof(buf), infile) != NULL)
  9042. {
  9043. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9044. json_object *tmpChargingProfile;
  9045. tmpChargingProfile = json_tokener_parse(buf);
  9046. if(!is_error(SetChargingProfile))
  9047. {
  9048. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  9049. {
  9050. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  9051. }
  9052. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  9053. {
  9054. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9055. {
  9056. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9057. }
  9058. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9059. {
  9060. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  9061. }
  9062. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9063. {
  9064. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9065. }
  9066. }
  9067. }
  9068. json_object_put(tmpChargingProfile);
  9069. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9070. {
  9071. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9072. {
  9073. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9074. if(ChargingProfileAdded == FALSE)
  9075. {
  9076. fprintf(outfile,"%s\n",payload);
  9077. ChargingProfileAdded = TRUE;
  9078. }
  9079. }
  9080. else
  9081. {
  9082. if(tempstackLevelInt < stackLevelInt)
  9083. {
  9084. if(ChargingProfileAdded == FALSE)
  9085. {
  9086. fprintf(outfile,"%s\n",buf);
  9087. fprintf(outfile,"%s\n",payload);
  9088. ChargingProfileAdded = TRUE;
  9089. }
  9090. else
  9091. {
  9092. fprintf(outfile,"%s\n",buf);
  9093. }
  9094. }
  9095. else
  9096. {
  9097. if(ChargingProfileAdded == FALSE)
  9098. {
  9099. fprintf(outfile,"%s\n",buf);
  9100. fprintf(outfile,"%s\n",payload);
  9101. ChargingProfileAdded = TRUE;
  9102. }
  9103. else
  9104. {
  9105. fprintf(outfile,"%s\n",buf);
  9106. }
  9107. }
  9108. }
  9109. }
  9110. else
  9111. {
  9112. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9113. {
  9114. if(ChargingProfileAdded == FALSE)
  9115. {
  9116. fprintf(outfile,"%s\n",buf);
  9117. fprintf(outfile,"%s\n",payload);
  9118. ChargingProfileAdded = TRUE;
  9119. }
  9120. else
  9121. {
  9122. fprintf(outfile,"%s\n",buf);
  9123. }
  9124. }
  9125. else if(tempstackLevelInt < stackLevelInt)
  9126. {
  9127. if(ChargingProfileAdded == FALSE)
  9128. {
  9129. fprintf(outfile,"%s\n",buf);
  9130. fprintf(outfile,"%s\n",payload);
  9131. ChargingProfileAdded = TRUE;
  9132. }
  9133. else
  9134. {
  9135. fprintf(outfile,"%s\n",buf);
  9136. }
  9137. }
  9138. else
  9139. {
  9140. if(ChargingProfileAdded == FALSE)
  9141. {
  9142. fprintf(outfile,"%s\n",buf);
  9143. fprintf(outfile,"%s\n",payload);
  9144. ChargingProfileAdded = TRUE;
  9145. }
  9146. else
  9147. {
  9148. fprintf(outfile,"%s\n",buf);
  9149. }
  9150. }
  9151. }
  9152. } // end of while loop
  9153. fclose(infile);
  9154. fclose(outfile);
  9155. sprintf(rmFileCmd,"rm -f %s",filename);
  9156. system(rmFileCmd);
  9157. rename(tempfile, filename);
  9158. }
  9159. sleep(1);
  9160. result = TRUE;
  9161. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9162. end:
  9163. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  9164. {
  9165. if(connectorIdInt == 0)
  9166. {
  9167. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9168. {
  9169. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx]);
  9170. }
  9171. }
  9172. else
  9173. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1]);
  9174. }
  9175. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9176. return result;
  9177. }
  9178. int handleTriggerMessageRequest(char *uuid, char *payload)
  9179. {
  9180. mtrace();
  9181. int result = FAIL;
  9182. int connectorIdIsNULL = FALSE;
  9183. int connectorIdInt =0;
  9184. char sstr[40]={0},sstrtemp[100]={ 0 };
  9185. char requestedMessagestr[40]={0};
  9186. char comfirmstr[20]={0};
  9187. int c = 0;
  9188. char *loc;
  9189. DEBUG_INFO("handleTriggerMessageRequest\n");
  9190. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9191. strcpy(sstrtemp, stringtrimspace(payload));
  9192. c = 0;
  9193. loc = strstr(sstrtemp, "requestedMessage");
  9194. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9195. {
  9196. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9197. c++;
  9198. }
  9199. sstr[c] = '\0';
  9200. strcpy(requestedMessagestr, sstr);
  9201. c = 0;
  9202. loc = strstr(sstrtemp, "connectorId");
  9203. if(loc == NULL)
  9204. {
  9205. connectorIdIsNULL = TRUE;
  9206. }
  9207. else
  9208. {
  9209. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9210. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9211. {
  9212. sstr[c] = loc[strlen("connectorId")+2+c];
  9213. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9214. c++;
  9215. }
  9216. sstr[c] = '\0';
  9217. connectorIdInt = atoi(sstr);
  9218. }
  9219. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  9220. {
  9221. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9222. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9223. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9224. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9225. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9226. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9227. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9228. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9229. {
  9230. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9231. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9232. return TRUE;
  9233. }
  9234. else
  9235. {
  9236. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9237. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9238. }
  9239. }
  9240. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9241. {
  9242. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9243. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9244. return TRUE;
  9245. }
  9246. //==========================
  9247. // Trigger message
  9248. //==========================
  9249. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9250. {
  9251. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9252. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9253. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9254. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9255. {
  9256. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9257. }
  9258. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9259. }
  9260. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9261. {
  9262. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9263. }
  9264. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9265. {
  9266. //sendBootNotificationRequest();
  9267. server_sign = FALSE;
  9268. }
  9269. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9270. {
  9271. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9272. }
  9273. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9274. {
  9275. if(connectorIdIsNULL == FALSE)
  9276. {
  9277. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9278. {
  9279. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9280. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  9281. }
  9282. }
  9283. else
  9284. {
  9285. for(int idx=0;idx< gunTotalNumber;idx++)
  9286. {
  9287. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9288. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  9289. }
  9290. }
  9291. }
  9292. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9293. {
  9294. if(connectorIdIsNULL == FALSE)
  9295. {
  9296. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9297. {
  9298. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9299. }
  9300. }
  9301. else
  9302. {
  9303. for(int idx=0;idx< gunTotalNumber;idx++)
  9304. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9305. }
  9306. }
  9307. return result;
  9308. }
  9309. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9310. {
  9311. mtrace();
  9312. int result = FAIL;
  9313. int connectorIdInt =0;
  9314. char comfirmstr[20]={0};
  9315. int tempIndex = 0;
  9316. json_object *UnlockConnector;
  9317. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9318. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9319. UnlockConnector = json_tokener_parse(payload);
  9320. if(!is_error(UnlockConnector))
  9321. {
  9322. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  9323. {
  9324. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  9325. }
  9326. }
  9327. json_object_put(UnlockConnector);
  9328. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  9329. if(gunTotalNumber == 0)
  9330. {
  9331. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9332. goto end;
  9333. }
  9334. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9335. {
  9336. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9337. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9338. goto end;
  9339. }
  9340. else
  9341. {
  9342. //check Transaction active
  9343. if(gunType[connectorIdInt-1] == 'J')
  9344. {
  9345. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9346. {
  9347. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9348. }
  9349. else
  9350. {
  9351. tempIndex = connectorIdInt -1;
  9352. }
  9353. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9354. {
  9355. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9356. {
  9357. //stop Transaction
  9358. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9359. }
  9360. }
  9361. }
  9362. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9363. {
  9364. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9365. {
  9366. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9367. }
  9368. else
  9369. {
  9370. tempIndex = connectorIdInt -1;
  9371. }
  9372. for (int index = 0; index < CCS_QUANTITY; index++)
  9373. {
  9374. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9375. {
  9376. //stop Transaction
  9377. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9378. }
  9379. }
  9380. }
  9381. else if(gunType[connectorIdInt-1] == 'G')
  9382. {
  9383. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9384. {
  9385. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9386. }
  9387. else
  9388. {
  9389. tempIndex = connectorIdInt -1;
  9390. }
  9391. for (int index = 0; index < GB_QUANTITY; index++)
  9392. {
  9393. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9394. {
  9395. //stop Transaction
  9396. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9397. }
  9398. }
  9399. }
  9400. else if(gunType[connectorIdInt-1] == 'O')
  9401. {
  9402. tempIndex = connectorIdInt -1;
  9403. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9404. {
  9405. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)))
  9406. {
  9407. //stop Transaction
  9408. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9409. }
  9410. }
  9411. }
  9412. else
  9413. {
  9414. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9415. {
  9416. tempIndex = 2;
  9417. }
  9418. else
  9419. {
  9420. tempIndex = connectorIdInt-1;
  9421. }
  9422. for (int index = 0; index < AC_QUANTITY; index++)
  9423. {
  9424. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9425. {
  9426. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9427. }
  9428. }
  9429. }
  9430. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9431. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9432. result = TRUE;
  9433. return result;
  9434. }
  9435. end:
  9436. //json_object_put(obj); --- remove temporally
  9437. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9438. return result;
  9439. }
  9440. static char UpdateFirmwarepayloadData[300]={0};
  9441. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9442. {
  9443. mtrace();
  9444. int result = FAIL;
  9445. pthread_t t;
  9446. sendUpdateFirmwareConfirmation(uuid);
  9447. memset(UpdateFirmwarepayloadData, 0, 300);
  9448. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9449. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9450. ////pthread_join(t, NULL); //
  9451. //pthread_detach(t);
  9452. //sendUpdateFirmwareConfirmation(uuid);
  9453. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9454. return result;
  9455. }
  9456. void *UpdateFirmwareProcess(void *data)
  9457. {
  9458. pthread_detach(pthread_self());
  9459. mtrace();
  9460. int retriesInt =0, retryIntervalInt=0;
  9461. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9462. int port=0;
  9463. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9464. int isSuccess = 0;
  9465. char ftpbuf[200];
  9466. char temp[100];
  9467. char * pch;
  9468. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9469. json_object *UpdateFirmware;
  9470. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  9471. if(!is_error(UpdateFirmware))
  9472. {
  9473. // Required data
  9474. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  9475. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  9476. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  9477. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  9478. // Optional data
  9479. if(json_object_object_get(UpdateFirmware, "retries"))
  9480. {
  9481. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  9482. }
  9483. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  9484. {
  9485. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  9486. }
  9487. }
  9488. json_object_put(UpdateFirmware);
  9489. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9490. memset(path, 0, ARRAY_SIZE(path));
  9491. system("rm -f /mnt/*");
  9492. if(strncmp(locationstr,"http", 4) == 0)
  9493. {
  9494. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9495. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9496. // protocol, user, password, host, path);
  9497. sprintf(ftppath,"/%s", path);
  9498. DEBUG_INFO("locationstr: %s\n", locationstr);
  9499. DEBUG_INFO("protocol: %s\n",protocol);
  9500. DEBUG_INFO("host: %s\n",host);
  9501. DEBUG_INFO("path: %s\n",path);
  9502. DEBUG_INFO("ftppath: %s\n",ftppath);
  9503. int ftppathlen=strlen(ftppath);
  9504. int i=1;
  9505. char filenametemp[50];
  9506. while(i < ftppathlen)
  9507. {
  9508. int len=ftppathlen-i;
  9509. if(ftppath[len]== 47) // '/' ascll code: 47
  9510. {
  9511. DEBUG_INFO("compare '/' all right\n");
  9512. break;
  9513. }
  9514. i=i+1;
  9515. }
  9516. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9517. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9518. filenametemp[i+1] = 0;
  9519. do
  9520. {
  9521. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9522. sleep(3);
  9523. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9524. if(!isSuccess)
  9525. {
  9526. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9527. sleep(retryIntervalInt);
  9528. }
  9529. else
  9530. {
  9531. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9532. }
  9533. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9534. }
  9535. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9536. {
  9537. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9538. memset(temp, 0, ARRAY_SIZE(temp));
  9539. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9540. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9541. int ftppathlen=strlen(ftpbuf);
  9542. int i=1;
  9543. char filenametemp[50];
  9544. while(i < ftppathlen)
  9545. {
  9546. int len=ftppathlen-i;
  9547. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9548. {
  9549. DEBUG_INFO(" compare '/' all right\n");
  9550. break;
  9551. }
  9552. i=i+1;
  9553. }
  9554. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9555. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9556. filenametemp[i+1] = 0;
  9557. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9558. pch=strchr(temp,'@');
  9559. if(pch==NULL)
  9560. {
  9561. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9562. protocol, host, &port, path);
  9563. strcpy(user,"anonymous");
  9564. strcpy(password,"");
  9565. }
  9566. else
  9567. {
  9568. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9569. protocol, user, password, host, &port, path);
  9570. }
  9571. sscanf(host,"%[^/]%s",host1, path1);
  9572. sprintf(ftppath,"%s", path1);
  9573. //DEBUG_INFO("protocol =%s\n",protocol);
  9574. //DEBUG_INFO("user =%s\n",user);
  9575. //DEBUG_INFO("password =%s\n",password);
  9576. //DEBUG_INFO("host1 =%s\n",host1);
  9577. //DEBUG_INFO("port =%d\n",port);
  9578. //DEBUG_INFO("path1 =%s\n",path1);
  9579. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9580. //ftpFile(host, user, password, port, ftppath, fname);
  9581. //download firmware pthred
  9582. if(port == 0)
  9583. {
  9584. port = 21;
  9585. }
  9586. do
  9587. {
  9588. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9589. sleep(3);
  9590. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9591. if(!isSuccess)
  9592. {
  9593. //BulldogUtil.sleepMs(interval*1000);
  9594. DEBUG_INFO("Update firmware request and download file fail.\n");
  9595. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9596. sleep(retryIntervalInt);
  9597. }
  9598. else
  9599. {
  9600. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9601. }
  9602. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9603. }
  9604. else
  9605. {
  9606. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9607. }
  9608. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9609. pthread_exit(NULL);
  9610. }
  9611. //==========================================
  9612. // Handle server response routine
  9613. //==========================================
  9614. void handleAuthorizeResponse(char *payload, int gun_index)
  9615. {
  9616. mtrace();
  9617. char expiryDatestr[30]={0};
  9618. char parentIdTagstr[20]={0};
  9619. char statusstr[20]={0};
  9620. char expiryDatestrtemp[30]={0};
  9621. char parentIdTagstrtemp[20]={0};
  9622. char IdTagstrtemp[20]={0};
  9623. char statusstrtemp[20]={0};
  9624. int expiryDateISNULL=FALSE;
  9625. int parentIdTagISNULL=FALSE;
  9626. char sstr[160]={0};
  9627. char* filename = AuthorizationCache_JSON;
  9628. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9629. char *loc;
  9630. int resultRename=0;
  9631. int responseIdTagInfoAsZero= 0;
  9632. char rmFileCmd[50]={0};
  9633. DEBUG_INFO("handleAuthorizeResponse...\n");
  9634. json_object *Authorize;
  9635. Authorize = json_tokener_parse(payload);
  9636. if(!is_error(Authorize))
  9637. {
  9638. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9639. {
  9640. // Required data
  9641. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9642. // Optional data
  9643. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9644. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9645. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9646. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9647. }
  9648. }
  9649. json_object_put(Authorize);
  9650. if(expiryDateISNULL == FALSE)
  9651. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9652. if(parentIdTagISNULL == FALSE)
  9653. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9654. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9655. //Update idTag information to authorization cache if supproted
  9656. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9657. {
  9658. if((access(filename,F_OK))!=-1)
  9659. {
  9660. printf("AuthorizationCache exist.\n");
  9661. }
  9662. else
  9663. {
  9664. printf("AuthorizationCache not exist\n");
  9665. FILE *log = fopen(filename, "w+");
  9666. if(log == NULL)
  9667. {
  9668. printf("log is NULL\n");
  9669. goto out;
  9670. }
  9671. else
  9672. {
  9673. fclose(log);
  9674. }
  9675. }
  9676. FILE *infile;
  9677. FILE *outfile;
  9678. // open file for writing
  9679. infile = fopen (filename, "r");
  9680. outfile = fopen (tempfile, "w");
  9681. int c;
  9682. c = fgetc(infile);
  9683. //DEBUG_INFO("c:%d\n",c);
  9684. rewind(infile);
  9685. if(c == EOF)
  9686. {
  9687. DEBUG_INFO("Orignal File is NULL\n");
  9688. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9689. {
  9690. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9691. }
  9692. else
  9693. {
  9694. strcpy(expiryDatestrtemp, "");
  9695. }
  9696. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9697. {
  9698. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9699. }
  9700. else
  9701. {
  9702. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9703. }
  9704. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9705. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9706. fclose(infile);
  9707. fclose(outfile);
  9708. sprintf(rmFileCmd,"rm -f %s",filename);
  9709. system(rmFileCmd);
  9710. resultRename = rename(tempfile, filename);
  9711. if(resultRename == 0)
  9712. {
  9713. printf("File renamed successfully");
  9714. }
  9715. else
  9716. {
  9717. printf("Error: unable to rename the file");
  9718. }
  9719. }
  9720. else
  9721. {
  9722. char buf[160]={0};
  9723. while (fgets(buf, ARRAY_SIZE(buf), infile) != NULL)
  9724. {
  9725. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9726. memset(expiryDatestr, 0, ARRAY_SIZE(expiryDatestrtemp));
  9727. memset(parentIdTagstr,0, ARRAY_SIZE(parentIdTagstrtemp));
  9728. memset(statusstr, 0, ARRAY_SIZE(statusstrtemp));
  9729. memset(IdTagstrtemp, 0, ARRAY_SIZE(IdTagstrtemp));
  9730. memset(expiryDatestrtemp, 0, ARRAY_SIZE(expiryDatestrtemp));
  9731. memset(parentIdTagstrtemp, 0, ARRAY_SIZE(parentIdTagstrtemp));
  9732. memset(statusstrtemp, 0, ARRAY_SIZE(statusstrtemp));
  9733. //------------------IdTag-----------------------
  9734. loc = strstr(buf, "idTag");
  9735. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9736. c = 0;
  9737. while (loc[3+strlen("idTag")+c] != '\"')
  9738. {
  9739. sstr[c] = loc[3+strlen("idTag")+c];
  9740. c++;
  9741. }
  9742. sstr[c] = '\0';
  9743. strcpy(IdTagstrtemp,sstr);
  9744. //*********************expiryDate***************/
  9745. loc = strstr(buf, "expiryDate");
  9746. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9747. c = 0;
  9748. while (loc[3+strlen("expiryDate")+c] != '\"')
  9749. {
  9750. sstr[c] = loc[3+strlen("expiryDate")+c];
  9751. c++;
  9752. }
  9753. sstr[c] = '\0';
  9754. strcpy(expiryDatestr,sstr);
  9755. //*********************parentIdTag***************/
  9756. loc = strstr(buf, "parentIdTag");
  9757. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9758. c = 0;
  9759. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9760. {
  9761. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9762. c++;
  9763. }
  9764. sstr[c] = '\0';
  9765. strcpy(parentIdTagstr,sstr);
  9766. //*********************status***************/
  9767. loc = strstr(buf, "status");
  9768. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9769. c = 0;
  9770. while (loc[3+strlen("status")+c] != '\"')
  9771. {
  9772. sstr[c] = loc[3+strlen("status")+c];
  9773. c++;
  9774. }
  9775. sstr[c] = '\0';
  9776. strcpy(statusstr,sstr);
  9777. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9778. {
  9779. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9780. responseIdTagInfoAsZero = 1;
  9781. }
  9782. else
  9783. {
  9784. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9785. }
  9786. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9787. {
  9788. //modify item
  9789. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9790. {
  9791. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9792. }
  9793. else
  9794. {
  9795. strcpy(expiryDatestrtemp, "");
  9796. }
  9797. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9798. {
  9799. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9800. }
  9801. else
  9802. {
  9803. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9804. }
  9805. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9806. }
  9807. else
  9808. {
  9809. //wrie original item
  9810. strcpy(expiryDatestrtemp, expiryDatestr);
  9811. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9812. strcpy(statusstrtemp, statusstr);
  9813. }
  9814. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9815. }
  9816. fclose(infile);
  9817. fclose(outfile);
  9818. sprintf(rmFileCmd,"rm -f %s",filename);
  9819. system(rmFileCmd);
  9820. resultRename = rename(tempfile, filename);
  9821. if(resultRename == 0)
  9822. {
  9823. DEBUG_INFO("File renamed successfully");
  9824. }
  9825. else
  9826. {
  9827. DEBUG_INFO("Error: unable to rename the file");
  9828. }
  9829. }
  9830. }
  9831. out:
  9832. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9833. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9834. authorizeRetryTimes = 0;
  9835. }
  9836. void handleBootNotificationResponse(char *payload, int gun_index)
  9837. {
  9838. mtrace();
  9839. char statusStr[12]={0};
  9840. char currentTimeStr[30]={0};
  9841. int intervalInt = 0;
  9842. struct tm tp;
  9843. char buf[28]={0};
  9844. char timebuf[50]={0};
  9845. DEBUG_INFO("handleBootNotificationResponse...\n");
  9846. json_object *BootNotification;
  9847. BootNotification = json_tokener_parse(payload);
  9848. if(!is_error(BootNotification))
  9849. {
  9850. // Required data
  9851. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9852. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9853. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9854. }
  9855. json_object_put(BootNotification);
  9856. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9857. BootNotificationInterval = intervalInt;
  9858. HeartBeatWaitTime = intervalInt;
  9859. //write back to ShmOCPP16Data->BootNotification
  9860. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9861. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9862. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9863. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9864. {
  9865. server_sign = TRUE;
  9866. server_pending =FALSE;
  9867. }
  9868. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9869. {
  9870. server_pending = TRUE;
  9871. }
  9872. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9873. tp.tm_isdst = -1;
  9874. //time_t utc = mktime(&tp);
  9875. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9876. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9877. sprintf(timebuf,"date -s '%s'",buf);
  9878. system(timebuf);
  9879. srand(time(NULL));
  9880. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9881. //==============================================
  9882. // RTC sync
  9883. //==============================================
  9884. system("/sbin/hwclock -w --systohc");
  9885. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9886. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9887. }
  9888. void handleDataTransferResponse(char *payload, int gun_index)
  9889. {
  9890. char sstr[160]={0};//sstr[200]={ 0 };
  9891. int c = 0;
  9892. char *loc;
  9893. DEBUG_INFO("handleDataTransferResponse ...\n");
  9894. loc = strstr(payload, "status");
  9895. printf("loc=%s\n",loc);
  9896. c = 0;
  9897. while (loc[3+strlen("status")+c] != '\"')
  9898. {
  9899. sstr[c] = loc[3+strlen("status")+c];
  9900. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9901. c++;
  9902. }
  9903. sstr[c] = '\0';
  9904. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9905. }
  9906. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9907. {
  9908. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9909. //struct json_object *obj;
  9910. // obj = json_tokener_parse(payload);
  9911. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9912. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9913. //No fields are defined.
  9914. }
  9915. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9916. {
  9917. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9918. //struct json_object *obj;
  9919. // obj = json_tokener_parse(payload);
  9920. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9921. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9922. //No fields are defined.
  9923. }
  9924. void handleHeartbeatResponse(char *payload, int gun_index)
  9925. {
  9926. mtrace();
  9927. struct tm tp;
  9928. char buf[28]={0};
  9929. char timebuf[50]={0};
  9930. DEBUG_INFO("handleHeartbeatResponse...\n");
  9931. json_object *Heartbeat;
  9932. Heartbeat = json_tokener_parse(payload);
  9933. if(!is_error(Heartbeat))
  9934. {
  9935. // Required data
  9936. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9937. }
  9938. json_object_put(Heartbeat);
  9939. if(FirstHeartBeat == 0)
  9940. {
  9941. FirstHeartBeat = 1;
  9942. DEBUG_INFO("FirstHeartBeat \n");
  9943. }
  9944. HeartBeatWithNOResponse = 0;
  9945. clientTime.Heartbeat=time((time_t*)NULL);
  9946. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9947. tp.tm_isdst = -1;
  9948. //time_t utc = mktime(&tp);
  9949. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9950. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9951. sprintf(timebuf,"date -s '%s'",buf);
  9952. system(timebuf);
  9953. //==============================================
  9954. // RTC sync
  9955. //==============================================
  9956. system("/sbin/hwclock -w --systohc");
  9957. }
  9958. void handleMeterValuesResponse(char *payload, int gun_index)
  9959. {
  9960. mtrace();
  9961. DEBUG_INFO("handleMeterValuesResponse...\n");
  9962. }
  9963. void handleStartTransactionResponse(char *payload, int gun_index)
  9964. {
  9965. mtrace();
  9966. //int transactionIdInt = 0;
  9967. FILE *outfile;
  9968. char data[100]={0};
  9969. DEBUG_INFO("handleStartTransactionResponse...\n");
  9970. json_object *StartTransaction;
  9971. StartTransaction = json_tokener_parse(payload);
  9972. if(!is_error(StartTransaction))
  9973. {
  9974. // Required data
  9975. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  9976. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  9977. // Optional data
  9978. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  9979. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  9980. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9981. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  9982. }
  9983. json_object_put(StartTransaction);
  9984. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9985. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9986. //-----------Start : write to the Queue TransactionId file -----------------//
  9987. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9988. {}
  9989. else
  9990. {
  9991. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9992. if(log == NULL)
  9993. {
  9994. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9995. return ;
  9996. }
  9997. else
  9998. {
  9999. fclose(log);
  10000. }
  10001. }
  10002. // open file for writing
  10003. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10004. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10005. {
  10006. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10007. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10008. fputs(data, outfile);
  10009. fclose (outfile);
  10010. }
  10011. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10012. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10013. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10014. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10015. }
  10016. void handleStatusNotificationResponse(char *payload, int gun_index)
  10017. {
  10018. mtrace();
  10019. DEBUG_INFO("handleStatusNotificationResponse...\n");
  10020. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10021. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10022. }
  10023. void handleStopTransactionnResponse(char *payload, int gun_index)
  10024. {
  10025. mtrace();
  10026. DEBUG_INFO("handleStopTransactionnResponse...\n");
  10027. json_object *StopTransaction;
  10028. StopTransaction = json_tokener_parse(payload);
  10029. if(!is_error(StopTransaction))
  10030. {
  10031. // Optional data
  10032. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  10033. {
  10034. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  10035. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  10036. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  10037. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10038. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  10039. }
  10040. }
  10041. json_object_put(StopTransaction);
  10042. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10043. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10044. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10045. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10046. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10047. }
  10048. //==========================================
  10049. // Handle Error routine
  10050. //==========================================
  10051. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10052. {
  10053. mtrace();
  10054. #ifdef SystemLogMessage
  10055. DEBUG_INFO("errorCode: %s\n", errorCode);
  10056. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10057. DEBUG_INFO("errorDetails: %s\n", payload);
  10058. #endif
  10059. }
  10060. //===============================================
  10061. // Common routine
  10062. //===============================================
  10063. int initialConfigurationTable(void)
  10064. {
  10065. //clock_t start_t, end_t, total_t;
  10066. FILE *fp;
  10067. FILE *outfile;
  10068. char str[200]={0};
  10069. char sstr[100]={0};
  10070. int c = 0;
  10071. char *loc;
  10072. DEBUG_INFO("initialConfigurationTable...\n");
  10073. //start_t = clock();
  10074. //printf("Starting of the program, start_t = %ld\n", start_t);
  10075. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10076. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10077. {
  10078. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10079. if(outfile == NULL)
  10080. {
  10081. DEBUG_INFO("Error opening file\n");
  10082. return FALSE;
  10083. }
  10084. /*Core Profile*/
  10085. //AllowOfflineTxForUnknownId
  10086. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10089. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10090. //AuthorizationCacheEnabled
  10091. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10094. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10095. //AuthorizeRemoteTxRequests
  10096. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10100. //BlinkRepeat
  10101. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10104. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10105. //ClockAlignedDataInterval
  10106. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10109. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10110. //ConnectionTimeOut
  10111. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10115. //GetConfigurationMaxKeys
  10116. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "44" );
  10119. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10120. // HeartbeatInterval
  10121. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10124. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10125. // LightIntensity
  10126. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10129. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10130. // LocalAuthorizeOffline
  10131. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  10132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10134. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10135. // LocalPreAuthorize
  10136. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10139. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10140. // MaxEnergyOnInvalidId
  10141. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10144. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10145. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10146. // MeterValuesAlignedData
  10147. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10149. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10151. else
  10152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10153. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10154. // MeterValuesAlignedDataMaxLength
  10155. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10157. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10159. else
  10160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10161. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10162. // MeterValuesSampledData
  10163. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10165. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10167. else
  10168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10169. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10170. // MeterValuesSampledDataMaxLength
  10171. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10173. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10175. else
  10176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10178. // MeterValueSampleInterval
  10179. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10182. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10183. // MinimumStatusDuration
  10184. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10187. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10188. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10189. // NumberOfConnectors
  10190. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10192. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10193. {
  10194. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10195. }
  10196. else
  10197. {
  10198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10199. }
  10200. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10201. // ResetRetries
  10202. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10206. // ConnectorPhaseRotation
  10207. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10210. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10211. // ConnectorPhaseRotationMaxLength
  10212. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10216. // StopTransactionOnEVSideDisconnect
  10217. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10221. // StopTransactionOnInvalidId
  10222. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10225. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10226. // StopTxnAlignedData
  10227. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10229. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10230. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10231. // StopTxnAlignedDataMaxLength
  10232. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10235. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10236. // StopTxnSampledData
  10237. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10239. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10241. else
  10242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10243. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10244. // StopTxnSampledDataMaxLength
  10245. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10247. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10248. {
  10249. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10250. }
  10251. else
  10252. {
  10253. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10254. }
  10255. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10256. // SupportedFeatureProfiles
  10257. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10260. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10261. // SupportedFeatureProfilesMaxLength
  10262. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10265. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10266. // TransactionMessageAttempts
  10267. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10270. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10272. // TransactionMessageRetryInterval
  10273. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10274. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10276. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10277. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10278. // UnlockConnectorOnEVSideDisconnect
  10279. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10283. // WebSocketPingInterval
  10284. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10288. // QueueOffLineStartTransactionMessage
  10289. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10293. // AuthorizationKey
  10294. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  10297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10298. // SecurityProfile
  10299. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  10302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10303. // DefaultPrice
  10304. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10307. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10308. // CustomDisplayCostAndPrice
  10309. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10312. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10313. // CustomIdleFeeAfterStop
  10314. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10318. //* Local Auth List Management Profile*/
  10319. #if 0
  10320. //For OCTT Test Case
  10321. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10324. #endif
  10325. #if 1
  10326. //LocalAuthListEnabled
  10327. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10330. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10331. #endif
  10332. //LocalAuthListMaxLength
  10333. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10336. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10337. //SendLocalListMaxLength
  10338. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10341. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10342. //ReserveConnectorZeroSupported
  10343. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10346. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10347. //* Smart Charging Profile */
  10348. //ChargeProfileMaxStackLevel
  10349. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10352. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10353. // ChargingScheduleAllowedChargingRateUnit
  10354. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10357. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10358. // ChargingScheduleMaxPeriods
  10359. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10362. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10363. // ConnectorSwitch3to1PhaseSupported
  10364. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10367. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10368. // MaxChargingProfilesInstalled
  10369. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  10372. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10373. fclose(outfile);
  10374. }
  10375. else
  10376. {
  10377. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10378. char keystr[60]={0};
  10379. char readonlystr[10]={0};
  10380. char valuestr[100]={0};
  10381. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10382. if(fp == NULL) {
  10383. DEBUG_INFO("Error opening file");
  10384. return FALSE;
  10385. }
  10386. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10387. {
  10388. //DEBUG_INFO("Get Configuration \n");
  10389. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10390. //*************************key*********************************/
  10391. loc = strstr(str, "key");
  10392. c = 0;
  10393. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10394. while (loc[strlen("key")+3+c] != '\"')
  10395. {
  10396. sstr[c] = loc[strlen("key")+3+c];
  10397. c++;
  10398. }
  10399. sstr[c] = '\0';
  10400. strcpy(keystr,sstr);
  10401. //*************************readonly*********************************/
  10402. loc = strstr(str, "readonly");
  10403. c = 0;
  10404. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10405. while (loc[strlen("readonly")+2+c] != ',')
  10406. {
  10407. sstr[c] = loc[strlen("readonly")+2+c];
  10408. c++;
  10409. }
  10410. sstr[c] = '\0';
  10411. strcpy(readonlystr,sstr);
  10412. //*************************value*********************************/
  10413. loc = strstr(str, "value");
  10414. c = 0;
  10415. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10416. while (loc[strlen("value")+3+c] != '\"')
  10417. {
  10418. sstr[c] = loc[strlen("value")+3+c];
  10419. c++;
  10420. }
  10421. sstr[c] = '\0';
  10422. strcpy(valuestr,sstr);
  10423. // DEBUG_INFO("keystr=%s\n",keystr);
  10424. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10425. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10426. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10427. {
  10428. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10429. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10430. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10431. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10432. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10433. }
  10434. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10435. {
  10436. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10437. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10438. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10439. }
  10440. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10441. {
  10442. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10443. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10444. }
  10445. if(strcmp(keystr, "BlinkRepeat") == 0)
  10446. {
  10447. //Charger.BlinkRepeat = Integer.parseInt(value);
  10448. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10450. }
  10451. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10452. {
  10453. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10454. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10455. }
  10456. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10457. {
  10458. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10459. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10460. }
  10461. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10462. {
  10463. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10464. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10465. }
  10466. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10467. {
  10468. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10470. HeartBeatWaitTime = atoi(valuestr);
  10471. }
  10472. if(strcmp(keystr, "LightIntensity") == 0)
  10473. {
  10474. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10475. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10476. }
  10477. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10478. {
  10479. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10480. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10481. }
  10482. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10483. {
  10484. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10485. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10486. }
  10487. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10488. {
  10489. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10490. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10491. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10492. }
  10493. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10494. {
  10495. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10496. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10497. }
  10498. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10499. {
  10500. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10501. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10502. }
  10503. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10504. {
  10505. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10506. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10507. }
  10508. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10509. {
  10510. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10511. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10512. }
  10513. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10514. {
  10515. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10517. }
  10518. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10519. {
  10520. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10521. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10522. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10523. }
  10524. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10525. {
  10526. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10527. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10528. }
  10529. if(strcmp(keystr, "ResetRetries") == 0)
  10530. {
  10531. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10532. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10533. }
  10534. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10535. {
  10536. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10537. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10538. }
  10539. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10540. {
  10541. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10542. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10543. }
  10544. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10545. {
  10546. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10547. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10548. }
  10549. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10550. {
  10551. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10552. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10553. }
  10554. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10555. {
  10556. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10557. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10558. }
  10559. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10560. {
  10561. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10562. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10563. }
  10564. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10565. {
  10566. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10567. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10568. }
  10569. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10570. {
  10571. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10572. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10573. }
  10574. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10575. {
  10576. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10577. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10578. }
  10579. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10580. {
  10581. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10582. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10583. }
  10584. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10585. {
  10586. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10587. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10588. TransactionMessageAttemptsValue = atoi(valuestr);
  10589. }
  10590. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10591. {
  10592. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10593. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10594. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10595. }
  10596. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10597. {
  10598. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10599. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10600. }
  10601. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10602. {
  10603. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10604. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10605. }
  10606. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10607. {
  10608. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10609. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10610. }
  10611. if(strcmp(keystr, "AuthorizationKey") == 0)
  10612. {
  10613. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  10615. }
  10616. if(strcmp(keystr, "SecurityProfile") == 0)
  10617. {
  10618. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10619. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  10620. }
  10621. if(strcmp(keystr, "DefaultPrice") == 0)
  10622. {
  10623. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10624. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  10625. }
  10626. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  10627. {
  10628. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10629. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  10630. }
  10631. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  10632. {
  10633. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10634. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  10635. }
  10636. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10637. {
  10638. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10639. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10640. }
  10641. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10642. {
  10643. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10644. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10645. }
  10646. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10647. {
  10648. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10649. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10650. }
  10651. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10652. {
  10653. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10654. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10655. }
  10656. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10657. {
  10658. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10659. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10660. }
  10661. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10662. {
  10663. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10664. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10665. }
  10666. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10667. {
  10668. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10669. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10670. }
  10671. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10672. {
  10673. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10674. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10675. }
  10676. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10677. {
  10678. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10679. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10680. }
  10681. }
  10682. fclose(fp);
  10683. }
  10684. return 0;
  10685. }
  10686. void StoreConfigurationTable(void)
  10687. {
  10688. FILE *outfile;
  10689. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10690. if(outfile == NULL)
  10691. {
  10692. DEBUG_INFO("Error opening file");
  10693. return ;
  10694. }
  10695. /*Core Profile*/
  10696. //AllowOfflineTxForUnknownId
  10697. /*
  10698. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10699. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10702. */
  10703. //DEBUG_INFO("data=%s\n",data);
  10704. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10705. //AuthorizationCacheEnabled
  10706. /*
  10707. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10710. */
  10711. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10712. //AuthorizeRemoteTxRequests
  10713. /*
  10714. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10715. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10717. */
  10718. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10719. //BlinkRepeat
  10720. /*
  10721. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10722. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10724. */
  10725. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10726. //ClockAlignedDataInterval
  10727. /*
  10728. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10731. */
  10732. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10733. //ConnectionTimeOut
  10734. /*
  10735. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10738. */
  10739. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10740. //GetConfigurationMaxKeys
  10741. /*
  10742. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10745. */
  10746. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10747. // HeartbeatInterval
  10748. /*
  10749. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10752. */
  10753. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10754. // LightIntensity
  10755. /*
  10756. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10759. */
  10760. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10761. // LocalAuthorizeOffline
  10762. /*
  10763. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10766. */
  10767. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10768. // LocalPreAuthorize
  10769. /*
  10770. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10773. */
  10774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10775. // MaxEnergyOnInvalidId
  10776. /*
  10777. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10780. */
  10781. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10783. // MeterValuesAlignedData
  10784. /*
  10785. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10788. */
  10789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10790. // MeterValuesAlignedDataMaxLength
  10791. /*
  10792. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10795. */
  10796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10797. // MeterValuesSampledData
  10798. /*
  10799. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10802. */
  10803. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10804. // MeterValuesSampledDataMaxLength
  10805. /*
  10806. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10809. */
  10810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10811. // MeterValueSampleInterval
  10812. /*
  10813. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10816. */
  10817. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10818. // MinimumStatusDuration
  10819. /*
  10820. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10823. */
  10824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10825. // NumberOfConnectors
  10826. /*
  10827. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10829. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10830. {
  10831. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10832. }
  10833. else
  10834. {
  10835. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10836. }
  10837. */
  10838. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10839. // ResetRetries
  10840. /*
  10841. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10844. */
  10845. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10846. // ConnectorPhaseRotation
  10847. /*
  10848. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10851. */
  10852. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10853. // ConnectorPhaseRotationMaxLength
  10854. /*
  10855. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10858. */
  10859. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10860. // StopTransactionOnEVSideDisconnect
  10861. /*
  10862. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10865. */
  10866. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10867. // StopTransactionOnInvalidId
  10868. /*
  10869. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10872. */
  10873. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10874. // StopTxnAlignedData
  10875. /*
  10876. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10879. */
  10880. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10881. // StopTxnAlignedDataMaxLength
  10882. /*
  10883. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10884. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10885. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10886. */
  10887. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10888. // StopTxnSampledData
  10889. /*
  10890. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10893. */
  10894. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10895. // StopTxnSampledDataMaxLength
  10896. /*
  10897. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10900. */
  10901. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10902. // SupportedFeatureProfiles
  10903. /*
  10904. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10907. */
  10908. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10909. // SupportedFeatureProfilesMaxLength
  10910. /*
  10911. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10912. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10914. */
  10915. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10916. // TransactionMessageAttempts
  10917. /*
  10918. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10919. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10921. */
  10922. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10923. // TransactionMessageRetryInterval
  10924. /*
  10925. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10928. */
  10929. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10930. // UnlockConnectorOnEVSideDisconnect
  10931. /*
  10932. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10933. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10934. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10935. */
  10936. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10937. // WebSocketPingInterval
  10938. /*
  10939. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10940. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10942. */
  10943. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10944. // QueueOffLineStartTransactionMessage
  10945. /*
  10946. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  10947. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10948. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10949. */
  10950. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10951. // AuthorizationKey
  10952. /*
  10953. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10954. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  10956. */
  10957. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10958. // SecurityProfile
  10959. /*
  10960. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  10963. */
  10964. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10965. // DefaultPrice
  10966. /*
  10967. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10968. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10969. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10970. */
  10971. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10972. // CustomDisplayCostAndPrice
  10973. /*
  10974. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10975. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10977. */
  10978. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10979. // CustomIdleFeeAfterStop
  10980. /*
  10981. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10984. */
  10985. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10986. //* Local Auth List Management Profile*/
  10987. //LocalAuthListEnabled
  10988. /*
  10989. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10992. */
  10993. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10994. //LocalAuthListMaxLength
  10995. /*
  10996. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10999. */
  11000. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11001. //SendLocalListMaxLength
  11002. /*
  11003. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11004. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  11006. */
  11007. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11008. //ReserveConnectorZeroSupported
  11009. /*
  11010. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11013. */
  11014. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11015. //* Smart Charging Profile */
  11016. //ChargeProfileMaxStackLevel
  11017. /*
  11018. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11021. */
  11022. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11023. // ChargingScheduleAllowedChargingRateUnit
  11024. /*
  11025. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11028. */
  11029. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11030. // ChargingScheduleMaxPeriods
  11031. /*
  11032. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11035. */
  11036. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11037. // ConnectorSwitch3to1PhaseSupported
  11038. /*
  11039. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11042. */
  11043. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11044. // MaxChargingProfilesInstalled
  11045. /*
  11046. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11049. */
  11050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11051. fclose(outfile);
  11052. }
  11053. void getKeyValue(char *keyReq)
  11054. {
  11055. int isEmpty = FALSE;
  11056. int isKnowKey = FALSE;
  11057. DEBUG_INFO("keyReq = %s\n", keyReq);
  11058. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11059. isEmpty = TRUE;
  11060. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11061. {
  11062. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11064. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11065. {
  11066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11067. }
  11068. else
  11069. {
  11070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11071. }
  11072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11073. isKnowKey = TRUE;
  11074. }
  11075. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11076. {
  11077. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11079. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11080. {
  11081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11082. }
  11083. else
  11084. {
  11085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11086. }
  11087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11088. isKnowKey = TRUE;
  11089. }
  11090. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11091. {
  11092. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11094. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11095. {
  11096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11097. }
  11098. else
  11099. {
  11100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11101. }
  11102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11103. isKnowKey = TRUE;
  11104. }
  11105. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11106. {
  11107. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11109. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11110. {
  11111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11112. }
  11113. else
  11114. {
  11115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11116. }
  11117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11118. isKnowKey = TRUE;
  11119. }
  11120. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11121. {
  11122. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11124. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11125. {
  11126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11127. }
  11128. else
  11129. {
  11130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11131. }
  11132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11133. isKnowKey = TRUE;
  11134. }
  11135. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11136. {
  11137. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11139. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11140. {
  11141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11142. }
  11143. else
  11144. {
  11145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11146. }
  11147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11148. isKnowKey = TRUE;
  11149. }
  11150. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11151. {
  11152. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11154. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11155. {
  11156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11157. }
  11158. else
  11159. {
  11160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11161. }
  11162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11163. isKnowKey = TRUE;
  11164. }
  11165. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11166. {
  11167. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11169. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11170. {
  11171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11172. }
  11173. else
  11174. {
  11175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11176. }
  11177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11178. isKnowKey = TRUE;
  11179. }
  11180. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11181. {
  11182. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11184. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11185. {
  11186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11187. }
  11188. else
  11189. {
  11190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11191. }
  11192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11193. isKnowKey = TRUE;
  11194. }
  11195. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11196. {
  11197. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11199. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11200. {
  11201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11202. }
  11203. else
  11204. {
  11205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11206. }
  11207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11208. isKnowKey = TRUE;
  11209. }
  11210. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11211. {
  11212. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11214. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11215. {
  11216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11217. }
  11218. else
  11219. {
  11220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11221. }
  11222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11223. isKnowKey = TRUE;
  11224. }
  11225. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11226. {
  11227. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11229. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11230. {
  11231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11232. }
  11233. else
  11234. {
  11235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11236. }
  11237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11238. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11239. isKnowKey = TRUE;
  11240. }
  11241. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11242. {
  11243. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11245. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11246. {
  11247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11248. }
  11249. else
  11250. {
  11251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11252. }
  11253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11254. isKnowKey = TRUE;
  11255. }
  11256. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11257. {
  11258. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11260. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11261. {
  11262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11263. }
  11264. else
  11265. {
  11266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11267. }
  11268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11269. isKnowKey = TRUE;
  11270. }
  11271. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11272. {
  11273. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11275. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11276. {
  11277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11278. }
  11279. else
  11280. {
  11281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11282. }
  11283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11284. isKnowKey = TRUE;
  11285. }
  11286. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11287. {
  11288. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11290. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11291. {
  11292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11293. }
  11294. else
  11295. {
  11296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11297. }
  11298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11299. isKnowKey = TRUE;
  11300. }
  11301. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11302. {
  11303. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11305. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11306. {
  11307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11308. }
  11309. else
  11310. {
  11311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11312. }
  11313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11314. isKnowKey = TRUE;
  11315. }
  11316. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11317. {
  11318. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11320. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11321. {
  11322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11323. }
  11324. else
  11325. {
  11326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11327. }
  11328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11329. isKnowKey = TRUE;
  11330. }
  11331. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11332. {
  11333. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11335. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11336. {
  11337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11338. }
  11339. else
  11340. {
  11341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11342. }
  11343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11344. isKnowKey = TRUE;
  11345. }
  11346. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11347. {
  11348. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11350. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11351. {
  11352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11353. }
  11354. else
  11355. {
  11356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11357. }
  11358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11359. isKnowKey = TRUE;
  11360. }
  11361. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11362. {
  11363. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11365. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11366. {
  11367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11368. }
  11369. else
  11370. {
  11371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11372. }
  11373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11374. isKnowKey = TRUE;
  11375. }
  11376. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11377. {
  11378. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11380. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11381. {
  11382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11383. }
  11384. else
  11385. {
  11386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11387. }
  11388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11389. isKnowKey = TRUE;
  11390. }
  11391. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11392. {
  11393. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11395. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11396. {
  11397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11398. }
  11399. else
  11400. {
  11401. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11402. }
  11403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11404. isKnowKey = TRUE;
  11405. }
  11406. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11407. {
  11408. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11410. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11411. {
  11412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11413. }
  11414. else
  11415. {
  11416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11417. }
  11418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11419. isKnowKey = TRUE;
  11420. }
  11421. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11422. {
  11423. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11425. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11426. {
  11427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11428. }
  11429. else
  11430. {
  11431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11432. }
  11433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11434. isKnowKey = TRUE;
  11435. }
  11436. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11437. {
  11438. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11440. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11441. {
  11442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11443. }
  11444. else
  11445. {
  11446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11447. }
  11448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11449. isKnowKey = TRUE;
  11450. }
  11451. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11452. {
  11453. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11455. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11456. {
  11457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11458. }
  11459. else
  11460. {
  11461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11462. }
  11463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11464. isKnowKey = TRUE;
  11465. }
  11466. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11467. {
  11468. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11470. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11471. {
  11472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11473. }
  11474. else
  11475. {
  11476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11477. }
  11478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11479. isKnowKey = TRUE;
  11480. }
  11481. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11482. {
  11483. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11485. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11486. {
  11487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11488. }
  11489. else
  11490. {
  11491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11492. }
  11493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11494. isKnowKey = TRUE;
  11495. }
  11496. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11497. {
  11498. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11500. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11501. {
  11502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11503. }
  11504. else
  11505. {
  11506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11507. }
  11508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11509. isKnowKey = TRUE;
  11510. }
  11511. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11512. {
  11513. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11515. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11516. {
  11517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11518. }
  11519. else
  11520. {
  11521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11522. }
  11523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11524. isKnowKey = TRUE;
  11525. }
  11526. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11527. {
  11528. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11530. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11531. {
  11532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11533. }
  11534. else
  11535. {
  11536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11537. }
  11538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11539. isKnowKey = TRUE;
  11540. }
  11541. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11542. {
  11543. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11545. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11546. {
  11547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11548. }
  11549. else
  11550. {
  11551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11552. }
  11553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11554. isKnowKey = TRUE;
  11555. }
  11556. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11557. {
  11558. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11560. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11561. {
  11562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11563. }
  11564. else
  11565. {
  11566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11567. }
  11568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11569. isKnowKey = TRUE;
  11570. }
  11571. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11572. {
  11573. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11575. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11576. {
  11577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11578. }
  11579. else
  11580. {
  11581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11582. }
  11583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11584. isKnowKey = TRUE;
  11585. }
  11586. /*
  11587. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  11588. {
  11589. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  11590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  11591. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  11592. {
  11593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  11594. }
  11595. else
  11596. {
  11597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  11598. }
  11599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  11600. isKnowKey = TRUE;
  11601. }*/
  11602. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  11603. {
  11604. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  11605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  11606. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  11607. {
  11608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  11609. }
  11610. else
  11611. {
  11612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  11613. }
  11614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  11615. isKnowKey = TRUE;
  11616. }
  11617. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  11618. {
  11619. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  11620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  11621. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  11622. {
  11623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  11624. }
  11625. else
  11626. {
  11627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  11628. }
  11629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  11630. isKnowKey = TRUE;
  11631. }
  11632. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  11633. {
  11634. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  11635. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  11636. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  11637. {
  11638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  11639. }
  11640. else
  11641. {
  11642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  11643. }
  11644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  11645. isKnowKey = TRUE;
  11646. }
  11647. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  11648. {
  11649. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  11650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  11651. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  11652. {
  11653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  11654. }
  11655. else
  11656. {
  11657. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  11658. }
  11659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  11660. isKnowKey = TRUE;
  11661. }
  11662. #if 1
  11663. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11664. {
  11665. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11667. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11668. {
  11669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11670. }
  11671. else
  11672. {
  11673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11674. }
  11675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11676. isKnowKey = TRUE;
  11677. }
  11678. #endif
  11679. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11680. {
  11681. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11683. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11684. {
  11685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11686. }
  11687. else
  11688. {
  11689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11690. }
  11691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11692. isKnowKey = TRUE;
  11693. }
  11694. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11695. {
  11696. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11698. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11699. {
  11700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11701. }
  11702. else
  11703. {
  11704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11705. }
  11706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11707. isKnowKey = TRUE;
  11708. }
  11709. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11710. {
  11711. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11713. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11714. {
  11715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11716. }
  11717. else
  11718. {
  11719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11720. }
  11721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11722. isKnowKey = TRUE;
  11723. }
  11724. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11725. {
  11726. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11728. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11729. {
  11730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11731. }
  11732. else
  11733. {
  11734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11735. }
  11736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11737. isKnowKey = TRUE;
  11738. }
  11739. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11740. {
  11741. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11743. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11744. {
  11745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11746. }
  11747. else
  11748. {
  11749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11750. }
  11751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11752. isKnowKey = TRUE;
  11753. }
  11754. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11755. {
  11756. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11758. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11759. {
  11760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11761. }
  11762. else
  11763. {
  11764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11765. }
  11766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11767. isKnowKey = TRUE;
  11768. }
  11769. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11770. {
  11771. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11773. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11774. {
  11775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11776. }
  11777. else
  11778. {
  11779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11780. }
  11781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11782. isKnowKey = TRUE;
  11783. }
  11784. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11785. {
  11786. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11788. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11789. {
  11790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11791. }
  11792. else
  11793. {
  11794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11795. }
  11796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11797. isKnowKey = TRUE;
  11798. }
  11799. //=========================================================
  11800. if(!isEmpty && !isKnowKey)
  11801. {
  11802. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11803. strcpy(unknownkey[UnknownKeynum], keyReq);
  11804. UnknownKeynum = UnknownKeynum + 1;
  11805. }
  11806. }
  11807. void processUnkownKey(void)
  11808. {
  11809. DEBUG_INFO("processUnkownKey...\n");
  11810. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11811. for(int index=0; index < UnknownKeynum; index++)
  11812. {
  11813. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11814. {
  11815. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11816. }
  11817. }
  11818. }
  11819. int setKeyValue(char *key, char *value)
  11820. {
  11821. int isSuccess = NotSupported;
  11822. int check_ascii=0;
  11823. char str[10]={0};
  11824. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11825. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11826. {
  11827. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11828. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11829. {
  11830. strcpy(str, (const char*)value);
  11831. for(int i = 0; str[i]; i++){
  11832. str[i] = tolower(str[i]);
  11833. }
  11834. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11835. isSuccess = ConfigurationStatus_Accepted;
  11836. }
  11837. else
  11838. {
  11839. isSuccess = ConfigurationStatus_Rejected;
  11840. }
  11841. }
  11842. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11843. {
  11844. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11845. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11846. {
  11847. strcpy(str, (const char*)value);
  11848. for(int i = 0; str[i]; i++){
  11849. str[i] = tolower(str[i]);
  11850. }
  11851. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11852. isSuccess = ConfigurationStatus_Accepted;
  11853. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11854. }
  11855. else
  11856. {
  11857. isSuccess = ConfigurationStatus_Rejected;
  11858. }
  11859. }
  11860. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11861. {
  11862. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11863. {
  11864. strcpy(str, (const char*)value);
  11865. for(int i = 0; str[i]; i++)
  11866. {
  11867. str[i] = tolower(str[i]);
  11868. }
  11869. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11870. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11871. isSuccess = ConfigurationStatus_Accepted;
  11872. }
  11873. else
  11874. {
  11875. isSuccess = ConfigurationStatus_Rejected;
  11876. }
  11877. }
  11878. if(strcmp(key, "BlinkRepeat") == 0)
  11879. {
  11880. //Charger.BlinkRepeat = Integer.parseInt(value);
  11881. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11882. {
  11883. check_ascii = value[0];
  11884. if( (check_ascii < 48) || (check_ascii > 57) )
  11885. {
  11886. isSuccess = ConfigurationStatus_Rejected;
  11887. }
  11888. else
  11889. {
  11890. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11891. isSuccess = ConfigurationStatus_Accepted;
  11892. }
  11893. }
  11894. else
  11895. {
  11896. isSuccess = ConfigurationStatus_Rejected;
  11897. }
  11898. }
  11899. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11900. {
  11901. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11902. {
  11903. check_ascii = value[0];
  11904. if( (check_ascii < 48) || (check_ascii > 57) )
  11905. {
  11906. isSuccess = ConfigurationStatus_Rejected;
  11907. }
  11908. else
  11909. {
  11910. if((atoi(value) == 0) || (atoi(value) >= 10))
  11911. {
  11912. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11913. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11914. isSuccess = ConfigurationStatus_Accepted;
  11915. }
  11916. else
  11917. isSuccess = ConfigurationStatus_Rejected;
  11918. }
  11919. }
  11920. else
  11921. {
  11922. isSuccess = ConfigurationStatus_Rejected;
  11923. }
  11924. }
  11925. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11926. {
  11927. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11928. {
  11929. check_ascii = value[0];
  11930. if( (check_ascii < 48) || (check_ascii > 57) )
  11931. {
  11932. isSuccess = ConfigurationStatus_Rejected;
  11933. }
  11934. else
  11935. {
  11936. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11937. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11938. isSuccess = ConfigurationStatus_Accepted;
  11939. }
  11940. }
  11941. else
  11942. {
  11943. isSuccess = ConfigurationStatus_Rejected;
  11944. }
  11945. }
  11946. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11947. {
  11948. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11949. {
  11950. check_ascii = value[0];
  11951. if( (check_ascii < 48) || (check_ascii > 57) )
  11952. {
  11953. isSuccess = ConfigurationStatus_Rejected;
  11954. }
  11955. else
  11956. {
  11957. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11958. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11959. isSuccess = ConfigurationStatus_Accepted;
  11960. }
  11961. }
  11962. else
  11963. {
  11964. isSuccess = ConfigurationStatus_Rejected;
  11965. }
  11966. }
  11967. if(strcmp(key, "HeartbeatInterval") == 0)
  11968. {
  11969. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11970. {
  11971. check_ascii = value[0];
  11972. if( (check_ascii < 48) || (check_ascii > 57) )
  11973. {
  11974. isSuccess = ConfigurationStatus_Rejected;
  11975. }
  11976. else
  11977. {
  11978. if((atoi(value) == 0) || (atoi(value) >= 10))
  11979. {
  11980. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11981. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11982. HeartBeatWaitTime = atoi(value);
  11983. isSuccess = ConfigurationStatus_Accepted;
  11984. }
  11985. else
  11986. {
  11987. isSuccess = ConfigurationStatus_Rejected;
  11988. }
  11989. }
  11990. }
  11991. else
  11992. {
  11993. isSuccess = ConfigurationStatus_Rejected;
  11994. }
  11995. }
  11996. if(strcmp(key, "LightIntensity") == 0)
  11997. {
  11998. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11999. {
  12000. check_ascii = value[0];
  12001. if( (check_ascii < 48) || (check_ascii > 57) )
  12002. {
  12003. isSuccess = ConfigurationStatus_Rejected;
  12004. }
  12005. else
  12006. {
  12007. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  12008. isSuccess = ConfigurationStatus_Accepted;
  12009. }
  12010. }
  12011. else
  12012. {
  12013. isSuccess = ConfigurationStatus_Rejected;
  12014. }
  12015. }
  12016. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  12017. {
  12018. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12019. {
  12020. strcpy(str, (const char*)value);
  12021. for(int i = 0; str[i]; i++)
  12022. {
  12023. str[i] = tolower(str[i]);
  12024. }
  12025. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12026. isSuccess = ConfigurationStatus_Accepted;
  12027. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12028. }
  12029. else
  12030. {
  12031. isSuccess = ConfigurationStatus_Rejected;
  12032. }
  12033. }
  12034. if(strcmp(key, "LocalPreAuthorize") == 0)
  12035. {
  12036. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12037. {
  12038. strcpy(str, (const char*)value);
  12039. for(int i = 0; str[i]; i++)
  12040. {
  12041. str[i] = tolower(str[i]);
  12042. }
  12043. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12044. isSuccess = ConfigurationStatus_Accepted;
  12045. }
  12046. else
  12047. {
  12048. isSuccess = ConfigurationStatus_Rejected;
  12049. }
  12050. }
  12051. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  12052. {
  12053. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12054. {
  12055. check_ascii = value[0];
  12056. if( (check_ascii < 48) || (check_ascii > 57) )
  12057. {
  12058. isSuccess = ConfigurationStatus_Rejected;
  12059. }
  12060. else
  12061. {
  12062. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  12063. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  12064. isSuccess = ConfigurationStatus_Accepted;
  12065. }
  12066. }
  12067. else
  12068. {
  12069. isSuccess = ConfigurationStatus_Rejected;
  12070. }
  12071. }
  12072. if(strcmp(key, "MeterValuesAlignedData") == 0)
  12073. {
  12074. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12075. {
  12076. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  12077. isSuccess = ConfigurationStatus_Accepted;
  12078. }
  12079. else
  12080. {
  12081. isSuccess = ConfigurationStatus_Rejected;
  12082. }
  12083. }
  12084. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  12085. {
  12086. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12087. {
  12088. check_ascii = value[0];
  12089. if( (check_ascii < 48) || (check_ascii > 57) )
  12090. {
  12091. isSuccess = ConfigurationStatus_Rejected;
  12092. }
  12093. else
  12094. {
  12095. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12096. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  12097. isSuccess = ConfigurationStatus_Accepted;
  12098. }
  12099. }
  12100. else
  12101. {
  12102. isSuccess = ConfigurationStatus_Rejected;
  12103. }
  12104. }
  12105. if(strcmp(key, "MeterValuesSampledData") == 0 )
  12106. {
  12107. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12108. {
  12109. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  12110. isSuccess = ConfigurationStatus_Accepted;
  12111. }
  12112. else
  12113. {
  12114. isSuccess = ConfigurationStatus_Rejected;
  12115. }
  12116. }
  12117. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  12118. {
  12119. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12120. {
  12121. check_ascii = value[0];
  12122. if( (check_ascii < 48) || (check_ascii > 57) )
  12123. {
  12124. isSuccess = ConfigurationStatus_Rejected;
  12125. }
  12126. else
  12127. {
  12128. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12129. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12130. isSuccess = ConfigurationStatus_Accepted;
  12131. }
  12132. }
  12133. else
  12134. {
  12135. isSuccess = ConfigurationStatus_Rejected;
  12136. }
  12137. }
  12138. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12139. {
  12140. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12141. {
  12142. check_ascii = value[0];
  12143. if( (check_ascii < 48) || (check_ascii > 57) )
  12144. {
  12145. isSuccess = ConfigurationStatus_Rejected;
  12146. }
  12147. else
  12148. {
  12149. if((atoi(value) == 0) || (atoi(value) >= 10))
  12150. {
  12151. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12152. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12153. isSuccess = ConfigurationStatus_Accepted;
  12154. }
  12155. else
  12156. {
  12157. isSuccess = ConfigurationStatus_Rejected;
  12158. }
  12159. }
  12160. }
  12161. else
  12162. {
  12163. isSuccess = ConfigurationStatus_Rejected;
  12164. }
  12165. }
  12166. if(strcmp(key, "MinimumStatusDuration") == 0)
  12167. {
  12168. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12169. {
  12170. check_ascii = value[0];
  12171. if( (check_ascii < 48) || (check_ascii > 57) )
  12172. {
  12173. isSuccess = ConfigurationStatus_Rejected;
  12174. }
  12175. else
  12176. {
  12177. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12178. {
  12179. isSuccess = ConfigurationStatus_Rejected;
  12180. }
  12181. else
  12182. {
  12183. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12184. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12185. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12186. isSuccess = ConfigurationStatus_Accepted;
  12187. }
  12188. }
  12189. }
  12190. else
  12191. {
  12192. isSuccess = ConfigurationStatus_Rejected;
  12193. }
  12194. }
  12195. if(strcmp(key, "NumberOfConnectors") == 0)
  12196. {
  12197. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12198. {
  12199. check_ascii = value[0];
  12200. if( (check_ascii < 48) || (check_ascii > 57) )
  12201. {
  12202. isSuccess = ConfigurationStatus_Rejected;
  12203. }
  12204. else
  12205. {
  12206. //Charger.ResetRetries = Integer.parseInt(value);
  12207. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12208. isSuccess = ConfigurationStatus_Accepted;
  12209. }
  12210. }
  12211. else
  12212. {
  12213. isSuccess = ConfigurationStatus_Rejected;
  12214. }
  12215. }
  12216. if(strcmp(key, "ResetRetries") == 0)
  12217. {
  12218. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12219. {
  12220. check_ascii = value[0];
  12221. if( (check_ascii < 48) || (check_ascii > 57) )
  12222. {
  12223. isSuccess = ConfigurationStatus_Rejected;
  12224. }
  12225. else
  12226. {
  12227. //Charger.ResetRetries = Integer.parseInt(value);
  12228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12229. isSuccess = ConfigurationStatus_Accepted;
  12230. }
  12231. }
  12232. else
  12233. {
  12234. isSuccess = ConfigurationStatus_Rejected;
  12235. }
  12236. }
  12237. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12238. {
  12239. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12240. {
  12241. strcpy(str, (const char*)value);
  12242. for(int i = 0; str[i]; i++)
  12243. {
  12244. str[i] = tolower(str[i]);
  12245. }
  12246. if(strcmp(str, "notapplicable")== 0)
  12247. {
  12248. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12249. isSuccess = ConfigurationStatus_Accepted;
  12250. }
  12251. else if(strcmp(str, "unknown")== 0)
  12252. {
  12253. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12254. isSuccess = ConfigurationStatus_Accepted;
  12255. }
  12256. else if(strcmp(str, "rst")== 0)
  12257. {
  12258. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12259. isSuccess = ConfigurationStatus_Accepted;
  12260. }
  12261. else if(strcmp(str, "rts")== 0)
  12262. {
  12263. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12264. isSuccess = ConfigurationStatus_Accepted;
  12265. }
  12266. else if(strcmp(str, "srt")== 0)
  12267. {
  12268. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12269. isSuccess = ConfigurationStatus_Accepted;
  12270. }
  12271. else if(strcmp(str, "str")== 0)
  12272. {
  12273. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12274. isSuccess = ConfigurationStatus_Accepted;
  12275. }
  12276. else if(strcmp(str, "trs")== 0)
  12277. {
  12278. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12279. isSuccess = ConfigurationStatus_Accepted;
  12280. }
  12281. else if(strcmp(str, "tsr")== 0)
  12282. {
  12283. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12284. isSuccess = ConfigurationStatus_Accepted;
  12285. }
  12286. else
  12287. {
  12288. isSuccess = ConfigurationStatus_Rejected;
  12289. }
  12290. }
  12291. else
  12292. {
  12293. isSuccess = ConfigurationStatus_Rejected;
  12294. }
  12295. }
  12296. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12297. {
  12298. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12299. {
  12300. check_ascii = value[0];
  12301. if( (check_ascii < 48) || (check_ascii > 57) )
  12302. {
  12303. isSuccess = ConfigurationStatus_Rejected;
  12304. }
  12305. else
  12306. {
  12307. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12308. isSuccess = ConfigurationStatus_Accepted;
  12309. }
  12310. }
  12311. else
  12312. {
  12313. isSuccess = ConfigurationStatus_Rejected;
  12314. }
  12315. }
  12316. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12317. {
  12318. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12319. {
  12320. strcpy(str, (const char*)value);
  12321. for(int i = 0; str[i]; i++)
  12322. {
  12323. str[i] = tolower(str[i]);
  12324. }
  12325. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12326. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12327. isSuccess = ConfigurationStatus_Accepted;
  12328. }
  12329. else
  12330. {
  12331. isSuccess = ConfigurationStatus_Rejected;
  12332. }
  12333. }
  12334. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12335. {
  12336. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12337. {
  12338. strcpy(str, (const char*)value);
  12339. for(int i = 0; str[i]; i++)
  12340. {
  12341. str[i] = tolower(str[i]);
  12342. }
  12343. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12344. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12345. isSuccess = ConfigurationStatus_Accepted;
  12346. }
  12347. else
  12348. {
  12349. isSuccess = ConfigurationStatus_Rejected;
  12350. }
  12351. }
  12352. if(strcmp(key, "StopTxnAlignedData") == 0)
  12353. {
  12354. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12355. {
  12356. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12357. isSuccess = ConfigurationStatus_Accepted;
  12358. }
  12359. else
  12360. {
  12361. isSuccess = ConfigurationStatus_Rejected;
  12362. }
  12363. }
  12364. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12365. {
  12366. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12367. {
  12368. check_ascii = value[0];
  12369. if( (check_ascii < 48) || (check_ascii > 57) )
  12370. {
  12371. isSuccess = ConfigurationStatus_Rejected;
  12372. }
  12373. else
  12374. {
  12375. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12376. isSuccess = ConfigurationStatus_Accepted;
  12377. }
  12378. }
  12379. else
  12380. {
  12381. isSuccess = ConfigurationStatus_Rejected;
  12382. }
  12383. }
  12384. if(strcmp(key, "StopTxnSampledData") == 0)
  12385. {
  12386. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12387. {
  12388. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12389. isSuccess = ConfigurationStatus_Accepted;
  12390. }
  12391. else
  12392. {
  12393. isSuccess = ConfigurationStatus_Rejected;
  12394. }
  12395. }
  12396. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12397. {
  12398. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12399. {
  12400. check_ascii = value[0];
  12401. if( (check_ascii < 48) || (check_ascii > 57) )
  12402. {
  12403. isSuccess = ConfigurationStatus_Rejected;
  12404. }
  12405. else
  12406. {
  12407. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12408. isSuccess = ConfigurationStatus_Accepted;
  12409. }
  12410. }
  12411. else
  12412. {
  12413. isSuccess = ConfigurationStatus_Rejected;
  12414. }
  12415. }
  12416. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12417. {
  12418. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12419. {
  12420. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12421. isSuccess = ConfigurationStatus_Accepted;
  12422. }
  12423. else
  12424. {
  12425. isSuccess = ConfigurationStatus_Rejected;
  12426. }
  12427. }
  12428. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12429. {
  12430. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12431. {
  12432. check_ascii = value[0];
  12433. if( (check_ascii < 48) || (check_ascii > 57) )
  12434. {
  12435. isSuccess = ConfigurationStatus_Rejected;
  12436. }
  12437. else
  12438. {
  12439. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12440. isSuccess = ConfigurationStatus_Accepted;
  12441. }
  12442. }
  12443. else
  12444. {
  12445. isSuccess = ConfigurationStatus_Rejected;
  12446. }
  12447. }
  12448. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12449. {
  12450. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12451. {
  12452. check_ascii = value[0];
  12453. if( (check_ascii < 48) || (check_ascii > 57) )
  12454. {
  12455. isSuccess = ConfigurationStatus_Rejected;
  12456. }
  12457. else
  12458. {
  12459. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12460. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12461. TransactionMessageAttemptsValue = atoi(value);
  12462. isSuccess = ConfigurationStatus_Accepted;
  12463. }
  12464. }
  12465. else
  12466. {
  12467. isSuccess = ConfigurationStatus_Rejected;
  12468. }
  12469. }
  12470. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12471. {
  12472. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12473. {
  12474. check_ascii = value[0];
  12475. if( (check_ascii < 48) || (check_ascii > 57) )
  12476. {
  12477. isSuccess = ConfigurationStatus_Rejected;
  12478. }
  12479. else
  12480. {
  12481. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12482. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12483. TransactionMessageRetryIntervalValue = atoi(value);
  12484. isSuccess = ConfigurationStatus_Accepted;
  12485. }
  12486. }
  12487. else
  12488. {
  12489. isSuccess = ConfigurationStatus_Rejected;
  12490. }
  12491. }
  12492. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12493. {
  12494. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12495. {
  12496. strcpy(str, (const char*)value);
  12497. for(int i = 0; str[i]; i++)
  12498. {
  12499. str[i] = tolower(str[i]);
  12500. }
  12501. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12502. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12503. isSuccess = ConfigurationStatus_Accepted;
  12504. }
  12505. else
  12506. {
  12507. isSuccess = ConfigurationStatus_Rejected;
  12508. }
  12509. }
  12510. if(strcmp(key, "WebSocketPingInterval") == 0)
  12511. {
  12512. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12513. {
  12514. check_ascii = value[0];
  12515. if( (check_ascii < 48) || (check_ascii > 57) )
  12516. {
  12517. isSuccess = ConfigurationStatus_Rejected;
  12518. }
  12519. else
  12520. {
  12521. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12522. isSuccess = ConfigurationStatus_Accepted;
  12523. }
  12524. }
  12525. else
  12526. {
  12527. isSuccess = ConfigurationStatus_Rejected;
  12528. }
  12529. }
  12530. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12531. {
  12532. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12533. {
  12534. strcpy(str, (const char*)value);
  12535. for(int i = 0; str[i]; i++)
  12536. {
  12537. str[i] = tolower(str[i]);
  12538. }
  12539. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12540. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12541. isSuccess = ConfigurationStatus_Accepted;
  12542. }
  12543. else
  12544. {
  12545. isSuccess = ConfigurationStatus_Rejected;
  12546. }
  12547. }
  12548. if(strcmp(key, "AuthorizationKey") == 0)
  12549. {
  12550. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  12551. {
  12552. strcpy(str, (const char*)value);
  12553. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  12554. isSuccess = ConfigurationStatus_Accepted;
  12555. }
  12556. else
  12557. {
  12558. isSuccess = ConfigurationStatus_Rejected;
  12559. }
  12560. }
  12561. if(strcmp(key, "SecurityProfile") == 0)
  12562. {
  12563. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12564. {
  12565. check_ascii = value[0];
  12566. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  12567. {
  12568. isSuccess = ConfigurationStatus_Rejected;
  12569. }
  12570. else if(check_ascii == 0x33)
  12571. {
  12572. isSuccess = NotSupported;
  12573. }
  12574. else
  12575. {
  12576. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  12577. {
  12578. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  12579. isSuccess = ConfigurationStatus_Accepted;
  12580. }
  12581. else
  12582. isSuccess = ConfigurationStatus_Rejected;
  12583. }
  12584. }
  12585. else
  12586. {
  12587. isSuccess = ConfigurationStatus_Rejected;
  12588. }
  12589. }
  12590. if(strcmp(key, "DefaultPrice") == 0)
  12591. {
  12592. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  12593. {
  12594. strcpy(str, (const char*)value);
  12595. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  12596. isSuccess = ConfigurationStatus_Accepted;
  12597. }
  12598. else
  12599. {
  12600. isSuccess = ConfigurationStatus_Rejected;
  12601. }
  12602. }
  12603. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  12604. {
  12605. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12606. {
  12607. strcpy(str, (const char*)value);
  12608. for(int i = 0; str[i]; i++)
  12609. {
  12610. str[i] = tolower(str[i]);
  12611. }
  12612. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12613. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12614. isSuccess = ConfigurationStatus_Accepted;
  12615. }
  12616. else
  12617. {
  12618. isSuccess = ConfigurationStatus_Rejected;
  12619. }
  12620. }
  12621. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  12622. {
  12623. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12624. {
  12625. strcpy(str, (const char*)value);
  12626. for(int i = 0; str[i]; i++)
  12627. {
  12628. str[i] = tolower(str[i]);
  12629. }
  12630. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12631. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12632. isSuccess = ConfigurationStatus_Accepted;
  12633. }
  12634. else
  12635. {
  12636. isSuccess = ConfigurationStatus_Rejected;
  12637. }
  12638. }
  12639. #if 0
  12640. //For OCPP Test Case
  12641. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12642. {
  12643. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12644. {
  12645. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12646. isSuccess = ConfigurationStatus_Accepted;
  12647. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12648. }
  12649. else
  12650. {
  12651. isSuccess = ConfigurationStatus_Rejected;
  12652. }
  12653. }
  12654. #endif
  12655. #if 1
  12656. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12657. {
  12658. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12659. {
  12660. strcpy(str, (const char*)value);
  12661. for(int i = 0; str[i]; i++)
  12662. {
  12663. str[i] = tolower(str[i]);
  12664. }
  12665. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12666. isSuccess = ConfigurationStatus_Accepted;
  12667. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12668. }
  12669. else
  12670. {
  12671. isSuccess = ConfigurationStatus_Rejected;
  12672. }
  12673. }
  12674. #endif
  12675. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12676. {
  12677. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12678. {
  12679. check_ascii = value[0];
  12680. if( (check_ascii < 48) || (check_ascii > 57) )
  12681. {
  12682. isSuccess = ConfigurationStatus_Rejected;
  12683. }
  12684. else
  12685. {
  12686. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12687. isSuccess = ConfigurationStatus_Accepted;
  12688. }
  12689. }
  12690. else
  12691. {
  12692. isSuccess = ConfigurationStatus_Rejected;
  12693. }
  12694. }
  12695. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12696. {
  12697. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12698. {
  12699. check_ascii = value[0];
  12700. if( (check_ascii < 48) || (check_ascii > 57) )
  12701. {
  12702. isSuccess = ConfigurationStatus_Rejected;
  12703. }
  12704. else
  12705. {
  12706. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12707. isSuccess = ConfigurationStatus_Accepted;
  12708. }
  12709. }
  12710. else
  12711. {
  12712. isSuccess = ConfigurationStatus_Rejected;
  12713. }
  12714. }
  12715. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12716. {
  12717. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12718. {
  12719. strcpy(str, (const char*)value);
  12720. for(int i = 0; str[i]; i++)
  12721. {
  12722. str[i] = tolower(str[i]);
  12723. }
  12724. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12725. isSuccess = ConfigurationStatus_Accepted;
  12726. }
  12727. else
  12728. {
  12729. isSuccess = ConfigurationStatus_Rejected;
  12730. }
  12731. }
  12732. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12733. {
  12734. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12735. {
  12736. check_ascii = value[0];
  12737. if( (check_ascii < 48) || (check_ascii > 57) )
  12738. {
  12739. isSuccess = ConfigurationStatus_Rejected;
  12740. }
  12741. else
  12742. {
  12743. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12744. isSuccess = ConfigurationStatus_Accepted;
  12745. }
  12746. }
  12747. else
  12748. {
  12749. isSuccess = ConfigurationStatus_Rejected;
  12750. }
  12751. }
  12752. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12753. {
  12754. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12755. {
  12756. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12757. isSuccess = ConfigurationStatus_Accepted;
  12758. }
  12759. else
  12760. {
  12761. isSuccess = ConfigurationStatus_Rejected;
  12762. }
  12763. }
  12764. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12765. {
  12766. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12767. {
  12768. check_ascii = value[0];
  12769. if( (check_ascii < 48) || (check_ascii > 57) )
  12770. {
  12771. isSuccess = ConfigurationStatus_Rejected;
  12772. }
  12773. else
  12774. {
  12775. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12776. isSuccess = ConfigurationStatus_Accepted;
  12777. }
  12778. }
  12779. else
  12780. {
  12781. isSuccess = ConfigurationStatus_Rejected;
  12782. }
  12783. }
  12784. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12785. {
  12786. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12787. {
  12788. strcpy(str, (const char*)value);
  12789. for(int i = 0; str[i]; i++)
  12790. {
  12791. str[i] = tolower(str[i]);
  12792. }
  12793. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12794. isSuccess = ConfigurationStatus_Accepted;
  12795. }
  12796. else
  12797. {
  12798. isSuccess = ConfigurationStatus_Rejected;
  12799. }
  12800. }
  12801. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12802. {
  12803. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12804. {
  12805. check_ascii = value[0];
  12806. if( (check_ascii < 48) || (check_ascii > 57) )
  12807. {
  12808. isSuccess = ConfigurationStatus_Rejected;
  12809. }
  12810. else
  12811. {
  12812. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12813. isSuccess = ConfigurationStatus_Accepted;
  12814. }
  12815. }
  12816. else
  12817. {
  12818. isSuccess = ConfigurationStatus_Rejected;
  12819. }
  12820. }
  12821. return isSuccess;
  12822. }
  12823. int TransactionMessageAttemptsGet(void)
  12824. {
  12825. return TransactionMessageAttemptsValue;
  12826. }
  12827. int FirstHeartBeatResponse(void)
  12828. {
  12829. return FirstHeartBeat;
  12830. }
  12831. int TransactionMessageRetryIntervalGet(void)
  12832. {
  12833. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12834. }
  12835. int ReadHttpStatus(int sock)
  12836. {
  12837. //char c;
  12838. char buff[1024]="",*ptr=buff+1;
  12839. int bytes_received, status;
  12840. DEBUG_INFO("Begin Response ..\n");
  12841. while((bytes_received = recv(sock, ptr, 1, 0))){
  12842. if(bytes_received==-1){
  12843. perror("ReadHttpStatus");
  12844. exit(1);
  12845. }
  12846. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12847. ptr++;
  12848. }
  12849. *ptr=0;
  12850. ptr=buff+1;
  12851. sscanf(ptr,"%*s %d ", &status);
  12852. DEBUG_INFO("%s\n",ptr);
  12853. DEBUG_INFO("status=%d\n",status);
  12854. DEBUG_INFO("End Response ..\n");
  12855. return (bytes_received>0)?status:0;
  12856. }
  12857. //the only filed that it parsed is 'Content-Length'
  12858. int ParseHeader(int sock)
  12859. {
  12860. //char c;
  12861. char buff[1024]="",*ptr=buff+4;
  12862. int bytes_received;
  12863. DEBUG_INFO("Begin HEADER ..\n");
  12864. while((bytes_received = recv(sock, ptr, 1, 0))){
  12865. if(bytes_received==-1){
  12866. perror("Parse Header");
  12867. exit(1);
  12868. }
  12869. if(
  12870. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12871. (ptr[-1]=='\r') && (*ptr=='\n' )
  12872. ) break;
  12873. ptr++;
  12874. }
  12875. *ptr=0;
  12876. ptr=buff+4;
  12877. //printf("%s",ptr);
  12878. if(bytes_received){
  12879. ptr=strstr(ptr,"Content-Length:");
  12880. if(ptr){
  12881. sscanf(ptr,"%*s %d",&bytes_received);
  12882. }else
  12883. bytes_received=-1; //unknown size
  12884. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12885. }
  12886. DEBUG_INFO("End HEADER ..\n");
  12887. return bytes_received ;
  12888. }
  12889. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12890. {
  12891. char rmFileCmd[100]={0};
  12892. char FilePath[100]={0};
  12893. char ftpbuf[200];
  12894. int systemresult;
  12895. //DEBUG_INFO("filename=%s\n",filename);
  12896. //DEBUG_INFO("url=%s\n",url);
  12897. sprintf(FilePath,"/mnt/%s",filename);
  12898. if((access(FilePath,F_OK))!=-1)
  12899. {
  12900. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12901. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12902. system(rmFileCmd);
  12903. }
  12904. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12905. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12906. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12907. systemresult = system(ftpbuf);
  12908. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12909. if(systemresult != 0)
  12910. {
  12911. DEBUG_INFO("http DownLoad error!\n");
  12912. return FALSE;
  12913. }
  12914. return TRUE;
  12915. }
  12916. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12917. {
  12918. char rmFileCmd[100]={0};
  12919. char FilePath[100]={0};
  12920. char ftpbuf[200];
  12921. int systemresult;
  12922. //char temp[100];
  12923. sprintf(FilePath,"/mnt/%s",filename);
  12924. if((access(FilePath,F_OK))!=-1)
  12925. {
  12926. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12927. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12928. system(rmFileCmd);
  12929. }
  12930. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12931. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12932. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12933. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12934. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12935. systemresult = system(ftpbuf);
  12936. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12937. if(systemresult != 0)
  12938. {
  12939. printf("wget error!\n");
  12940. return FALSE;
  12941. }
  12942. return TRUE;
  12943. }
  12944. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12945. {
  12946. char rmFileCmd[100]={0};
  12947. char FilePath[100]={0};
  12948. char ftpbuf[200];
  12949. int systemresult;
  12950. //DEBUG_INFO("filename=%s\n",filename);
  12951. //DEBUG_INFO("url=%s\n",url);
  12952. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12953. if((access(FilePath,F_OK))!=-1)
  12954. {
  12955. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12956. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12957. system(rmFileCmd);
  12958. }
  12959. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12960. if(fp == NULL)
  12961. {
  12962. DEBUG_INFO("log is NULL\n");
  12963. return FALSE;
  12964. }
  12965. else
  12966. {
  12967. fprintf(fp, "%s\n", url);
  12968. fprintf(fp, "%s\n", filename);
  12969. fclose(fp);
  12970. }
  12971. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12972. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12973. systemresult = system(ftpbuf);
  12974. DEBUG_INFO("systemresult = %d\n",systemresult);
  12975. if(systemresult != 0)
  12976. {
  12977. DEBUG_INFO("http upload error!\n");
  12978. return FALSE;
  12979. }
  12980. return TRUE;
  12981. }
  12982. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12983. {
  12984. struct hostent* server;
  12985. char *IPbuffer;
  12986. char ftpbuf[200];
  12987. int systemresult;
  12988. // To retrieve host information
  12989. server = gethostbyname(location);
  12990. // To convert an Internet network
  12991. // address into ASCII string
  12992. IPbuffer = inet_ntoa(*((struct in_addr*)
  12993. server->h_addr_list[0]));
  12994. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12995. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12996. /* format : ftpput -u username -p passwd IP target source*/
  12997. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12998. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12999. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13000. systemresult = system(ftpbuf);
  13001. DEBUG_INFO("systemresult=%d\n",systemresult);
  13002. if(systemresult != 0)
  13003. {
  13004. DEBUG_INFO("ftpput error!\n");
  13005. return FALSE;
  13006. }
  13007. return TRUE;
  13008. }
  13009. /**
  13010. * Place the contents of the specified file into a memory buffer
  13011. *
  13012. * @param[in] filename The path and name of the file to read
  13013. * @param[out] filebuffer A pointer to the contents in memory
  13014. * @return status 0 success, 1 on failure
  13015. */
  13016. int get_file_contents(const char* filename, char** outbuffer) {
  13017. FILE* file = NULL;
  13018. long filesize;
  13019. const int blocksize = 1;
  13020. size_t readsize;
  13021. char* filebuffer;
  13022. // Open the file
  13023. file = fopen(filename, "r");
  13024. if (NULL == file)
  13025. {
  13026. printf("'%s' not opened\n", filename);
  13027. exit(EXIT_FAILURE);
  13028. }
  13029. // Determine the file size
  13030. fseek(file, 0, SEEK_END);
  13031. filesize = ftell(file);
  13032. rewind (file);
  13033. // Allocate memory for the file contents
  13034. filebuffer = (char*) malloc(sizeof(char) * filesize);
  13035. *outbuffer = filebuffer;
  13036. if (filebuffer == NULL)
  13037. {
  13038. fputs ("malloc out-of-memory", stderr);
  13039. exit(EXIT_FAILURE);
  13040. }
  13041. // Read in the file
  13042. readsize = fread(filebuffer, blocksize, filesize, file);
  13043. if (readsize != filesize)
  13044. {
  13045. fputs ("didn't read file completely",stderr);
  13046. exit(EXIT_FAILURE);
  13047. }
  13048. // Clean exit
  13049. fclose(file);
  13050. return EXIT_SUCCESS;
  13051. }
  13052. static int selectSqlCount = 0;
  13053. static int callback(void *data, int argc, char **argv, char **azColName){
  13054. int i;
  13055. //printf("%s: ", (const char*)data);
  13056. selectSqlCount = argc;
  13057. for(i = 0; i<argc; i++){
  13058. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  13059. }
  13060. //printf("\n");
  13061. return 0;
  13062. }
  13063. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  13064. //int i;
  13065. //printf("%s:\n", (const char*)data);
  13066. localversion = argv[5] ? atoi(argv[5]) : 0;
  13067. //printf("localversion=%d\n", localversion);
  13068. return 0;
  13069. }
  13070. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  13071. //int i;
  13072. //printf("%s:\n", (const char*)data);
  13073. //idTag
  13074. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  13075. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  13076. //parentIdTag
  13077. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  13078. //expir_date
  13079. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  13080. //status
  13081. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  13082. //version
  13083. idTagQuery.listVersionInt = atoi(argv[5]);
  13084. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  13085. return 0;
  13086. }
  13087. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  13088. {
  13089. // localversion = argv[5] ? atoi(argv[5]) : 0;
  13090. // printf("localversion=%d\n", localversion);
  13091. return 0;
  13092. }
  13093. //=========================================
  13094. // Sqlite3 related function
  13095. //=========================================
  13096. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  13097. {
  13098. for (int i = 0; i < n_columns; i++)
  13099. {
  13100. DEBUG_INFO("%s\t", col_values[i]);
  13101. }
  13102. DEBUG_INFO("\n");
  13103. return 0;
  13104. }
  13105. void OCPP_getListVerion()
  13106. {
  13107. int rc = 0;
  13108. // const char* data = "Callback function called";
  13109. char sql[100];
  13110. char zErrMsg[100];
  13111. memset(sql, 0, 100);
  13112. memset(zErrMsg, 0, 100);
  13113. strcpy(sql, "select * from ocpp_auth_local order by idx");
  13114. /* Execute SQL statement */
  13115. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  13116. if( rc != SQLITE_OK )
  13117. {
  13118. DEBUG_INFO("SQL error: %s", zErrMsg);
  13119. }
  13120. }
  13121. void OCPP_getIdTag(char idTag[])
  13122. {
  13123. int rc = 0;
  13124. // const char* data = "Callback function called";
  13125. char sql[100];
  13126. char zErrMsg[100];
  13127. memset(sql, 0, 100);
  13128. memset(zErrMsg, 0, 100);
  13129. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  13130. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13131. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  13132. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13133. /* Execute SQL statement */
  13134. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13135. if( rc != SQLITE_OK )
  13136. {
  13137. DEBUG_INFO("SQL error: %s", zErrMsg);
  13138. }
  13139. //return ver;
  13140. }
  13141. void OCPP_get_TableAuthlocalAllData(void)
  13142. {
  13143. int rc = 0;
  13144. char sql[100];
  13145. char zErrMsg[100];
  13146. memset(sql, 0, 100);
  13147. memset(zErrMsg, 0, 100);
  13148. sprintf(sql,"select * from ocpp_auth_local ");
  13149. /* Execute SQL statement */
  13150. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  13151. if( rc != SQLITE_OK )
  13152. {
  13153. DEBUG_INFO("SQL error: %s", zErrMsg);
  13154. }
  13155. //return ver;
  13156. }
  13157. int OCPP_cleanLocalList()
  13158. {
  13159. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  13160. char *errMsg = 0;
  13161. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13162. if (SQLITE_OK != rc)
  13163. {
  13164. DEBUG_INFO("%s\n",errMsg);
  13165. return FALSE;
  13166. }
  13167. return TRUE;
  13168. }
  13169. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13170. {
  13171. int isSuccess = FALSE;
  13172. int ret = 0;
  13173. //const char* data = "Callback function called";
  13174. char sql[300];
  13175. char zErrMsg[200];
  13176. memset(sql, 0, 300);
  13177. memset(zErrMsg, 0, 200);
  13178. 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);
  13179. //* Execute SQL statement */
  13180. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13181. if( ret != SQLITE_OK )
  13182. {
  13183. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13184. return isSuccess;
  13185. }
  13186. memset(sql, 0, 300);
  13187. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13188. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13189. if( ret != SQLITE_OK )
  13190. {
  13191. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13192. return isSuccess;
  13193. }
  13194. isSuccess = TRUE;
  13195. return isSuccess;
  13196. }
  13197. void OCPP_deleteIdTag(char idTag[])
  13198. {
  13199. //int ver = 0;
  13200. //int isSuccess = FALSE;
  13201. int rc = 0;
  13202. char sql[100];
  13203. char zErrMsg[100];
  13204. memset(sql, 0, 100);
  13205. memset(zErrMsg, 0, 100);
  13206. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13207. //* Execute SQL statement */
  13208. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13209. if( rc != SQLITE_OK )
  13210. {
  13211. DEBUG_INFO("SQL error: %s", zErrMsg);
  13212. }
  13213. }
  13214. int GetOcppServerURL()
  13215. {
  13216. int result = FALSE;
  13217. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  13218. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  13219. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  13220. struct yuarel url;
  13221. char urlStr[512];
  13222. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13223. {
  13224. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13225. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13226. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13227. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  13228. if(yuarel_parse(&url, urlStr) != -1)
  13229. {
  13230. sprintf(OcppProtocol, "%s", url.scheme);
  13231. sprintf(OcppHost, "%s", url.host);
  13232. if(url.path == NULL)
  13233. OcppTempPath[0] = '\0';
  13234. else
  13235. sprintf(OcppTempPath, "%s", url.path);
  13236. if(url.port == 0)
  13237. {
  13238. if(strcmp(OcppProtocol, "wss") == 0)
  13239. OcppPort = 443;
  13240. else
  13241. OcppPort = 80;
  13242. }
  13243. else
  13244. OcppPort = url.port;
  13245. result = TRUE;
  13246. }
  13247. }
  13248. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13249. {
  13250. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13251. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13252. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13253. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  13254. if(yuarel_parse(&url, urlStr) != -1)
  13255. {
  13256. sprintf(OcppProtocol, "%s", url.scheme);
  13257. sprintf(OcppHost, "%s", url.host);
  13258. if(url.path == NULL)
  13259. OcppTempPath[0] = '\0';
  13260. else
  13261. sprintf(OcppTempPath, "%s", url.path);
  13262. if(url.port == 0)
  13263. {
  13264. if(strcmp(OcppProtocol, "wss") == 0)
  13265. OcppPort = 443;
  13266. else
  13267. OcppPort = 80;
  13268. }
  13269. else
  13270. OcppPort = url.port;
  13271. result = TRUE;
  13272. }
  13273. }
  13274. else
  13275. {
  13276. strcpy(OcppHost,"");
  13277. }
  13278. return result;
  13279. }
  13280. int GetOcppPath()
  13281. {
  13282. int result = FALSE;
  13283. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13284. {
  13285. if(OcppTempPath == NULL)
  13286. {
  13287. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13288. }
  13289. else
  13290. {
  13291. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13292. }
  13293. result = TRUE;
  13294. goto End;
  13295. }
  13296. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13297. {
  13298. if(OcppTempPath == NULL)
  13299. {
  13300. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13301. }
  13302. else
  13303. {
  13304. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13305. }
  13306. result = TRUE;
  13307. goto End;
  13308. }
  13309. else
  13310. {
  13311. strcpy(OcppPath,"");
  13312. }
  13313. End:
  13314. return result;
  13315. }
  13316. int GetOcppPort()
  13317. {
  13318. return OcppPort;
  13319. }
  13320. int GetOcppConnStatus(void)
  13321. {
  13322. return ShmOCPP16Data->OcppConnStatus;
  13323. }
  13324. void SetOcppConnStatus(uint8_t status)
  13325. {
  13326. ShmOCPP16Data->OcppConnStatus = status;
  13327. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13328. }
  13329. int GetHeartBeatWithNOResponse(void)
  13330. {
  13331. return HeartBeatWithNOResponse;
  13332. }
  13333. void SetHeartBeatWithNOResponse(void)
  13334. {
  13335. HeartBeatWithNOResponse = 0;
  13336. }
  13337. void GetStartTransactionIdTag(int gun_index)
  13338. {
  13339. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13340. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13341. }
  13342. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13343. {
  13344. char ch;
  13345. FILE *fptr1;
  13346. int temptransactionId;
  13347. char str[100]={0};
  13348. temptransactionId = 0;
  13349. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  13350. {
  13351. DEBUG_INFO("IdTag is empty.\n");
  13352. return temptransactionId;
  13353. }
  13354. /*------ Read the file ----------------*/
  13355. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13356. if (!fptr1)
  13357. {
  13358. DEBUG_INFO("QueueTransactionId file open error.\n");
  13359. //printf(" File not found or unable to open the input file!!\n");
  13360. return temptransactionId;
  13361. }
  13362. ch=fgetc(fptr1);
  13363. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13364. rewind(fptr1);
  13365. if(ch!=EOF)
  13366. {
  13367. // printf("%c",ch);
  13368. while (fgets(str, 100, fptr1) != NULL)
  13369. {
  13370. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13371. if(str[0]=='\0')
  13372. {
  13373. break;
  13374. }
  13375. char *revbuf[8] = {0}; // Variable store string split
  13376. int num = 0;// Quantity after string split
  13377. DEBUG_INFO("Transaction queue data= %s\n", str);
  13378. splitstring(str,",",revbuf,&num); // String split
  13379. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  13380. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  13381. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  13382. DEBUG_INFO("------------------------------\n");
  13383. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13384. {
  13385. if(isStopTransaction)
  13386. {
  13387. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13388. {
  13389. temptransactionId = atoi(revbuf[2]);
  13390. break;
  13391. }
  13392. }
  13393. else
  13394. {
  13395. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13396. {
  13397. temptransactionId = atoi(revbuf[2]);
  13398. break;
  13399. }
  13400. }
  13401. }
  13402. }
  13403. }
  13404. else
  13405. DEBUG_INFO("EOF\n");
  13406. fclose(fptr1);
  13407. /*------- End of reading ---------------*/
  13408. return temptransactionId;
  13409. }
  13410. void SetTransactionIdZero(int transactionId)
  13411. {
  13412. char ch;
  13413. FILE *fptr1, *fptr2;
  13414. int temptransactionId = 0;
  13415. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13416. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13417. if (!fptr1)
  13418. {
  13419. //printf(" File not found or unable to open the input file!!\n");
  13420. return ;
  13421. }
  13422. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13423. if (!fptr2)
  13424. {
  13425. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13426. fclose(fptr1);
  13427. return ;
  13428. }
  13429. ch=fgetc(fptr1);
  13430. rewind(fptr1);
  13431. if(ch!=EOF)
  13432. {
  13433. // copy all contents to the temporary file except the specific line
  13434. while (fgets(str, 100, fptr1) != NULL)
  13435. {
  13436. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13437. if(str[0]=='\0')
  13438. {
  13439. break;
  13440. }
  13441. char *revbuf[8] = {0};
  13442. int num = 0;
  13443. strcpy(strtemp, str);
  13444. splitstring(str,",",revbuf,&num);
  13445. if(revbuf[2][0] != '\0')
  13446. {
  13447. temptransactionId = atoi(revbuf[2]);
  13448. if(transactionId != temptransactionId)
  13449. {
  13450. fprintf(fptr2, "%s\n", strtemp);
  13451. }
  13452. }
  13453. }
  13454. }
  13455. fclose(fptr1);
  13456. fclose(fptr2);
  13457. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13458. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13459. /*------ Read the file ----------------*/
  13460. }
  13461. int InternetDisconnect(void)
  13462. {
  13463. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13464. }
  13465. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13466. void storeTempStopTransaction(int gun_index)
  13467. {
  13468. char guid[37]={0};
  13469. int tempIndex = 0;
  13470. char TempStopTransaction[256];
  13471. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13472. DEBUG_INFO("storeTempStopTransaction...\n");
  13473. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13474. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  13475. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13476. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13477. if(gunType[gun_index] == 'J')
  13478. {
  13479. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13480. {
  13481. tempIndex = ((gun_index==2) ? 1: 0);
  13482. }
  13483. else
  13484. {
  13485. tempIndex = gun_index;
  13486. }
  13487. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13488. {
  13489. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13490. {
  13491. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13492. }
  13493. }// END OF CHAdeMO_QUANTITY
  13494. }
  13495. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13496. {
  13497. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13498. {
  13499. tempIndex = ((gun_index==2) ? 1: 0);
  13500. }
  13501. else
  13502. {
  13503. tempIndex = gun_index;
  13504. }
  13505. for (int index = 0; index < CCS_QUANTITY; index++)
  13506. {
  13507. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13508. {
  13509. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13510. }
  13511. }// END OF CCS_QUANTITY
  13512. }
  13513. else if(gunType[gun_index] == 'G')
  13514. {
  13515. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13516. {
  13517. tempIndex = ((gun_index==2) ? 1: 0);
  13518. }
  13519. else
  13520. {
  13521. tempIndex = gun_index;
  13522. }
  13523. for (int index = 0; index < GB_QUANTITY; index++)
  13524. {
  13525. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13526. {
  13527. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13528. }
  13529. }// END OF GB_QUANTITY
  13530. }
  13531. else if(gunType[gun_index] == 'O')
  13532. {
  13533. tempIndex = gun_index;
  13534. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13535. {
  13536. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13537. {
  13538. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  13539. }
  13540. }
  13541. }
  13542. else
  13543. {
  13544. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13545. {
  13546. tempIndex = 2;
  13547. }
  13548. else
  13549. {
  13550. tempIndex = gun_index;
  13551. }
  13552. for (int index = 0; index < AC_QUANTITY; index++)
  13553. {
  13554. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13555. {
  13556. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13557. }
  13558. }// END OF AC_QUANTITY
  13559. }
  13560. //Stop Transaction Time
  13561. struct timeval tmnow;
  13562. struct tm *tm;
  13563. char buf[28];//, usec_buf[6];
  13564. gettimeofday(&tmnow, NULL);
  13565. time_t t;
  13566. t = time(NULL);
  13567. /*UTC time and date*/
  13568. tm = gmtime(&t);
  13569. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13570. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13571. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13573. random_uuid(guid);
  13574. /***********************************transactionData******************************************************/
  13575. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13577. //=================================
  13578. //1. Transaction_Begin
  13579. //=================================
  13580. //============================== Energy.Active.Import.Interval ===========================================
  13581. //idx_sample=0;
  13582. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  13583. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13584. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13585. 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*/]);
  13586. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13587. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13588. {
  13589. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13590. }
  13591. else
  13592. {
  13593. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13594. }
  13595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13596. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13597. //=================================
  13598. //2. Transaction_End
  13599. //=================================
  13600. //2.1====================================== Current.Import L1 ==============================================
  13601. //idx_sample=1;
  13602. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13603. if(gunType[gun_index] == 'J')
  13604. {
  13605. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13606. {
  13607. tempIndex = ((gun_index==2) ? 1: 0);
  13608. }
  13609. else
  13610. {
  13611. tempIndex = gun_index;
  13612. }
  13613. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13614. {
  13615. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13616. {
  13617. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13618. }
  13619. }// End of for CHAdeMO_QUANTITY
  13620. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13621. }
  13622. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13623. {
  13624. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13625. {
  13626. tempIndex = ((gun_index==2) ? 1: 0);
  13627. }
  13628. else
  13629. {
  13630. tempIndex = gun_index;
  13631. }
  13632. for (int index = 0; index < CCS_QUANTITY; index++)
  13633. {
  13634. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13635. {
  13636. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13637. }
  13638. }// End of for CCS_QUANTITY
  13639. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13640. }
  13641. else if(gunType[gun_index] == 'G')
  13642. {
  13643. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13644. {
  13645. tempIndex = ((gun_index==2) ? 1: 0);
  13646. }
  13647. else
  13648. {
  13649. tempIndex = gun_index;
  13650. }
  13651. for (int index = 0; index < GB_QUANTITY; index++)
  13652. {
  13653. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13654. {
  13655. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13656. }
  13657. }// End of for GB_QUANTITY
  13658. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13659. }
  13660. else if(gunType[gun_index] == 'O')
  13661. {
  13662. tempIndex = gun_index;
  13663. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13664. {
  13665. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13666. {
  13667. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13668. }
  13669. }
  13670. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13671. }
  13672. else
  13673. {
  13674. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13675. {
  13676. tempIndex = 2;
  13677. }
  13678. else
  13679. {
  13680. tempIndex = gun_index;
  13681. }
  13682. for (int index = 0; index < AC_QUANTITY; index++)
  13683. {
  13684. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13685. {
  13686. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13687. }
  13688. }// End of for AC_QUANTITY
  13689. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13690. }
  13691. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13692. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13693. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13694. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13695. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13696. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13697. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13698. //idx_sample=2;
  13699. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13700. if(gunType[gun_index] == 'J')
  13701. {
  13702. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13703. {
  13704. tempIndex = ((gun_index==2) ? 1: 0);
  13705. }
  13706. else
  13707. {
  13708. tempIndex = gun_index;
  13709. }
  13710. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13711. {
  13712. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13713. {
  13714. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13715. }
  13716. }// END OF CHAdeMO_QUANTITY
  13717. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13718. }
  13719. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13720. {
  13721. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13722. {
  13723. tempIndex = ((gun_index==2) ? 1: 0);
  13724. }
  13725. else
  13726. {
  13727. tempIndex = gun_index;
  13728. }
  13729. for (int index = 0; index < CCS_QUANTITY; index++)
  13730. {
  13731. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13732. {
  13733. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13734. }
  13735. }// END OF CCS_QUANTITY
  13736. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13737. }
  13738. else if(gunType[gun_index] == 'G')
  13739. {
  13740. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13741. {
  13742. tempIndex = ((gun_index==2) ? 1: 0);
  13743. }
  13744. else
  13745. {
  13746. tempIndex = gun_index;
  13747. }
  13748. for (int index = 0; index < GB_QUANTITY; index++)
  13749. {
  13750. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13751. {
  13752. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13753. }
  13754. }// END OF GB_QUANTITY
  13755. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13756. }
  13757. else if(gunType[gun_index] == 'O')
  13758. {
  13759. tempIndex = gun_index;
  13760. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13761. {
  13762. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13763. {
  13764. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13765. }
  13766. }
  13767. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13768. }
  13769. else
  13770. {
  13771. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13772. {
  13773. tempIndex = 2;
  13774. }
  13775. else
  13776. {
  13777. tempIndex = gun_index;
  13778. }
  13779. for (int index = 0; index < AC_QUANTITY; index++)
  13780. {
  13781. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13782. {
  13783. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13784. }
  13785. }// END OF AC_QUANTITY
  13786. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13787. }
  13788. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13789. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13790. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13791. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13792. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13793. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13794. //2.3====================================== Power.Active.Import =========================================
  13795. //idx_sample=3;
  13796. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13797. if(gunType[gun_index] == 'J')
  13798. {
  13799. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13800. {
  13801. tempIndex = ((gun_index==2) ? 1: 0);
  13802. }
  13803. else
  13804. {
  13805. tempIndex = gun_index;
  13806. }
  13807. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13808. {
  13809. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13810. {
  13811. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13812. }
  13813. } // End for CHAdeMO_QUANTITY
  13814. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13815. }
  13816. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13817. {
  13818. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13819. {
  13820. tempIndex = ((gun_index==2) ? 1: 0);
  13821. }
  13822. else
  13823. {
  13824. tempIndex = gun_index;
  13825. }
  13826. for (int index = 0; index < CCS_QUANTITY; index++)
  13827. {
  13828. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13829. {
  13830. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13831. }
  13832. } // END for CCS_QUANTITY
  13833. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13834. }
  13835. else if(gunType[gun_index] == 'G')
  13836. {
  13837. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13838. {
  13839. tempIndex = ((gun_index==2) ? 1: 0);
  13840. }
  13841. else
  13842. {
  13843. tempIndex = gun_index;
  13844. }
  13845. for (int index = 0; index < GB_QUANTITY; index++)
  13846. {
  13847. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13848. {
  13849. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13850. }
  13851. }// END for GB_QUANTITY
  13852. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13853. }
  13854. else if(gunType[gun_index] == 'O')
  13855. {
  13856. tempIndex = gun_index;
  13857. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13858. {
  13859. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13860. {
  13861. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13862. }
  13863. }
  13864. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13865. }
  13866. else
  13867. {
  13868. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13869. {
  13870. tempIndex = 2;
  13871. }
  13872. else
  13873. {
  13874. tempIndex = gun_index;
  13875. }
  13876. for (int index = 0; index < AC_QUANTITY; index++)
  13877. {
  13878. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13879. {
  13880. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13881. }
  13882. } // END for AC_QUANTITY
  13883. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13884. }
  13885. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13886. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13887. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13888. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13889. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13891. //2.4====================================== Voltage L1 ====================================================
  13892. //idx_sample=4;
  13893. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13894. if(gunType[gun_index] == 'J')
  13895. {
  13896. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13897. {
  13898. tempIndex = ((gun_index==2) ? 1: 0);
  13899. }
  13900. else
  13901. {
  13902. tempIndex = gun_index;
  13903. }
  13904. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13905. {
  13906. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13907. {
  13908. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13909. }
  13910. } // END OF FOR CHAdeMO_QUANTITY
  13911. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13912. }
  13913. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13914. {
  13915. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13916. {
  13917. tempIndex = ((gun_index==2) ? 1: 0);
  13918. }
  13919. else
  13920. {
  13921. tempIndex = gun_index;
  13922. }
  13923. for (int index = 0; index < CCS_QUANTITY; index++)
  13924. {
  13925. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13926. {
  13927. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13928. }
  13929. } // END OF FOR CCS_QUANTITY
  13930. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13931. }
  13932. else if(gunType[gun_index] == 'G')
  13933. {
  13934. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13935. {
  13936. tempIndex = ((gun_index==2) ? 1: 0);
  13937. }
  13938. else
  13939. {
  13940. tempIndex = gun_index;
  13941. }
  13942. for (int index = 0; index < GB_QUANTITY; index++)
  13943. {
  13944. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13945. {
  13946. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13947. }
  13948. } // END OF FOR GB_QUANTITY
  13949. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13950. }
  13951. else if(gunType[gun_index] == 'O')
  13952. {
  13953. tempIndex = gun_index;
  13954. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13955. {
  13956. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13957. {
  13958. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13959. }
  13960. }
  13961. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13962. }
  13963. else
  13964. {
  13965. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13966. {
  13967. tempIndex = 2;
  13968. }
  13969. else
  13970. {
  13971. tempIndex = gun_index;
  13972. }
  13973. for (int index = 0; index < AC_QUANTITY; index++)
  13974. {
  13975. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13976. {
  13977. 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
  13978. }
  13979. } // END OF FOR AC_QUANTITY
  13980. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13981. }
  13982. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13983. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13985. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13987. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13988. //2.5============================================== End SoC =========================================================
  13989. //idx_sample=5;
  13990. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13991. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  13992. {
  13993. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  13994. {
  13995. tempIndex = ((gun_index==2) ? 1: 0);
  13996. }
  13997. else
  13998. {
  13999. tempIndex = gun_index;
  14000. }
  14001. if(gunType[gun_index] == 'J')
  14002. {
  14003. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14004. {
  14005. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14006. {
  14007. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  14008. }
  14009. }
  14010. }
  14011. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  14012. {
  14013. for (int index = 0; index < CCS_QUANTITY; index++)
  14014. {
  14015. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14016. {
  14017. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  14018. }
  14019. }
  14020. }
  14021. else if(gunType[gun_index] == 'G')
  14022. {
  14023. for (int index = 0; index < GB_QUANTITY; index++)
  14024. {
  14025. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14026. {
  14027. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  14028. }
  14029. }
  14030. }
  14031. else if(gunType[gun_index] == 'O')
  14032. {
  14033. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14034. {
  14035. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14036. {
  14037. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  14038. }
  14039. }
  14040. }
  14041. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14042. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  14043. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14044. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  14045. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  14046. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14047. } // END FOR DC CASE
  14048. //2.6====================================== Current.Import L2 ==============================================
  14049. // idx_sample=6;
  14050. // AC 3 phase L2 current
  14051. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  14052. {
  14053. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14054. {
  14055. tempIndex = 2;
  14056. }
  14057. else
  14058. {
  14059. tempIndex = gun_index;
  14060. }
  14061. for (int index = 0; index < AC_QUANTITY; index++)
  14062. {
  14063. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14064. {
  14065. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  14066. }
  14067. }// End of for AC_QUANTITY
  14068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  14069. }
  14070. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14071. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  14072. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  14073. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  14074. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14075. //2.7====================================== Current.Import L3 ==============================================
  14076. // idx_sample=7;
  14077. // AC 3 phase L3 current
  14078. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  14079. {
  14080. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14081. {
  14082. tempIndex = 2;
  14083. }
  14084. else
  14085. {
  14086. tempIndex = gun_index;
  14087. }
  14088. for (int index = 0; index < AC_QUANTITY; index++)
  14089. {
  14090. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14091. {
  14092. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  14093. }
  14094. }// End of for AC_QUANTITY
  14095. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  14096. }
  14097. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14098. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  14099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  14100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  14101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14102. //2.9====================================== Voltage L2 ====================================================
  14103. //idx_sample=8;
  14104. // AC 3 phase L2 volatge
  14105. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  14106. {
  14107. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14108. {
  14109. tempIndex = 2;
  14110. }
  14111. else
  14112. {
  14113. tempIndex = gun_index;
  14114. }
  14115. for (int index = 0; index < AC_QUANTITY; index++)
  14116. {
  14117. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14118. {
  14119. 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
  14120. }
  14121. } // END OF FOR AC_QUANTITY
  14122. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  14123. }
  14124. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14125. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  14126. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  14127. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  14128. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14129. //2.10====================================== Voltage L3 ====================================================
  14130. //idx_sample=9;
  14131. // AC 3 phase L3 volatge
  14132. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  14133. {
  14134. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14135. {
  14136. tempIndex = 2;
  14137. }
  14138. else
  14139. {
  14140. tempIndex = gun_index;
  14141. }
  14142. for (int index = 0; index < AC_QUANTITY; index++)
  14143. {
  14144. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14145. {
  14146. 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
  14147. }
  14148. } // END OF FOR AC_QUANTITY
  14149. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  14150. }
  14151. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14152. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  14153. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  14154. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  14155. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14156. //====================== Start SoC ================================
  14157. //idx_sample=10;
  14158. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14159. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  14160. {
  14161. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  14162. {
  14163. tempIndex = ((gun_index==2) ? 1: 0);
  14164. }
  14165. else
  14166. {
  14167. tempIndex = gun_index;
  14168. }
  14169. if(gunType[gun_index] == 'J')
  14170. {
  14171. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14172. {
  14173. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14174. {
  14175. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  14176. }
  14177. }
  14178. }
  14179. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  14180. {
  14181. for (int index = 0; index < CCS_QUANTITY; index++)
  14182. {
  14183. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14184. {
  14185. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  14186. }
  14187. }
  14188. }
  14189. else if(gunType[gun_index] == 'G')
  14190. {
  14191. for (int index = 0; index < GB_QUANTITY; index++)
  14192. {
  14193. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14194. {
  14195. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  14196. }
  14197. }
  14198. }
  14199. else if(gunType[gun_index] == 'O')
  14200. {
  14201. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14202. {
  14203. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14204. {
  14205. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  14206. }
  14207. }
  14208. }
  14209. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14210. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  14211. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14212. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  14213. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  14214. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14215. } // END FOR DC CASE
  14216. //======================================== Message create ==============================================
  14217. json_object *StopTransaction = json_object_new_object();
  14218. json_object *transactionDatas = json_object_new_array();
  14219. json_object *sampledValues = json_object_new_array();
  14220. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  14221. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  14222. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  14223. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  14224. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  14225. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  14226. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  14227. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  14228. {
  14229. json_object *transactionData = json_object_new_object();
  14230. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  14231. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  14232. {
  14233. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  14234. {
  14235. json_object *sampledValue = json_object_new_object();
  14236. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  14237. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  14238. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  14239. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  14240. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  14241. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  14242. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  14243. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  14244. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  14245. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  14246. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  14247. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  14248. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  14249. json_object_array_add(sampledValues, sampledValue);
  14250. }
  14251. }
  14252. json_object_object_add(transactionData, "sampledValue", sampledValues);
  14253. json_object_array_add(transactionDatas, transactionData);
  14254. }
  14255. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  14256. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  14257. ,MESSAGE_TYPE_CALL
  14258. ,guid
  14259. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  14260. json_object_put(StopTransaction);
  14261. // Check File "TempStopTransaction" Exist
  14262. if((access(TempStopTransaction,F_OK))!=-1)
  14263. {
  14264. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14265. fclose(fopen(TempStopTransaction, "w"));
  14266. }
  14267. else
  14268. {
  14269. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  14270. FILE *log = fopen(TempStopTransaction, "w+");
  14271. if(log == NULL)
  14272. {
  14273. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  14274. return ;
  14275. }
  14276. else
  14277. {
  14278. fclose(log);
  14279. }
  14280. }
  14281. //Add TempStopTransaction | Update TempStopTransaction
  14282. // open file for writing
  14283. FILE *outfile;
  14284. outfile = fopen (TempStopTransaction, "a");
  14285. //DEBUG_INFO("data = %s\n", queuedata);
  14286. fputs(queuedata, outfile);
  14287. fputs("\n", outfile);
  14288. fclose (outfile);
  14289. }
  14290. void checkTempStopTransaction(int gun_index)
  14291. {
  14292. FILE *fptr1;
  14293. char ch;
  14294. char str[QUEUE_MESSAGE_LENGTH]={0};
  14295. char guid[37]={0};
  14296. char tempdata[65]={0};
  14297. char connectorStr[2]={0};
  14298. char TempStopTransaction[256];
  14299. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14300. fptr1 = fopen(TempStopTransaction, "r");
  14301. //TempStopTransaction格式: 槍號,StopTransaction封包
  14302. if (!fptr1)
  14303. {
  14304. //printf(" File not found or unable to open the input file!!\n");
  14305. return ;
  14306. }
  14307. ch=fgetc(fptr1);
  14308. //printf(" Now the content of the file %s is : \n",fname);
  14309. rewind(fptr1);
  14310. if(ch!=EOF)
  14311. {
  14312. // copy all contents to the temporary file except the specific line
  14313. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14314. {
  14315. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14316. if(str[0]=='\0')
  14317. {
  14318. break;
  14319. }
  14320. //TempStopTransaction格式: 槍號,StopTransaction封包
  14321. strncpy(connectorStr, str, 1);
  14322. if(atoi(connectorStr) != (gun_index+1))
  14323. {
  14324. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  14325. fclose(fptr1);
  14326. return ;
  14327. }
  14328. //random_uuid(guid);
  14329. strncpy(guid, str+6, 36); //copy guid
  14330. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14331. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14332. {
  14333. //DEBUG_INFO("StopTransaction mapitem pass\n");
  14334. }
  14335. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14336. memset(str,0,ARRAY_SIZE(str));
  14337. }
  14338. }
  14339. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14340. fclose(fptr1);
  14341. remove(TempStopTransaction); // remove the original file
  14342. }
  14343. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14344. {
  14345. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14346. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14347. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14348. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14349. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14350. }
  14351. int GetWebSocketPingInterval(void)
  14352. {
  14353. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14354. }
  14355. int GetServerSign(void)
  14356. {
  14357. return server_sign;
  14358. }
  14359. uint8_t GetOcppSecurityProfile()
  14360. {
  14361. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14362. }
  14363. void GetOcppChargerBoxId(uint8_t *data)
  14364. {
  14365. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  14366. }
  14367. void GetOcppSecurityPassword(uint8_t *data)
  14368. {
  14369. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14370. }
  14371. void SetServerSign(int value)
  14372. {
  14373. server_sign = value;
  14374. }
  14375. int GetBootNotificationInterval(void)
  14376. {
  14377. return BootNotificationInterval;
  14378. }
  14379. int GetInternetConn(void)
  14380. {
  14381. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14382. }
  14383. void InitialSystemValue(void)
  14384. {
  14385. int connectorIndex = 0;
  14386. //int valueASCII = 0;
  14387. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14388. gunTotalNumber=0;
  14389. SystemInitial = 0;
  14390. localversion=0;
  14391. BootNotificationInterval = 0;
  14392. authorizeRetryTimes = 0;
  14393. GunStatusInterval = 10;
  14394. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14395. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14396. //Hear Beat
  14397. HeartBeatWithNOResponse = 0;
  14398. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14399. FirstHeartBeat = 0;
  14400. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14401. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14402. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14403. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14404. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14405. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14406. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14407. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14408. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14409. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14410. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14411. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14412. memset(gunType, 0, ARRAY_SIZE(gunType));
  14413. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14414. {
  14415. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  14416. {
  14417. // DO series
  14418. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  14419. {
  14420. SystemInitial = SystemInitial + 1;
  14421. gunTotalNumber = gunTotalNumber + 1;
  14422. gunType[connectorIndex] = 'O';
  14423. connectorIndex = connectorIndex + 1;
  14424. }
  14425. }
  14426. else
  14427. {
  14428. // DM, DW, DS series
  14429. //check connector / socket type (index: 8, 9, 10)
  14430. for(int index=7; index <10 ; index++)
  14431. {
  14432. if(index != 8)
  14433. {
  14434. // DC Connector
  14435. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  14436. {
  14437. SystemInitial = SystemInitial + 1;
  14438. gunTotalNumber = gunTotalNumber + 1;
  14439. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14440. connectorIndex = connectorIndex + 1;
  14441. }
  14442. }
  14443. else
  14444. {
  14445. // AC Connector
  14446. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14447. {
  14448. SystemInitial = SystemInitial + 1;
  14449. gunTotalNumber = gunTotalNumber + 1;
  14450. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14451. connectorIndex = connectorIndex + 1;
  14452. }
  14453. }
  14454. }
  14455. }
  14456. //DEBUG_INFO("DC ...\n");
  14457. }
  14458. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14459. {
  14460. //check connector / socket type (index: 8, 9, 10)
  14461. for(int index=7; index <10 ; index++)
  14462. {
  14463. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14464. {
  14465. SystemInitial = SystemInitial + 1;
  14466. gunTotalNumber = gunTotalNumber + 1;
  14467. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14468. connectorIndex = connectorIndex + 1;
  14469. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14470. }
  14471. }
  14472. }
  14473. //Status && ConnectorPlugIn Setting
  14474. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14475. {
  14476. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14477. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14478. }
  14479. for (int index = 0; index < CCS_QUANTITY; index++)
  14480. {
  14481. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14482. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14483. }
  14484. for (int index = 0; index < GB_QUANTITY; index++)
  14485. {
  14486. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14487. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14488. }
  14489. for (int index = 0; index < AC_QUANTITY; index++)
  14490. {
  14491. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14492. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14493. }
  14494. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14495. {
  14496. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  14497. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  14498. }
  14499. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14500. {
  14501. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14502. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14503. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14504. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14505. }
  14506. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14507. clientTime.Heartbeat=time((time_t*)NULL);
  14508. sleep(1);
  14509. }
  14510. void LWS_Send(char * str)
  14511. {
  14512. //=====================================================
  14513. // Check InternetConn 0: disconnected, 1: connected
  14514. //====================================================
  14515. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14516. {
  14517. DEBUG_INFO("offline now !!!\n");
  14518. return;
  14519. }
  14520. pthread_mutex_lock(&lock_send);
  14521. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14522. sprintf((char *)SendBuffer, "%s", str);
  14523. SendBufLen = strlen(str);
  14524. pthread_mutex_unlock(&lock_send);
  14525. lws_callback_on_writable(wsi_client);
  14526. //lws_service(context, 0);
  14527. //sleep(1);
  14528. }
  14529. void LWS_SendNow(char * str)
  14530. {
  14531. //=====================================================
  14532. // Check InternetConn 0: disconnected, 1: connected
  14533. //====================================================
  14534. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14535. {
  14536. DEBUG_INFO("offline now !!!\n");
  14537. return;
  14538. }
  14539. pthread_mutex_lock(&lock_send);
  14540. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14541. sprintf((char *)SendBuffer, "%s", str);
  14542. SendBufLen = strlen(str);
  14543. pthread_mutex_unlock(&lock_send);
  14544. lws_callback_on_writable(wsi_client);
  14545. lws_service(context, 0);
  14546. //sleep(1);
  14547. }